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

Make testFailureExitCode compatible with bail option #10958

Merged
merged 7 commits into from Dec 24, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -27,6 +27,7 @@
- `[jest-circus]` Fix `testLocation` on Windows when using `test.each` ([#10871](https://github.com/facebook/jest/pull/10871))
- `[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-cli]` Use testFailureExitCode when bailing from a failed test ([#10958](https://github.com/facebook/jest/pull/10958))
- `[jest-each]` [**BREAKING**] Ignore excess words in headings ([#8766](https://github.com/facebook/jest/pull/8766))
- `[jest-environment-jsdom]` Use inner realm’s `ArrayBuffer` constructor ([#10885](https://github.com/facebook/jest/pull/10885))
- `[jest-globals]` [**BREAKING**] Disallow return values other than a `Promise` from hooks and tests ([#10512](https://github.com/facebook/jest/pull/10512))
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