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 2 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 @@ -18,6 +18,7 @@

### Fixes

- `[jest-cli]` use testFailureExitCode when bailing from a failed test
- `[babel-plugin-jest-hoist]` Add `__dirname` and `__filename` to whitelisted globals ([#10903](https://github.com/facebook/jest/pull/10903))
- `[expect]` [**BREAKING**] Revise `expect.not.objectContaining()` to be the inverse of `expect.objectContaining()`, as documented. ([#10708](https://github.com/facebook/jest/pull/10708))
- `[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))
Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/jestChangedFiles.test.ts
Expand Up @@ -21,7 +21,7 @@ const HG = 'hg --config ui.username=jest_test';

const gitVersionSupportsInitialBranch = (() => {
const {stdout} = run(`${GIT} --version`);
const gitVersion = stdout.split(' ').slice(-1)[0];
const gitVersion = stdout;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was necessary fix since on my machine, it gives git version 2.24.3 (Apple Git-128)


const match = gitVersion.match(/(?<version>\d+\.\d+\.\d+)/);

Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/onlyChanged.test.ts
Expand Up @@ -17,7 +17,7 @@ const HG = 'hg --config ui.username=jest_test';

const gitVersionSupportsInitialBranch = (() => {
const {stdout} = run(`${GIT} --version`);
const gitVersion = stdout.split(' ').slice(-1)[0];
const gitVersion = stdout;

const match = gitVersion.match(/(?<version>\d+\.\d+\.\d+)/);

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