Skip to content

Commit

Permalink
Make testFailureExitCode compatible with bail option (#10958)
Browse files Browse the repository at this point in the history
  • Loading branch information
fazouane-marouane committed Dec 24, 2020
1 parent a89be24 commit f171d38
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -25,6 +25,7 @@
- `[expect]` [**BREAKING**] Make `toContain` more strict with the received type ([#10119](https://github.com/facebook/jest/pull/10119) & [#10929](https://github.com/facebook/jest/pull/10929))
- `[jest-circus]` Fixed the issue of beforeAll & afterAll hooks getting executed even if it is inside a skipped `describe` block [#10451](https://github.com/facebook/jest/issues/10451)
- `[jest-circus]` Fix `testLocation` on Windows when using `test.each` ([#10871](https://github.com/facebook/jest/pull/10871))
- `[jest-cli]` Use testFailureExitCode when bailing from a failed test ([#10958](https://github.com/facebook/jest/pull/10958))
- `[jest-config]` [**BREAKING**] Change default file extension order by moving json behind ts and tsx ([10572](https://github.com/facebook/jest/pull/10572))
- `[jest-console]` `console.dir` now respects the second argument correctly ([#10638](https://github.com/facebook/jest/pull/10638))
- `[jest-each]` [**BREAKING**] Ignore excess words in headings ([#8766](https://github.com/facebook/jest/pull/8766))
Expand Down
26 changes: 26 additions & 0 deletions e2e/__tests__/testFailureExitCode.test.ts
Expand Up @@ -38,3 +38,29 @@ test('exits with a specified code when test fail', () => {
({exitCode} = runJest(DIR));
expect(exitCode).toBe(1);
});

test('exits with a specified code when bailing from a failed test', () => {
writeFiles(DIR, {
'__tests__/test.test.js': `test('test', () => { expect(1).toBe(2); });`,
'__tests__/test2.test.js': `test('test2', () => { expect(1).toBe(2); });`,
'package.json': JSON.stringify({
jest: {testEnvironment: 'node', testFailureExitCode: 99},
}),
});

let {exitCode} = runJest(DIR, ['--bail']);
expect(exitCode).toBe(99);

({exitCode} = runJest(DIR, ['--bail', '--testFailureExitCode', '77']));
expect(exitCode).toBe(77);

writeFiles(DIR, {
'__tests__/test.test.js': `test('test', () => { expect(1).toBe(2); });`,
'__tests__/test2.test.js': `test('test2', () => { expect(1).toBe(2); });`,
'package.json': JSON.stringify({
jest: {testEnvironment: 'node'},
}),
});
({exitCode} = runJest(DIR));
expect(exitCode).toBe(1);
});
3 changes: 2 additions & 1 deletion packages/jest-core/src/TestScheduler.ts
Expand Up @@ -436,7 +436,8 @@ export default class TestScheduler {
try {
await this._dispatcher.onRunComplete(contexts, aggregatedResults);
} finally {
exit(1);
const exitCode = this._globalConfig.testFailureExitCode;
exit(exitCode);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/pretty-format/src/__tests__/ReactElement.test.ts
Expand Up @@ -15,7 +15,7 @@ setPrettyPrint([ReactElement]);

describe('ReactElement Plugin', () => {
let forwardRefComponent: {
(_props: unknown, _ref: unknown): unknown;
(_props: unknown, _ref: unknown): React.ReactElement | null;
displayName?: string;
};

Expand Down
2 changes: 1 addition & 1 deletion packages/pretty-format/src/__tests__/react.test.tsx
Expand Up @@ -706,7 +706,7 @@ test('ReactTestComponent plugin highlights syntax with color from theme option',
});

test('supports forwardRef with a child', () => {
function Cat(props: any) {
function Cat(props: any, _ref: any) {
return React.createElement('div', props, props.children);
}

Expand Down

0 comments on commit f171d38

Please sign in to comment.