Closed as not planned
Description
Version
29.7.0
Steps to reproduce
- Clone my repo at https://github.com/Merovech/jest-bug
- Run
npm i
- Execute one of the below commands using npm run
Commands:
Name | Alias |
---|---|
test:noargs |
jest --verbose |
test:cmd |
jest --passWithNoTests --verbose |
test:config |
jest --config=jest.testconfig.js |
test:showconfig |
jest --config=jest.testconfig.js --showConfig |
Expected behavior
The passWithNoTests
flag should treat an empty file as having no tests and not throw an error.
Actual behavior
All results are the same, regardless of whether I put the parameter on the command line, in a config file, or exclude it altogether.
No parameter
$ npm run test:noargs
> test:noargs
> jest --verbose
FAIL ./empty.test.js
● Test suite failed to run
Your test suite must contain at least one test.
at onResult (node_modules/@jest/core/build/TestScheduler.js:133:18)
at Array.map (<anonymous>)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 0.315 s
Ran all test suites.
Parameter on command line
$ npm run test:cmd
> test:cmd
> jest --passWithNoTests --verbose
FAIL ./empty.test.js
● Test suite failed to run
Your test suite must contain at least one test.
at onResult (node_modules/@jest/core/build/TestScheduler.js:133:18)
at Array.map (<anonymous>)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 0.301 s
Ran all test suites.
Parameter in config file
$ npm run test:config
> test:config
> jest --config=jest.testconfig.js
FAIL ./empty.test.js
● Test suite failed to run
Your test suite must contain at least one test.
at onResult (node_modules/@jest/core/build/TestScheduler.js:133:18)
at Array.map (<anonymous>)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 0.295 s
Ran all test suites.
Additional context
I don't honestly know if this is a bug or deliberate behavior (in which this shouldn't be a bug report but rather a feature request) and I can't find out the answer. But I think it's a perfectly reasonable thing for a developer to create empty test files when adding a feature and fleshing them out later. And on a system where all test files are picked up automatically, this shouldn't fail.
The workaround is to add an empty test suite and a single test to it. But that seems clunky.
Environment
This command does not work in windows. See https://github.com/tabrindle/envinfo/issues/238. If anyone knows a workaround I'd be happy to update this report with it.