diff --git a/CHANGELOG.md b/CHANGELOG.md index 08f3f72face3..a18b154bd7db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ - `[jest-core]` Make watch plugin initialization errors look nice ([#8422](https://github.com/facebook/jest/pull/8422)) - `[jest-snapshot]` Prevent inline snapshots from drifting when inline snapshots are updated ([#8492](https://github.com/facebook/jest/pull/8492)) - `[jest-haste-map]` Don't throw on missing mapper in Node crawler ([#8558](https://github.com/facebook/jest/pull/8558)) +- `[jest-core]` Fix incorrect `passWithNoTests` warning ([#8595](https://github.com/facebook/jest/pull/8595)) ### Chore & Maintenance diff --git a/packages/jest-core/src/__tests__/__snapshots__/getNoTestsFoundMessage.test.js.snap b/packages/jest-core/src/__tests__/__snapshots__/getNoTestsFoundMessage.test.js.snap new file mode 100644 index 000000000000..cc1634348043 --- /dev/null +++ b/packages/jest-core/src/__tests__/__snapshots__/getNoTestsFoundMessage.test.js.snap @@ -0,0 +1,25 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`getNoTestsFoundMessage returns correct message when monitoring only changed 1`] = `"No tests found related to files changed since last commit."`; + +exports[`getNoTestsFoundMessage returns correct message when monitoring only failures 1`] = ` +"No failed test found. +Press \`f\` to quit \\"only failed tests\\" mode." +`; + +exports[`getNoTestsFoundMessage returns correct message with passWithNoTests 1`] = `"No tests found, exiting with code 0"`; + +exports[`getNoTestsFoundMessage returns correct message with verbose option 1`] = ` +"No tests found, exiting with code 1 +Run with \`--passWithNoTests\` to exit with code 0 + +Pattern: /path/pattern - 0 matches" +`; + +exports[`getNoTestsFoundMessage returns correct message without options 1`] = ` +"No tests found, exiting with code 1 +Run with \`--passWithNoTests\` to exit with code 0 +In /root/dir + 0 files checked across 0 projects. Run with \`--verbose\` for more details. +Pattern: /path/pattern - 0 matches" +`; diff --git a/packages/jest-core/src/__tests__/getNoTestsFoundMessage.test.js b/packages/jest-core/src/__tests__/getNoTestsFoundMessage.test.js new file mode 100644 index 000000000000..cb726cf292ee --- /dev/null +++ b/packages/jest-core/src/__tests__/getNoTestsFoundMessage.test.js @@ -0,0 +1,38 @@ +// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + +import getNoTestsFoundMessage from '../getNoTestsFoundMessage'; + +describe('getNoTestsFoundMessage', () => { + function createGlobalConfig(options) { + return { + rootDir: '/root/dir', + testPathPattern: '/path/pattern', + ...options, + }; + } + + test('returns correct message when monitoring only failures', () => { + const config = createGlobalConfig({onlyFailures: true}); + expect(getNoTestsFoundMessage([], config)).toMatchSnapshot(); + }); + + test('returns correct message when monitoring only changed', () => { + const config = createGlobalConfig({onlyChanged: true}); + expect(getNoTestsFoundMessage([], config)).toMatchSnapshot(); + }); + + test('returns correct message with verbose option', () => { + const config = createGlobalConfig({verbose: true}); + expect(getNoTestsFoundMessage([], config)).toMatchSnapshot(); + }); + + test('returns correct message without options', () => { + const config = createGlobalConfig(); + expect(getNoTestsFoundMessage([], config)).toMatchSnapshot(); + }); + + test('returns correct message with passWithNoTests', () => { + const config = createGlobalConfig({passWithNoTests: true}); + expect(getNoTestsFoundMessage([], config)).toMatchSnapshot(); + }); +}); diff --git a/packages/jest-core/src/getNoTestFoundPassWithNoTests.ts b/packages/jest-core/src/getNoTestFoundPassWithNoTests.ts new file mode 100644 index 000000000000..f05c16ff78c3 --- /dev/null +++ b/packages/jest-core/src/getNoTestFoundPassWithNoTests.ts @@ -0,0 +1,7 @@ +// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + +import chalk from 'chalk'; + +export default function getNoTestFoundPassWithNoTests() { + return chalk.bold('No tests found, exiting with code 0'); +} diff --git a/packages/jest-core/src/getNoTestsFoundMessage.ts b/packages/jest-core/src/getNoTestsFoundMessage.ts index 00b0b5e6148b..a411527ee265 100644 --- a/packages/jest-core/src/getNoTestsFoundMessage.ts +++ b/packages/jest-core/src/getNoTestsFoundMessage.ts @@ -11,6 +11,7 @@ import getNoTestFound from './getNoTestFound'; import getNoTestFoundRelatedToChangedFiles from './getNoTestFoundRelatedToChangedFiles'; import getNoTestFoundVerbose from './getNoTestFoundVerbose'; import getNoTestFoundFailed from './getNoTestFoundFailed'; +import getNoTestFoundPassWithNoTests from './getNoTestFoundPassWithNoTests'; export default function getNoTestsFoundMessage( testRunData: TestRunData, @@ -22,6 +23,9 @@ export default function getNoTestsFoundMessage( if (globalConfig.onlyChanged) { return getNoTestFoundRelatedToChangedFiles(globalConfig); } + if (globalConfig.passWithNoTests) { + return getNoTestFoundPassWithNoTests(); + } return testRunData.length === 1 || globalConfig.verbose ? getNoTestFoundVerbose(testRunData, globalConfig) : getNoTestFound(testRunData, globalConfig);