diff --git a/CHANGELOG.md b/CHANGELOG.md index e7ff5c291841..865d3a5fca39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ ### Fixes +- `[jest-cli]` Add check to make sure one or more tests have run before notifying when using `--notify` ([#6495](https://github.com/facebook/jest/pull/6495)) - `[jest-cli]` Pass `globalConfig` as a parameter to `globalSetup` and `globalTeardown` functions ([#6486](https://github.com/facebook/jest/pull/6486)) - `[jest-config]` Add missing options to the `defaults` object ([#6428](https://github.com/facebook/jest/pull/6428)) - `[expect]` Using symbolic property names in arrays no longer causes the `toEqual` matcher to fail ([#6391](https://github.com/facebook/jest/pull/6391)) diff --git a/packages/jest-cli/src/__tests__/__snapshots__/notify_reporter.test.js.snap b/packages/jest-cli/src/__tests__/__snapshots__/notify_reporter.test.js.snap index 30a010dcd5ef..5235644f80da 100644 --- a/packages/jest-cli/src/__tests__/__snapshots__/notify_reporter.test.js.snap +++ b/packages/jest-cli/src/__tests__/__snapshots__/notify_reporter.test.js.snap @@ -31,10 +31,6 @@ Array [ exports[`test change 1`] = ` Array [ - Object { - "message": "3 tests passed", - "title": "100% Passed", - }, Object { "message": "3 of 3 tests failed", "title": "100% Failed", @@ -52,10 +48,6 @@ Array [ exports[`test failure-change 1`] = ` Array [ - Object { - "message": "3 tests passed", - "title": "100% Passed", - }, Object { "message": "3 of 3 tests failed", "title": "100% Failed", diff --git a/packages/jest-cli/src/__tests__/notify_reporter.test.js b/packages/jest-cli/src/__tests__/notify_reporter.test.js index 442815a197b4..c5073d28e3f2 100644 --- a/packages/jest-cli/src/__tests__/notify_reporter.test.js +++ b/packages/jest-cli/src/__tests__/notify_reporter.test.js @@ -45,8 +45,21 @@ const aggregatedResultsFailure: AggregatedResult = { success: false, }; +const aggregatedResultsNoTests: AggregatedResult = { + numFailedTestSuites: 0, + numFailedTests: 0, + numPassedTestSuites: 0, + numPassedTests: 0, + numPendingTestSuites: 0, + numPendingTests: 0, + numRuntimeErrorTestSuites: 0, + numTotalTestSuites: 0, + numTotalTests: 0, +}; + // Simulated sequence of events for NotifyReporter const notifyEvents = [ + aggregatedResultsNoTests, aggregatedResultsSuccess, aggregatedResultsFailure, aggregatedResultsSuccess, @@ -84,6 +97,10 @@ const testModes = (notifyMode: string, arl: Array) => { ); previousContext = newContext; reporter.onRunComplete(new Set(), ar); + + if (ar.numTotalTests === 0) { + expect(notify.notify).not.toHaveBeenCalled(); + } }); expect( diff --git a/packages/jest-cli/src/reporters/notify_reporter.js b/packages/jest-cli/src/reporters/notify_reporter.js index 91d7df636c83..c63e4eb06c44 100644 --- a/packages/jest-cli/src/reporters/notify_reporter.js +++ b/packages/jest-cli/src/reporters/notify_reporter.js @@ -44,7 +44,10 @@ export default class NotifyReporter extends BaseReporter { const notifyMode = this._globalConfig.notifyMode; const statusChanged = this._context.previousSuccess !== success || this._context.firstRun; + const testsHaveRun = result.numTotalTests !== 0; + if ( + testsHaveRun && success && (notifyMode === 'always' || notifyMode === 'success' || @@ -60,6 +63,7 @@ export default class NotifyReporter extends BaseReporter { notifier.notify({icon, message, title}); } else if ( + testsHaveRun && !success && (notifyMode === 'always' || notifyMode === 'failure' ||