Run single test with jest.runCLI()
Asked Answered
L

1

6

I want to use jest.runCLI() in gulp for executing only a changed test.

How can I do this?

How can I run just one test with jest.runCLI()?

Lodgings answered 10/11, 2015 at 15:41 Comment(0)
F
10

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
Formulism answered 12/11, 2015 at 10:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.