Skip to content

Commit

Permalink
fix: handle null being passed to createTransformer (#9955)
Browse files Browse the repository at this point in the history
  • Loading branch information
yinm authored May 3, 2020
1 parent 7a3c997 commit 2e8f8d5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 2e8f8d5

Please sign in to comment.