Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: passWithNoTests flag ignored for empty test files #15107

Open
Merovech opened this issue Jun 5, 2024 · 1 comment
Open

[Bug]: passWithNoTests flag ignored for empty test files #15107

Merovech opened this issue Jun 5, 2024 · 1 comment

Comments

@Merovech
Copy link

Merovech commented Jun 5, 2024

Version

29.7.0

Steps to reproduce

  1. Clone my repo at https://github.com/Merovech/jest-bug
  2. Run npm i
  3. 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.
Copy link

github-actions bot commented Jul 5, 2024

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant