Skip to content

Commit 2e8f8d5

Browse files
authored
fix: handle null being passed to createTransformer (#9955)
1 parent 7a3c997 commit 2e8f8d5

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
### Fixes
88

9+
- `[babel-jest]` Handle `null` being passed to `createTransformer` ([#9955](https://github.com/facebook/jest/pull/9955))
910
- `[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))
1011
- `[jest-circus]` [**BREAKING**] Fail tests if a test takes a done callback and have return values ([#9129](https://github.com/facebook/jest/pull/9129))
1112
- `[jest-circus]` [**BREAKING**] Throw a proper error if a test / hook is defined asynchronously ([#8096](https://github.com/facebook/jest/pull/8096))

e2e/__tests__/__snapshots__/transform.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ FAIL __tests__/ignoredFile.test.js
66
77
babel-jest: Babel ignores __tests__/ignoredFile.test.js - make sure to include the file in Jest's transformIgnorePatterns as well.
88
9-
at loadBabelConfig (../../../packages/babel-jest/build/index.js:178:13)
9+
at loadBabelConfig (../../../packages/babel-jest/build/index.js:180:13)
1010
`;
1111

1212
exports[`babel-jest instruments only specific files and collects coverage 1`] = `

packages/babel-jest/src/__tests__/index.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,21 @@ describe('caller option correctly merges from defaults and options', () => {
9797
);
9898
});
9999
});
100+
101+
test('can pass null to createTransformer', () => {
102+
const transformer = babelJest.createTransformer(null);
103+
transformer.process(sourceString, 'dummy_path.js', makeProjectConfig(), {
104+
instrument: false,
105+
});
106+
107+
expect(loadPartialConfig).toHaveBeenCalledTimes(1);
108+
expect(loadPartialConfig).toHaveBeenCalledWith(
109+
expect.objectContaining({
110+
caller: {
111+
name: 'babel-jest',
112+
supportsDynamicImport: false,
113+
supportsStaticESM: false,
114+
},
115+
}),
116+
);
117+
});

packages/babel-jest/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ interface BabelJestTransformOptions extends TransformOptions {
4141
}
4242

4343
const createTransformer = (
44-
inputOptions: TransformOptions = {},
44+
userOptions?: TransformOptions | null,
4545
): BabelJestTransformer => {
46+
const inputOptions: TransformOptions = userOptions ?? {};
4647
const options: BabelJestTransformOptions = {
4748
...inputOptions,
4849
caller: {

0 commit comments

Comments
 (0)