Skip to content

Commit dd9ec17

Browse files
taylorwinfieldcpojer
authored andcommitted
Add check to make sure one or more tests have run before notifying (jestjs#6495)
* add check to make sure tests have run before notifying * update changelog * add condition for aggregatedResults with no tests to not call notifier
1 parent 87bf0dd commit dd9ec17

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
### Fixes
99

10+
- `[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))
1011
- `[jest-cli]` Pass `globalConfig` as a parameter to `globalSetup` and `globalTeardown` functions ([#6486](https://github.com/facebook/jest/pull/6486))
1112
- `[jest-config]` Add missing options to the `defaults` object ([#6428](https://github.com/facebook/jest/pull/6428))
1213
- `[expect]` Using symbolic property names in arrays no longer causes the `toEqual` matcher to fail ([#6391](https://github.com/facebook/jest/pull/6391))

packages/jest-cli/src/__tests__/__snapshots__/notify_reporter.test.js.snap

-8
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ Array [
3131

3232
exports[`test change 1`] = `
3333
Array [
34-
Object {
35-
"message": "3 tests passed",
36-
"title": "100% Passed",
37-
},
3834
Object {
3935
"message": "3 of 3 tests failed",
4036
"title": "100% Failed",
@@ -52,10 +48,6 @@ Array [
5248

5349
exports[`test failure-change 1`] = `
5450
Array [
55-
Object {
56-
"message": "3 tests passed",
57-
"title": "100% Passed",
58-
},
5951
Object {
6052
"message": "3 of 3 tests failed",
6153
"title": "100% Failed",

packages/jest-cli/src/__tests__/notify_reporter.test.js

+17
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,21 @@ const aggregatedResultsFailure: AggregatedResult = {
4545
success: false,
4646
};
4747

48+
const aggregatedResultsNoTests: AggregatedResult = {
49+
numFailedTestSuites: 0,
50+
numFailedTests: 0,
51+
numPassedTestSuites: 0,
52+
numPassedTests: 0,
53+
numPendingTestSuites: 0,
54+
numPendingTests: 0,
55+
numRuntimeErrorTestSuites: 0,
56+
numTotalTestSuites: 0,
57+
numTotalTests: 0,
58+
};
59+
4860
// Simulated sequence of events for NotifyReporter
4961
const notifyEvents = [
62+
aggregatedResultsNoTests,
5063
aggregatedResultsSuccess,
5164
aggregatedResultsFailure,
5265
aggregatedResultsSuccess,
@@ -84,6 +97,10 @@ const testModes = (notifyMode: string, arl: Array<AggregatedResult>) => {
8497
);
8598
previousContext = newContext;
8699
reporter.onRunComplete(new Set(), ar);
100+
101+
if (ar.numTotalTests === 0) {
102+
expect(notify.notify).not.toHaveBeenCalled();
103+
}
87104
});
88105

89106
expect(

packages/jest-cli/src/reporters/notify_reporter.js

+4
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ export default class NotifyReporter extends BaseReporter {
4444
const notifyMode = this._globalConfig.notifyMode;
4545
const statusChanged =
4646
this._context.previousSuccess !== success || this._context.firstRun;
47+
const testsHaveRun = result.numTotalTests !== 0;
48+
4749
if (
50+
testsHaveRun &&
4851
success &&
4952
(notifyMode === 'always' ||
5053
notifyMode === 'success' ||
@@ -60,6 +63,7 @@ export default class NotifyReporter extends BaseReporter {
6063

6164
notifier.notify({icon, message, title});
6265
} else if (
66+
testsHaveRun &&
6367
!success &&
6468
(notifyMode === 'always' ||
6569
notifyMode === 'failure' ||

0 commit comments

Comments
 (0)