From 09a7ca89972da8a091731527c763b91d5412655c Mon Sep 17 00:00:00 2001 From: Taylor Winfield Date: Tue, 19 Jun 2018 11:41:53 +0100 Subject: [PATCH 1/3] add check to make sure tests have run before notifying --- .../__snapshots__/notify_reporter.test.js.snap | 8 -------- .../jest-cli/src/__tests__/notify_reporter.test.js | 13 +++++++++++++ packages/jest-cli/src/reporters/notify_reporter.js | 4 ++++ 3 files changed, 17 insertions(+), 8 deletions(-) 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..3b98504f8f54 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, 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' || From 896ec2c3b5dfd0cec474972c33f26ce6cf0fa1a1 Mon Sep 17 00:00:00 2001 From: Taylor Winfield Date: Tue, 19 Jun 2018 11:55:31 +0100 Subject: [PATCH 2/3] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 72b2a46da94f..d5c9d4ab87b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,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-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)) - `[expect]` `toEqual` no longer tries to compare non-enumerable symbolic properties, to be consistent with non-symbolic properties. ([#6398](https://github.com/facebook/jest/pull/6398)) From 84f16eaa250efe83d1bd8d46ff9a777e844d84c4 Mon Sep 17 00:00:00 2001 From: Taylor Winfield Date: Wed, 20 Jun 2018 08:28:46 +0100 Subject: [PATCH 3/3] add condition for aggregatedResults with no tests to not call notifier --- packages/jest-cli/src/__tests__/notify_reporter.test.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/jest-cli/src/__tests__/notify_reporter.test.js b/packages/jest-cli/src/__tests__/notify_reporter.test.js index 3b98504f8f54..c5073d28e3f2 100644 --- a/packages/jest-cli/src/__tests__/notify_reporter.test.js +++ b/packages/jest-cli/src/__tests__/notify_reporter.test.js @@ -97,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(