From 0354fedc5323a51552f4dad0fd4f9471d871185e Mon Sep 17 00:00:00 2001 From: Dmitri Gabbasov Date: Thu, 24 Oct 2019 15:47:17 +0300 Subject: [PATCH 1/2] Fix --testNamePattern matching against it.concurrent within describe --- CHANGELOG.md | 1 + e2e/__tests__/jasmineAsync.test.ts | 13 ++++++++++ .../concurrentWithinDescribe.test.js | 12 ++++++++++ packages/jest-jasmine2/src/jasmine/Env.ts | 4 ++-- .../jest-jasmine2/src/jasmineAsyncInstall.ts | 24 +++++++++++-------- 5 files changed, 42 insertions(+), 12 deletions(-) create mode 100644 e2e/jasmine-async/__tests__/concurrentWithinDescribe.test.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 507920b30aed..e3af2203c503 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ - `[jest-snapshot]` [**BREAKING**] Distinguish empty string from internal snapshot not written ([#8898](https://github.com/facebook/jest/pull/8898)) - `[jest-snapshot]` [**BREAKING**] Remove `report` method and throw matcher errors ([#9049](https://github.com/facebook/jest/pull/9049)) - `[jest-transform]` Properly cache transformed files across tests ([#8890](https://github.com/facebook/jest/pull/8890)) +- `[jest-jasmine2]` Fix `--testNamePattern` matching with `concurrent` tests ([#9090](https://github.com/facebook/jest/pull/9090)) ### Chore & Maintenance diff --git a/e2e/__tests__/jasmineAsync.test.ts b/e2e/__tests__/jasmineAsync.test.ts index fb869f65cd06..cf621b5104d2 100644 --- a/e2e/__tests__/jasmineAsync.test.ts +++ b/e2e/__tests__/jasmineAsync.test.ts @@ -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(1); + expect(json.numPassedTests).toBe(0); + expect(json.numFailedTests).toBe(1); + expect(json.numPendingTests).toBe(0); + 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); diff --git a/e2e/jasmine-async/__tests__/concurrentWithinDescribe.test.js b/e2e/jasmine-async/__tests__/concurrentWithinDescribe.test.js new file mode 100644 index 000000000000..be0a6c794fb2 --- /dev/null +++ b/e2e/jasmine-async/__tests__/concurrentWithinDescribe.test.js @@ -0,0 +1,12 @@ +/** + * 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 fails', () => Promise.reject()); +}); diff --git a/packages/jest-jasmine2/src/jasmine/Env.ts b/packages/jest-jasmine2/src/jasmine/Env.ts index 6ff8da163bcf..00d1d0530994 100644 --- a/packages/jest-jasmine2/src/jasmine/Env.ts +++ b/packages/jest-jasmine2/src/jasmine/Env.ts @@ -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; @@ -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; diff --git a/packages/jest-jasmine2/src/jasmineAsyncInstall.ts b/packages/jest-jasmine2/src/jasmineAsyncInstall.ts index 85e1975ba7d4..b3a7bb241233 100644 --- a/packages/jest-jasmine2/src/jasmineAsyncInstall.ts +++ b/packages/jest-jasmine2/src/jasmineAsyncInstall.ts @@ -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; @@ -141,19 +142,22 @@ function promisifyIt( } function makeConcurrent( - originalFn: Function, + originalFn: ( + description: string, + fn: QueueableFn['fn'], + timeout?: number, + ) => Spec, env: Jasmine['currentEnv_'], mutex: ReturnType, ): 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 = Promise.resolve(); + + const spec = originalFn.call(env, specName, () => promise, timeout); + if (env != null && !env.specFilter(spec)) { + return spec; } - let promise: Promise; try { promise = mutex(() => { const promise = fn(); @@ -161,14 +165,14 @@ function makeConcurrent( 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; }; } From 43f0e16ee1ebbfd62ccd39c1ef9c967fc022aeed Mon Sep 17 00:00:00 2001 From: Dmitri Gabbasov Date: Fri, 25 Oct 2019 12:49:36 +0300 Subject: [PATCH 2/2] Add another test case to make sure filtering actually works --- e2e/__tests__/jasmineAsync.test.ts | 4 ++-- e2e/jasmine-async/__tests__/concurrentWithinDescribe.test.js | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/e2e/__tests__/jasmineAsync.test.ts b/e2e/__tests__/jasmineAsync.test.ts index cf621b5104d2..6eaaa864e956 100644 --- a/e2e/__tests__/jasmineAsync.test.ts +++ b/e2e/__tests__/jasmineAsync.test.ts @@ -121,10 +121,10 @@ describe('async jasmine', () => { 'one concurrent test fails', 'concurrentWithinDescribe.test.js', ]); - expect(json.numTotalTests).toBe(1); + expect(json.numTotalTests).toBe(2); expect(json.numPassedTests).toBe(0); expect(json.numFailedTests).toBe(1); - expect(json.numPendingTests).toBe(0); + expect(json.numPendingTests).toBe(1); expect(json.testResults[0].message).toMatch(/concurrent test fails/); }); diff --git a/e2e/jasmine-async/__tests__/concurrentWithinDescribe.test.js b/e2e/jasmine-async/__tests__/concurrentWithinDescribe.test.js index be0a6c794fb2..1e674e10d2e1 100644 --- a/e2e/jasmine-async/__tests__/concurrentWithinDescribe.test.js +++ b/e2e/jasmine-async/__tests__/concurrentWithinDescribe.test.js @@ -8,5 +8,6 @@ 'use strict'; describe('one', () => { + it.concurrent('concurrent test gets skipped', () => Promise.resolve()); it.concurrent('concurrent test fails', () => Promise.reject()); });