From 2e8f8d5d22fe70a11d5ce407f573078ebaca6b47 Mon Sep 17 00:00:00 2001 From: Yusuke Iinuma Date: Sun, 3 May 2020 17:49:46 +0900 Subject: [PATCH] fix: handle `null` being passed to `createTransformer` (#9955) --- CHANGELOG.md | 1 + .../__snapshots__/transform.test.ts.snap | 2 +- packages/babel-jest/src/__tests__/index.ts | 18 ++++++++++++++++++ packages/babel-jest/src/index.ts | 3 ++- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac92ed7f0cd7..6bef176537ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/e2e/__tests__/__snapshots__/transform.test.ts.snap b/e2e/__tests__/__snapshots__/transform.test.ts.snap index 5ccf71e5a934..ee94c751c5ab 100644 --- a/e2e/__tests__/__snapshots__/transform.test.ts.snap +++ b/e2e/__tests__/__snapshots__/transform.test.ts.snap @@ -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`] = ` diff --git a/packages/babel-jest/src/__tests__/index.ts b/packages/babel-jest/src/__tests__/index.ts index 7bbc4f7c84d1..df0387390ce6 100644 --- a/packages/babel-jest/src/__tests__/index.ts +++ b/packages/babel-jest/src/__tests__/index.ts @@ -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, + }, + }), + ); +}); diff --git a/packages/babel-jest/src/index.ts b/packages/babel-jest/src/index.ts index 50259e0ec2cb..5a23c4fdb1d9 100644 --- a/packages/babel-jest/src/index.ts +++ b/packages/babel-jest/src/index.ts @@ -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: {