使用jest.runCLI()运行单个测试

时间:2015-11-10 15:41:05

标签: jestjs gulp-jest

我想在jest.runCLI()中使用gulp来执行仅更改过的测试。

我该怎么做?

如何使用jest.runCLI()运行一次测试?

1 个答案:

答案 0 :(得分:8)

Jest has a CLI option to run only changed files (based on the git repository status). The command line jest --onlyChanged becomes programmatically:

jest.runCLI({'onlyChanged': true}, __dirname, function (success) {...});

Using the terminal, jest uses non-hyphenated options to specified filenames:

  • jest test1 runs only test1.js
  • jest test1 test2 runs test1.js and test2.js

jest-cli uses optimist to parse options and non-hyphenated option are mapped to the underscore option (_):

  • jest.runCLI({'_': ['test1']}, __dirname, function (success) {...}); runs only test1.js
  • jest.runCLI({'_': ['test1', 'test2']}, __dirname, function (success) {...}); runs test1.js and test2.js