From 6bf6dfc68880c1f432e39e150eefc3c3296263e9 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sun, 15 Apr 2018 12:22:20 +0200 Subject: [PATCH 1/2] always return object from babel-jest transform --- CHANGELOG.md | 1 + packages/babel-jest/src/__tests__/index.js | 33 ------------------- packages/babel-jest/src/index.js | 11 +------ .../jest-runtime/src/script_transformer.js | 1 - types/Transform.js | 1 - 5 files changed, 2 insertions(+), 45 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 47daaf340e1a..84f70c875334 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -108,6 +108,7 @@ ### Chore & Maintenance +* `[babel-jest]` [**BREAKING**] Always return object from transformer (TBD) * `[jest-jasmine2]` Simplify `Env.execute` and TreeProcessor to setup and clean resources for the top suite the same way as for all of the children suites ([#5885](https://github.com/facebook/jest/pull/5885)) diff --git a/packages/babel-jest/src/__tests__/index.js b/packages/babel-jest/src/__tests__/index.js index 38423c2c1ff1..80a39f87108c 100644 --- a/packages/babel-jest/src/__tests__/index.js +++ b/packages/babel-jest/src/__tests__/index.js @@ -31,39 +31,6 @@ const mockConfig = { test(`Returns source string with inline maps when no transformOptions is passed`, () => { const result = babelJest.process(sourceString, 'dummy_path.js', mockConfig); - expect(typeof result).toBe('string'); - expect(result).toMatch('//# sourceMappingURL'); - expect(result).toMatch('customMultiply'); -}); - -test(`Returns source string with inline maps when transformOptions - is passed but doesn't have returnSourceString passed`, () => { - const result = babelJest.process( - sourceString, - 'dummy_path.js', - mockConfig, - {}, - ); - expect(typeof result).toBe('string'); - expect(result).toMatch('//# sourceMappingURL'); - expect(result).toMatch('customMultiply'); -}); - -test(`Returns source string with inline maps when transformOptions - is passed and returnSourceString is true`, () => { - const result = babelJest.process(sourceString, 'dummy_path.js', mockConfig, { - returnSourceString: true, - }); - expect(typeof result).toBe('string'); - expect(result).toMatch('//# sourceMappingURL'); - expect(result).toMatch('customMultiply'); -}); - -test(`Returns source string with inline maps when transformOptions - is passed and returnSourceString is false`, () => { - const result = babelJest.process(sourceString, 'dummy_path.js', mockConfig, { - returnSourceString: false, - }); expect(typeof result).toBe('object'); expect(result.code).toBeDefined(); expect(result.map).toBeDefined(); diff --git a/packages/babel-jest/src/index.js b/packages/babel-jest/src/index.js index 223ce85a56f9..46333a98b9ef 100644 --- a/packages/babel-jest/src/index.js +++ b/packages/babel-jest/src/index.js @@ -135,16 +135,7 @@ const createTransformer = (options: any): Transformer => { // babel v7 might return null in the case when the file has been ignored. const transformResult = babelTransform(src, theseOptions); - if (!transformResult) { - return src; - } - - const shouldReturnCodeOnly = - transformOptions == null || - transformOptions.returnSourceString == null || - transformOptions.returnSourceString === true; - - return shouldReturnCodeOnly ? transformResult.code : transformResult; + return transformResult || src; }, }; }; diff --git a/packages/jest-runtime/src/script_transformer.js b/packages/jest-runtime/src/script_transformer.js index 0f5890e55934..43604830a335 100644 --- a/packages/jest-runtime/src/script_transformer.js +++ b/packages/jest-runtime/src/script_transformer.js @@ -217,7 +217,6 @@ export default class ScriptTransformer { if (transform && shouldCallTransform) { const processed = transform.process(content, filename, this._config, { instrument, - returnSourceString: false, }); if (typeof processed === 'string') { diff --git a/types/Transform.js b/types/Transform.js index 3747720537c4..b769fa8a4c17 100644 --- a/types/Transform.js +++ b/types/Transform.js @@ -23,7 +23,6 @@ export type TransformResult = {| export type TransformOptions = {| instrument: boolean, - returnSourceString?: boolean, |}; export type CacheKeyOptions = {| From d5427430e281a1230cd2b9a27aa3ea6d51fa7332 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sun, 15 Apr 2018 12:23:52 +0200 Subject: [PATCH 2/2] link to PR --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 84f70c875334..e61d7ccd7134 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -108,7 +108,8 @@ ### Chore & Maintenance -* `[babel-jest]` [**BREAKING**] Always return object from transformer (TBD) +* `[babel-jest]` [**BREAKING**] Always return object from transformer + ([#5991](https://github.com/facebook/jest/pull/5991)) * `[jest-jasmine2]` Simplify `Env.execute` and TreeProcessor to setup and clean resources for the top suite the same way as for all of the children suites ([#5885](https://github.com/facebook/jest/pull/5885))