Skip to content

Commit c2a879d

Browse files
authored
Fix --testNamePattern matching against it.concurrent within describe (#9090)
1 parent 56565cc commit c2a879d

5 files changed

Lines changed: 43 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- `[jest-cli]` Allow specifying `.cjs` and `.mjs` config files by `--config` CLI option ([#9578](https://github.com/facebook/jest/pull/9578))
1919
- `[jest-config]` Ensure pattern of `replacePosixSep` is a string ([#9546]https://github.com/facebook/jest/pull/9546)
2020
- `[jest-haste-map]` Fix crash on unix based systems without find ([#9579](https://github.com/facebook/jest/pull/9579))
21+
- `[jest-jasmine2]` Fix `--testNamePattern` matching with `concurrent` tests ([#9090](https://github.com/facebook/jest/pull/9090))
2122
- `[jest-matcher-utils]` Fix diff highlight of symbol-keyed object. ([#9499](https://github.com/facebook/jest/pull/9499))
2223
- `[@jest/reporters]` Notifications should be fire&forget rather than having a timeout ([#9567](https://github.com/facebook/jest/pull/9567))
2324
- `[jest-resolve]` Fix module identity preservation with symlinks and browser field resolution ([#9511](https://github.com/facebook/jest/pull/9511))

e2e/__tests__/jasmineAsync.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,19 @@ describe('async jasmine', () => {
115115
expect(json.testResults[0].message).toMatch(/concurrent test fails/);
116116
});
117117

118+
it('works with concurrent within a describe block when invoked with testNamePattern', () => {
119+
const {json} = runWithJson('jasmine-async', [
120+
'--testNamePattern',
121+
'one concurrent test fails',
122+
'concurrentWithinDescribe.test.js',
123+
]);
124+
expect(json.numTotalTests).toBe(2);
125+
expect(json.numPassedTests).toBe(0);
126+
expect(json.numFailedTests).toBe(1);
127+
expect(json.numPendingTests).toBe(1);
128+
expect(json.testResults[0].message).toMatch(/concurrent test fails/);
129+
});
130+
118131
it("doesn't execute more than 5 tests simultaneously", () => {
119132
const {json} = runWithJson('jasmine-async', ['concurrent-many.test.js']);
120133
expect(json.numTotalTests).toBe(10);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
'use strict';
9+
10+
describe('one', () => {
11+
it.concurrent('concurrent test gets skipped', () => Promise.resolve());
12+
it.concurrent('concurrent test fails', () => Promise.reject());
13+
});

packages/jest-jasmine2/src/jasmine/Env.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export default function(j$: Jasmine) {
5555
fail: (error: Error | AssertionErrorWithStack) => void;
5656
pending: (message: string) => void;
5757
afterAll: (afterAllFunction: QueueableFn['fn'], timeout?: number) => void;
58-
fit: (description: string, fn: QueueableFn['fn'], timeout?: number) => void;
58+
fit: (description: string, fn: QueueableFn['fn'], timeout?: number) => Spec;
5959
throwingExpectationFailures: () => boolean;
6060
randomizeTests: (value: unknown) => void;
6161
randomTests: () => boolean;
@@ -79,7 +79,7 @@ export default function(j$: Jasmine) {
7979
addReporter: (reporterToAdd: Reporter) => void;
8080
it: (description: string, fn: QueueableFn['fn'], timeout?: number) => Spec;
8181
xdescribe: (description: string, specDefinitions: Function) => Suite;
82-
xit: (description: string, fn: QueueableFn['fn'], timeout?: number) => any;
82+
xit: (description: string, fn: QueueableFn['fn'], timeout?: number) => Spec;
8383
beforeAll: (beforeAllFunction: QueueableFn['fn'], timeout?: number) => void;
8484
todo: () => Spec;
8585
provideFallbackReporter: (reporterToAdd: Reporter) => void;

packages/jest-jasmine2/src/jasmineAsyncInstall.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import throat from 'throat';
1717
import isError from './isError';
1818
import {Jasmine} from './types';
1919
import Spec from './jasmine/Spec';
20+
import {QueueableFn} from './queueRunner';
2021

2122
interface DoneFn {
2223
(): void;
@@ -141,34 +142,37 @@ function promisifyIt(
141142
}
142143

143144
function makeConcurrent(
144-
originalFn: Function,
145+
originalFn: (
146+
description: string,
147+
fn: QueueableFn['fn'],
148+
timeout?: number,
149+
) => Spec,
145150
env: Jasmine['currentEnv_'],
146151
mutex: ReturnType<typeof throat>,
147152
): Global.ItConcurrentBase {
148153
return function(specName, fn, timeout) {
149-
if (
150-
env != null &&
151-
!env.specFilter({getFullName: () => specName || ''} as Spec)
152-
) {
153-
return originalFn.call(env, specName, () => Promise.resolve(), timeout);
154+
let promise: Promise<unknown> = Promise.resolve();
155+
156+
const spec = originalFn.call(env, specName, () => promise, timeout);
157+
if (env != null && !env.specFilter(spec)) {
158+
return spec;
154159
}
155160

156-
let promise: Promise<unknown>;
157161
try {
158162
promise = mutex(() => {
159163
const promise = fn();
160164
if (isPromise(promise)) {
161165
return promise;
162166
}
163167
throw new Error(
164-
`Jest: concurrent test "${specName}" must return a Promise.`,
168+
`Jest: concurrent test "${spec.getFullName()}" must return a Promise.`,
165169
);
166170
});
167171
} catch (error) {
168-
return originalFn.call(env, specName, () => Promise.reject(error));
172+
promise = Promise.reject(error);
169173
}
170174

171-
return originalFn.call(env, specName, () => promise, timeout);
175+
return spec;
172176
};
173177
}
174178

0 commit comments

Comments
 (0)