Skip to content

Commit

Permalink
fix: notifications should be fire&forget rather than having a timeout (
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Feb 12, 2020
1 parent 2793c67 commit 00e9e09
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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))
Expand Down
14 changes: 13 additions & 1 deletion e2e/__tests__/detectOpenHandles.ts
Expand Up @@ -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 {
Expand Down Expand Up @@ -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`)
Expand Down
10 changes: 10 additions & 0 deletions 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);
});
18 changes: 11 additions & 7 deletions packages/jest-reporters/src/notify_reporter.ts
Expand Up @@ -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';

Expand Down Expand Up @@ -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 &&
Expand Down Expand Up @@ -106,17 +108,19 @@ 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(
{
actions: [restartAnswer, quitAnswer],
closeLabel: 'Close',
icon,
message,
timeout: 10,
timeout: false,
title,
},
// https://github.com/DefinitelyTyped/DefinitelyTyped/pull/42303
} as any,
(err, _, metadata) => {
if (err || !metadata) {
return;
Expand Down

0 comments on commit 00e9e09

Please sign in to comment.