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

Add check to make sure one or more tests have run before notifying #6495

Merged
merged 4 commits into from
Jun 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ Array [

exports[`test change 1`] = `
Array [
Object {
"message": "3 tests passed",
"title": "100% Passed",
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be some snapshots added?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that this is a result of the firstRun: i === 0 logic which is causing new snapshots in the the change testMode scenarios, due to me adding a new aggregation result to the notifyEvents array, so I believe this is expected?

Object {
"message": "3 of 3 tests failed",
"title": "100% Failed",
Expand All @@ -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",
Expand Down
17 changes: 17 additions & 0 deletions packages/jest-cli/src/__tests__/notify_reporter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -84,6 +97,10 @@ const testModes = (notifyMode: string, arl: Array<AggregatedResult>) => {
);
previousContext = newContext;
reporter.onRunComplete(new Set(), ar);

if (ar.numTotalTests === 0) {
expect(notify.notify).not.toHaveBeenCalled();
}
});

expect(
Expand Down
4 changes: 4 additions & 0 deletions packages/jest-cli/src/reporters/notify_reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' ||
Expand All @@ -60,6 +63,7 @@ export default class NotifyReporter extends BaseReporter {

notifier.notify({icon, message, title});
} else if (
testsHaveRun &&
!success &&
(notifyMode === 'always' ||
notifyMode === 'failure' ||
Expand Down