Skip to content

Commit 00e9e09

Browse files
authored
fix: notifications should be fire&forget rather than having a timeout (#9567)
1 parent 2793c67 commit 00e9e09

File tree

4 files changed

+35
-8
lines changed

4 files changed

+35
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- `[jest-config]` Support `.mjs` config files on Windows as well ([#9558](https://github.com/facebook/jest/pull/9558))
1212
- `[jest-cli]` Set `coverageProvider` correctly when provided in config ([#9562](https://github.com/facebook/jest/pull/9562))
1313
- `[jest-matcher-utils]` Fix diff highlight of symbol-keyed object. ([#9499](https://github.com/facebook/jest/pull/9499))
14+
- `[@jest/reporters]` Notifications should be fire&forget rather than having a timeout ([#9567](https://github.com/facebook/jest/pull/9567))
1415
- `[jest-resolve]` Fix module identity preservation with symlinks and browser field resolution ([#9511](https://github.com/facebook/jest/pull/9511))
1516
- `[jest-resolve]` Do not confuse directories with files ([#8912](https://github.com/facebook/jest/pull/8912))
1617
- `[jest-resolve]` `moduleNameMapper` should take precedence over Node core modules ([#9563](https://github.com/facebook/jest/pull/9563))

e2e/__tests__/detectOpenHandles.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import {wrap} from 'jest-snapshot-serializer-raw';
9-
import {onNodeVersions} from '@jest/test-utils';
9+
import {onNodeVersions, skipSuiteOnWindows} from '@jest/test-utils';
1010
import runJest, {runContinuous} from '../runJest';
1111

1212
try {
@@ -71,6 +71,18 @@ it('does not report promises', () => {
7171
expect(textAfterTest).toBe('');
7272
});
7373

74+
describe('notify', () => {
75+
skipSuiteOnWindows();
76+
77+
it('does not report --notify flag', () => {
78+
// The test here is basically that it exits cleanly without reporting anything (does not need `until`)
79+
const {stderr} = runJest('detect-open-handles', ['notify', '--notify']);
80+
const textAfterTest = getTextAfterTest(stderr);
81+
82+
expect(textAfterTest).toBe('');
83+
});
84+
});
85+
7486
onNodeVersions('>=11', () => {
7587
it('does not report timeouts using unref', () => {
7688
// The test here is basically that it exits cleanly without reporting anything (does not need `until`)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
test('something', () => {
9+
expect(true).toBe(true);
10+
});

packages/jest-reporters/src/notify_reporter.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import * as util from 'util';
1010
import exit = require('exit');
1111
import {Config} from '@jest/types';
1212
import {AggregatedResult} from '@jest/test-result';
13+
import {pluralize} from 'jest-util';
1314
import {Context, TestSchedulerContext} from './types';
1415
import BaseReporter from './base_reporter';
1516

@@ -73,12 +74,13 @@ export default class NotifyReporter extends BaseReporter {
7374
(notifyMode === 'failure-change' && statusChanged))
7475
) {
7576
const title = util.format('%s%d%% Passed', packageName, 100);
76-
const message = util.format(
77-
(isDarwin ? '\u2705 ' : '') + '%d tests passed',
77+
const message = `${isDarwin ? '\u2705 ' : ''}${pluralize(
78+
'test',
7879
result.numPassedTests,
79-
);
80+
)} passed`;
8081

81-
this._notifier.notify({icon, message, title});
82+
// @ts-ignore: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/42303
83+
this._notifier.notify({icon, message, timeout: false, title});
8284
} else if (
8385
testsHaveRun &&
8486
!success &&
@@ -106,17 +108,19 @@ export default class NotifyReporter extends BaseReporter {
106108
const quitAnswer = 'Exit tests';
107109

108110
if (!watchMode) {
109-
this._notifier.notify({icon, message, title});
111+
// @ts-ignore: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/42303
112+
this._notifier.notify({icon, message, timeout: false, title});
110113
} else {
111114
this._notifier.notify(
112115
{
113116
actions: [restartAnswer, quitAnswer],
114117
closeLabel: 'Close',
115118
icon,
116119
message,
117-
timeout: 10,
120+
timeout: false,
118121
title,
119-
},
122+
// https://github.com/DefinitelyTyped/DefinitelyTyped/pull/42303
123+
} as any,
120124
(err, _, metadata) => {
121125
if (err || !metadata) {
122126
return;

0 commit comments

Comments
 (0)