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

Fix --testNamePattern matching against it.concurrent within describe #9090

Merged
merged 3 commits into from
Feb 20, 2020
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 @@ -18,6 +18,7 @@
- `[jest-cli]` Allow specifying `.cjs` and `.mjs` config files by `--config` CLI option ([#9578](https://github.com/facebook/jest/pull/9578))
- `[jest-config]` Ensure pattern of `replacePosixSep` is a string ([#9546]https://github.com/facebook/jest/pull/9546)
- `[jest-haste-map]` Fix crash on unix based systems without find ([#9579](https://github.com/facebook/jest/pull/9579))
- `[jest-jasmine2]` Fix `--testNamePattern` matching with `concurrent` tests ([#9090](https://github.com/facebook/jest/pull/9090))
- `[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))
Expand Down
13 changes: 13 additions & 0 deletions e2e/__tests__/jasmineAsync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,19 @@ describe('async jasmine', () => {
expect(json.testResults[0].message).toMatch(/concurrent test fails/);
});

it('works with concurrent within a describe block when invoked with testNamePattern', () => {
const {json} = runWithJson('jasmine-async', [
'--testNamePattern',
'one concurrent test fails',
'concurrentWithinDescribe.test.js',
]);
expect(json.numTotalTests).toBe(2);
expect(json.numPassedTests).toBe(0);
expect(json.numFailedTests).toBe(1);
expect(json.numPendingTests).toBe(1);
expect(json.testResults[0].message).toMatch(/concurrent test fails/);
});

it("doesn't execute more than 5 tests simultaneously", () => {
const {json} = runWithJson('jasmine-async', ['concurrent-many.test.js']);
expect(json.numTotalTests).toBe(10);
Expand Down
13 changes: 13 additions & 0 deletions e2e/jasmine-async/__tests__/concurrentWithinDescribe.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* 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.
*/

'use strict';

describe('one', () => {
it.concurrent('concurrent test gets skipped', () => Promise.resolve());
it.concurrent('concurrent test fails', () => Promise.reject());
thymikee marked this conversation as resolved.
Show resolved Hide resolved
});
4 changes: 2 additions & 2 deletions packages/jest-jasmine2/src/jasmine/Env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default function(j$: Jasmine) {
fail: (error: Error | AssertionErrorWithStack) => void;
pending: (message: string) => void;
afterAll: (afterAllFunction: QueueableFn['fn'], timeout?: number) => void;
fit: (description: string, fn: QueueableFn['fn'], timeout?: number) => void;
fit: (description: string, fn: QueueableFn['fn'], timeout?: number) => Spec;
throwingExpectationFailures: () => boolean;
randomizeTests: (value: unknown) => void;
randomTests: () => boolean;
Expand All @@ -79,7 +79,7 @@ export default function(j$: Jasmine) {
addReporter: (reporterToAdd: Reporter) => void;
it: (description: string, fn: QueueableFn['fn'], timeout?: number) => Spec;
xdescribe: (description: string, specDefinitions: Function) => Suite;
xit: (description: string, fn: QueueableFn['fn'], timeout?: number) => any;
xit: (description: string, fn: QueueableFn['fn'], timeout?: number) => Spec;
beforeAll: (beforeAllFunction: QueueableFn['fn'], timeout?: number) => void;
todo: () => Spec;
provideFallbackReporter: (reporterToAdd: Reporter) => void;
Expand Down
24 changes: 14 additions & 10 deletions packages/jest-jasmine2/src/jasmineAsyncInstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import throat from 'throat';
import isError from './isError';
import {Jasmine} from './types';
import Spec from './jasmine/Spec';
import {QueueableFn} from './queueRunner';

interface DoneFn {
(): void;
Expand Down Expand Up @@ -141,34 +142,37 @@ function promisifyIt(
}

function makeConcurrent(
originalFn: Function,
originalFn: (
description: string,
fn: QueueableFn['fn'],
timeout?: number,
) => Spec,
env: Jasmine['currentEnv_'],
mutex: ReturnType<typeof throat>,
): Global.ItConcurrentBase {
return function(specName, fn, timeout) {
if (
env != null &&
!env.specFilter({getFullName: () => specName || ''} as Spec)
) {
return originalFn.call(env, specName, () => Promise.resolve(), timeout);
let promise: Promise<unknown> = Promise.resolve();

const spec = originalFn.call(env, specName, () => promise, timeout);
if (env != null && !env.specFilter(spec)) {
return spec;
}

let promise: Promise<unknown>;
try {
promise = mutex(() => {
const promise = fn();
if (isPromise(promise)) {
return promise;
}
throw new Error(
`Jest: concurrent test "${specName}" must return a Promise.`,
`Jest: concurrent test "${spec.getFullName()}" must return a Promise.`,
);
});
} catch (error) {
return originalFn.call(env, specName, () => Promise.reject(error));
promise = Promise.reject(error);
}

return originalFn.call(env, specName, () => promise, timeout);
return spec;
};
}

Expand Down