Skip to content

Commit

Permalink
always return object from babel-jest transform (#5991)
Browse files Browse the repository at this point in the history
* always return object from babel-jest transform

* link to PR
  • Loading branch information
SimenB authored and cpojer committed Apr 15, 2018
1 parent ea53f3c commit 5d1baba
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 45 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@

### Chore & Maintenance

* `[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))
Expand Down
33 changes: 0 additions & 33 deletions packages/babel-jest/src/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
11 changes: 1 addition & 10 deletions packages/babel-jest/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
};
};
Expand Down
1 change: 0 additions & 1 deletion packages/jest-runtime/src/script_transformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
1 change: 0 additions & 1 deletion types/Transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export type TransformResult = {|

export type TransformOptions = {|
instrument: boolean,
returnSourceString?: boolean,
|};

export type CacheKeyOptions = {|
Expand Down

0 comments on commit 5d1baba

Please sign in to comment.