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

fix: handle null being passed to createTransformer #9955

Merged
merged 2 commits into from May 3, 2020
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -6,6 +6,7 @@

### Fixes

- `[babel-jest]` Handle `null` being passed to `createTransformer` ([#9955](https://github.com/facebook/jest/pull/9955))
- `[jest-circus, jest-console, jest-jasmine2, jest-reporters, jest-util, pretty-format]` Fix time durating formatting and consolidate time formatting code ([#9765](https://github.com/facebook/jest/pull/9765))
- `[jest-circus]` [**BREAKING**] Fail tests if a test takes a done callback and have return values ([#9129](https://github.com/facebook/jest/pull/9129))
- `[jest-circus]` [**BREAKING**] Throw a proper error if a test / hook is defined asynchronously ([#8096](https://github.com/facebook/jest/pull/8096))
Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/__snapshots__/transform.test.ts.snap
Expand Up @@ -6,7 +6,7 @@ FAIL __tests__/ignoredFile.test.js

babel-jest: Babel ignores __tests__/ignoredFile.test.js - make sure to include the file in Jest's transformIgnorePatterns as well.

at loadBabelConfig (../../../packages/babel-jest/build/index.js:178:13)
at loadBabelConfig (../../../packages/babel-jest/build/index.js:180:13)
`;

exports[`babel-jest instruments only specific files and collects coverage 1`] = `
Expand Down
18 changes: 18 additions & 0 deletions packages/babel-jest/src/__tests__/index.ts
Expand Up @@ -97,3 +97,21 @@ describe('caller option correctly merges from defaults and options', () => {
);
});
});

test('can pass null to createTransformer', () => {
const transformer = babelJest.createTransformer(null);
transformer.process(sourceString, 'dummy_path.js', makeProjectConfig(), {
instrument: false,
});

expect(loadPartialConfig).toHaveBeenCalledTimes(1);
expect(loadPartialConfig).toHaveBeenCalledWith(
expect.objectContaining({
caller: {
name: 'babel-jest',
supportsDynamicImport: false,
supportsStaticESM: false,
},
}),
);
});
3 changes: 2 additions & 1 deletion packages/babel-jest/src/index.ts
Expand Up @@ -41,8 +41,9 @@ interface BabelJestTransformOptions extends TransformOptions {
}

const createTransformer = (
inputOptions: TransformOptions = {},
userOptions?: TransformOptions | null,
): BabelJestTransformer => {
const inputOptions: TransformOptions = userOptions ?? {};
const options: BabelJestTransformOptions = {
...inputOptions,
caller: {
Expand Down