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.

94 changes: 62 additions & 32 deletions e2e/__tests__/__snapshots__/testFailingJasmine.test.ts.snap
Expand Up @@ -34,6 +34,21 @@ FAIL __tests__/worksWithConcurrentMode.test.js

at Object.toBe (__tests__/worksWithConcurrentMode.test.js:10:16)

● block with concurrent › encountered a declaration exception

TypeError: test.concurrent.failing.each is not a function
SimenB marked this conversation as resolved.
Show resolved Hide resolved

15 | });
16 |
> 17 | test.concurrent.failing.each([
| ^
18 | {a: 1, b: 1, expected: 2},
19 | {a: 1, b: 2, expected: 3},
20 | {a: 2, b: 1, expected: 3},

at Suite.each (__tests__/worksWithConcurrentMode.test.js:17:27)
at Object.describe (__tests__/worksWithConcurrentMode.test.js:8:1)

FAIL __tests__/worksWithConcurrentOnlyMode.test.js
● block with concurrent › skipped failing test

Expand All @@ -52,6 +67,21 @@ FAIL __tests__/worksWithConcurrentOnlyMode.test.js

at Object.toBe (__tests__/worksWithConcurrentOnlyMode.test.js:10:16)

● block with concurrent › encountered a declaration exception

TypeError: test.concurrent.only.failing.each is not a function

15 | });
16 |
> 17 | test.concurrent.only.failing.each([
| ^
18 | {a: 1, b: 1, expected: 2},
19 | {a: 1, b: 2, expected: 3},
20 | {a: 2, b: 1, expected: 3},

at Suite.each (__tests__/worksWithConcurrentOnlyMode.test.js:17:32)
at Object.describe (__tests__/worksWithConcurrentOnlyMode.test.js:8:1)

FAIL __tests__/worksWithOnlyMode.test.js
● block with only, should pass › encountered a declaration exception

Expand All @@ -72,46 +102,46 @@ FAIL __tests__/worksWithOnlyMode.test.js

Jest: \`failing\` tests are only supported in \`jest-circus\`.

21 |
22 | describe('block with only, should fail', () => {
> 23 | it.only.failing('failing passes = fails, should fail', () => {
29 |
30 | describe('block with only, should fail', () => {
> 31 | it.only.failing('failing passes = fails, should fail', () => {
| ^
24 | expect(10).toBe(10);
25 | });
26 |
32 | expect(10).toBe(10);
33 | });
34 |

at Suite.failing (__tests__/worksWithOnlyMode.test.js:23:11)
at Object.describe (__tests__/worksWithOnlyMode.test.js:22:1)
at Suite.failing (__tests__/worksWithOnlyMode.test.js:31:11)
at Object.describe (__tests__/worksWithOnlyMode.test.js:30:1)

● block with only in other it, should skip › encountered a declaration exception

Jest: \`failing\` tests are only supported in \`jest-circus\`.

35 |
36 | describe('block with only in other it, should skip', () => {
> 37 | it.failing('failing passes = fails, should fail but skipped', () => {
43 |
44 | describe('block with only in other it, should skip', () => {
> 45 | it.failing('failing passes = fails, should fail but skipped', () => {
| ^
38 | expect(10).toBe(10);
39 | });
40 |
46 | expect(10).toBe(10);
47 | });
48 |

at Suite.failing (__tests__/worksWithOnlyMode.test.js:37:6)
at Object.describe (__tests__/worksWithOnlyMode.test.js:36:1)
at Suite.failing (__tests__/worksWithOnlyMode.test.js:45:6)
at Object.describe (__tests__/worksWithOnlyMode.test.js:44:1)

● block with only with different syntax, should fail › encountered a declaration exception

Jest: \`failing\` tests are only supported in \`jest-circus\`.

49 |
50 | describe('block with only with different syntax, should fail', () => {
> 51 | fit.failing('failing passes = fails, should fail 1', () => {
57 |
58 | describe('block with only with different syntax, should fail', () => {
> 59 | fit.failing('failing passes = fails, should fail 1', () => {
| ^
52 | expect(10).toBe(10);
53 | });
54 |
60 | expect(10).toBe(10);
61 | });
62 |

at Suite.failing (__tests__/worksWithOnlyMode.test.js:51:7)
at Object.describe (__tests__/worksWithOnlyMode.test.js:50:1)
at Suite.failing (__tests__/worksWithOnlyMode.test.js:59:7)
at Object.describe (__tests__/worksWithOnlyMode.test.js:58:1)

FAIL __tests__/worksWithSkipMode.test.js
● block with only, should pass › encountered a declaration exception
Expand All @@ -133,14 +163,14 @@ FAIL __tests__/worksWithSkipMode.test.js

Jest: \`failing\` tests are only supported in \`jest-circus\`.

25 |
26 | describe('block with only, should fail', () => {
> 27 | it.skip.failing('failing passes = fails, should fail', () => {
33 |
34 | describe('block with only, should fail', () => {
> 35 | it.skip.failing('failing passes = fails, should fail', () => {
| ^
28 | expect(10).toBe(10);
29 | });
30 |
36 | expect(10).toBe(10);
37 | });
38 |

at Suite.failing (__tests__/worksWithSkipMode.test.js:27:11)
at Object.describe (__tests__/worksWithSkipMode.test.js:26:1)"
at Suite.failing (__tests__/worksWithSkipMode.test.js:35:11)
at Object.describe (__tests__/worksWithSkipMode.test.js:34:1)"
`;
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