diff --git a/CHANGELOG.md b/CHANGELOG.md index e0efdc0b12c7..8f35b5d7fe32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - `[jest-config]` Support `.mjs` config files on Windows as well ([#9558](https://github.com/facebook/jest/pull/9558)) - `[jest-cli]` Set `coverageProvider` correctly when provided in config ([#9562](https://github.com/facebook/jest/pull/9562)) - `[jest-matcher-utils]` Fix diff highlight of symbol-keyed object. ([#9499](https://github.com/facebook/jest/pull/9499)) +- `[@jest/reporters]` Notifications should be fire&forget rather than having a timeout ([#9567](https://github.com/facebook/jest/pull/9567)) - `[jest-resolve]` Fix module identity preservation with symlinks and browser field resolution ([#9511](https://github.com/facebook/jest/pull/9511)) - `[jest-resolve]` Do not confuse directories with files ([#8912](https://github.com/facebook/jest/pull/8912)) - `[jest-resolve]` `moduleNameMapper` should take precedence over Node core modules ([#9563](https://github.com/facebook/jest/pull/9563)) diff --git a/e2e/__tests__/detectOpenHandles.ts b/e2e/__tests__/detectOpenHandles.ts index 9d7b1781e411..9b384c34e60b 100644 --- a/e2e/__tests__/detectOpenHandles.ts +++ b/e2e/__tests__/detectOpenHandles.ts @@ -6,7 +6,7 @@ */ import {wrap} from 'jest-snapshot-serializer-raw'; -import {onNodeVersions} from '@jest/test-utils'; +import {onNodeVersions, skipSuiteOnWindows} from '@jest/test-utils'; import runJest, {runContinuous} from '../runJest'; try { @@ -71,6 +71,18 @@ it('does not report promises', () => { expect(textAfterTest).toBe(''); }); +describe('notify', () => { + skipSuiteOnWindows(); + + it('does not report --notify flag', () => { + // The test here is basically that it exits cleanly without reporting anything (does not need `until`) + const {stderr} = runJest('detect-open-handles', ['notify', '--notify']); + const textAfterTest = getTextAfterTest(stderr); + + expect(textAfterTest).toBe(''); + }); +}); + onNodeVersions('>=11', () => { it('does not report timeouts using unref', () => { // The test here is basically that it exits cleanly without reporting anything (does not need `until`) diff --git a/e2e/detect-open-handles/__tests__/notify.js b/e2e/detect-open-handles/__tests__/notify.js new file mode 100644 index 000000000000..3172ab00f387 --- /dev/null +++ b/e2e/detect-open-handles/__tests__/notify.js @@ -0,0 +1,10 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +test('something', () => { + expect(true).toBe(true); +}); diff --git a/packages/jest-reporters/src/notify_reporter.ts b/packages/jest-reporters/src/notify_reporter.ts index 70d22e1c1d8f..78fc62896eda 100644 --- a/packages/jest-reporters/src/notify_reporter.ts +++ b/packages/jest-reporters/src/notify_reporter.ts @@ -10,6 +10,7 @@ import * as util from 'util'; import exit = require('exit'); import {Config} from '@jest/types'; import {AggregatedResult} from '@jest/test-result'; +import {pluralize} from 'jest-util'; import {Context, TestSchedulerContext} from './types'; import BaseReporter from './base_reporter'; @@ -73,12 +74,13 @@ export default class NotifyReporter extends BaseReporter { (notifyMode === 'failure-change' && statusChanged)) ) { const title = util.format('%s%d%% Passed', packageName, 100); - const message = util.format( - (isDarwin ? '\u2705 ' : '') + '%d tests passed', + const message = `${isDarwin ? '\u2705 ' : ''}${pluralize( + 'test', result.numPassedTests, - ); + )} passed`; - this._notifier.notify({icon, message, title}); + // @ts-ignore: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/42303 + this._notifier.notify({icon, message, timeout: false, title}); } else if ( testsHaveRun && !success && @@ -106,7 +108,8 @@ export default class NotifyReporter extends BaseReporter { const quitAnswer = 'Exit tests'; if (!watchMode) { - this._notifier.notify({icon, message, title}); + // @ts-ignore: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/42303 + this._notifier.notify({icon, message, timeout: false, title}); } else { this._notifier.notify( { @@ -114,9 +117,10 @@ export default class NotifyReporter extends BaseReporter { closeLabel: 'Close', icon, message, - timeout: 10, + timeout: false, title, - }, + // https://github.com/DefinitelyTyped/DefinitelyTyped/pull/42303 + } as any, (err, _, metadata) => { if (err || !metadata) { return;