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

feat(circus): added each to failing tests #13142

Merged
merged 13 commits into from Aug 17, 2022
306 changes: 261 additions & 45 deletions e2e/__tests__/__snapshots__/testFailing.test.ts.snap

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions e2e/test-failing/__tests__/statuses.test.js
Expand Up @@ -27,6 +27,14 @@ test.failing('failing fails = passes with test syntax', () => {
expect(10).toBe(101);
});

test.failing.each([
{a: 1, b: 1, expected: 2},
{a: 1, b: 2, expected: 3},
{a: 2, b: 1, expected: 3},
])('.add($a, $b)', ({a, b, expected}) => {
expect(a + b).toBe(expected);
});

it.skip.failing('skipped failing 1', () => {
expect(10).toBe(10);
});
Expand Down
8 changes: 8 additions & 0 deletions e2e/test-failing/__tests__/worksWithConcurrentMode.test.js
Expand Up @@ -14,6 +14,14 @@ describe('block with concurrent', () => {
expect(10).toBe(10);
});

test.concurrent.failing.each([
{a: 1, b: 1, expected: 2},
{a: 1, b: 2, expected: 3},
{a: 2, b: 1, expected: 3},
])('.add($a, $b)', ({a, b, expected}) => {
expect(a + b).toBe(expected);
});

it.concurrent.failing('failing fails = passes', () => {
expect(10).toBe(101);
});
Expand Down
Expand Up @@ -14,6 +14,14 @@ describe('block with concurrent', () => {
expect(10).toBe(10);
});

test.concurrent.only.failing.each([
{a: 1, b: 1, expected: 2},
{a: 1, b: 2, expected: 3},
{a: 2, b: 1, expected: 3},
])('.add($a, $b)', ({a, b, expected}) => {
expect(a + b).toBe(expected);
});

it.concurrent.only.failing('failing fails = passes', () => {
expect(10).toBe(101);
});
Expand Down
8 changes: 8 additions & 0 deletions e2e/test-failing/__tests__/worksWithOnlyMode.test.js
Expand Up @@ -10,6 +10,14 @@ describe('block with only, should pass', () => {
expect(10).toBe(101);
});

it.only.failing.each([
{a: 1, b: 1, expected: 2},
{a: 1, b: 2, expected: 3},
{a: 2, b: 1, expected: 3},
])('.add($a, $b)', ({a, b, expected}) => {
expect(a + b).toBe(expected);
});

it('failing test but skipped', () => {
expect(10).toBe(101);
});
Expand Down
8 changes: 8 additions & 0 deletions e2e/test-failing/__tests__/worksWithSkipMode.test.js
Expand Up @@ -10,6 +10,14 @@ describe('block with only, should pass', () => {
expect(10).toBe(101);
});

it.skip.failing.each([
{a: 1, b: 1, expected: 2},
{a: 1, b: 2, expected: 3},
{a: 2, b: 1, expected: 3},
])('.add($a, $b)', ({a, b, expected}) => {
expect(a + b).toBe(expected);
});

it('failing test', () => {
expect(10).toBe(101);
});
Expand Down
8 changes: 7 additions & 1 deletion packages/jest-circus/src/index.ts
Expand Up @@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import type {Failing} from '@jest/types/src/Global';
SimenB marked this conversation as resolved.
Show resolved Hide resolved
import type {Circus, Global} from '@jest/types';
import {bind as bindEach} from 'jest-each';
import {ErrorWithStack, convertDescriptorToString, isPromise} from 'jest-util';
Expand Down Expand Up @@ -145,7 +146,7 @@ const test: Global.It = (() => {
fn?: Circus.TestFn,
timeout?: number,
): void => _addTest(testName, mode, concurrent, fn, failing, timeout, true);
return failing;
return failing as Failing;
kkyusufk marked this conversation as resolved.
Show resolved Hide resolved
SimenB marked this conversation as resolved.
Show resolved Hide resolved
};

test.todo = (testName: Circus.TestNameLike, ...rest: Array<any>): void => {
Expand Down Expand Up @@ -213,16 +214,21 @@ const test: Global.It = (() => {
concurrentOnly.each = bindEach(concurrentOnly, false);

only.failing = bindFailing(false, 'only');
only.failing.each = bindEach(only.failing, false);
skip.failing = bindFailing(false, 'skip');
skip.failing.each = bindEach(skip.failing, false);

test.failing = bindFailing(false);
test.failing.each = bindEach(test.failing, false);
test.only = only;
test.skip = skip;
test.concurrent = concurrentTest;
concurrentTest.only = concurrentOnly;
concurrentTest.skip = skip;
concurrentTest.failing = bindFailing(true);
concurrentTest.failing.each = bindEach(concurrentTest.failing, false);
concurrentOnly.failing = bindFailing(true, 'only');
concurrentOnly.failing.each = bindEach(concurrentOnly.failing, false);

return test;
})();
Expand Down
9 changes: 7 additions & 2 deletions packages/jest-types/src/Global.ts
Expand Up @@ -106,10 +106,15 @@ export interface HookBase {
(fn: HookFn, timeout?: number): void;
}

export interface Failing {
(testName?: TestNameLike, fn?: TestFn, timeout?: number): void | never;
SimenB marked this conversation as resolved.
Show resolved Hide resolved
each?: Each<TestFn>;
SimenB marked this conversation as resolved.
Show resolved Hide resolved
}

export interface ItBase {
(testName: TestNameLike, fn: TestFn, timeout?: number): void;
each: Each<TestFn>;
failing(testName: TestNameLike, fn: TestFn, timeout?: number): void;
failing: Failing;
}

export interface It extends ItBase {
Expand All @@ -121,7 +126,7 @@ export interface It extends ItBase {
export interface ItConcurrentBase {
(testName: TestNameLike, testFn: ConcurrentTestFn, timeout?: number): void;
each: Each<ConcurrentTestFn>;
failing(testName: TestNameLike, fn: ConcurrentTestFn, timeout?: number): void;
failing: Failing;
}

export interface ItConcurrentExtended extends ItConcurrentBase {
Expand Down