Skip to content

Commit 5d1baba

Browse files
SimenBcpojer
authored andcommitted
always return object from babel-jest transform (#5991)
* always return object from babel-jest transform * link to PR
1 parent ea53f3c commit 5d1baba

File tree

5 files changed

+3
-45
lines changed

5 files changed

+3
-45
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@
110110

111111
### Chore & Maintenance
112112

113+
* `[babel-jest]` [**BREAKING**] Always return object from transformer
114+
([#5991](https://github.com/facebook/jest/pull/5991))
113115
* `[jest-jasmine2]` Simplify `Env.execute` and TreeProcessor to setup and clean
114116
resources for the top suite the same way as for all of the children suites
115117
([#5885](https://github.com/facebook/jest/pull/5885))

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

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -31,39 +31,6 @@ const mockConfig = {
3131

3232
test(`Returns source string with inline maps when no transformOptions is passed`, () => {
3333
const result = babelJest.process(sourceString, 'dummy_path.js', mockConfig);
34-
expect(typeof result).toBe('string');
35-
expect(result).toMatch('//# sourceMappingURL');
36-
expect(result).toMatch('customMultiply');
37-
});
38-
39-
test(`Returns source string with inline maps when transformOptions
40-
is passed but doesn't have returnSourceString passed`, () => {
41-
const result = babelJest.process(
42-
sourceString,
43-
'dummy_path.js',
44-
mockConfig,
45-
{},
46-
);
47-
expect(typeof result).toBe('string');
48-
expect(result).toMatch('//# sourceMappingURL');
49-
expect(result).toMatch('customMultiply');
50-
});
51-
52-
test(`Returns source string with inline maps when transformOptions
53-
is passed and returnSourceString is true`, () => {
54-
const result = babelJest.process(sourceString, 'dummy_path.js', mockConfig, {
55-
returnSourceString: true,
56-
});
57-
expect(typeof result).toBe('string');
58-
expect(result).toMatch('//# sourceMappingURL');
59-
expect(result).toMatch('customMultiply');
60-
});
61-
62-
test(`Returns source string with inline maps when transformOptions
63-
is passed and returnSourceString is false`, () => {
64-
const result = babelJest.process(sourceString, 'dummy_path.js', mockConfig, {
65-
returnSourceString: false,
66-
});
6734
expect(typeof result).toBe('object');
6835
expect(result.code).toBeDefined();
6936
expect(result.map).toBeDefined();

packages/babel-jest/src/index.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,7 @@ const createTransformer = (options: any): Transformer => {
135135
// babel v7 might return null in the case when the file has been ignored.
136136
const transformResult = babelTransform(src, theseOptions);
137137

138-
if (!transformResult) {
139-
return src;
140-
}
141-
142-
const shouldReturnCodeOnly =
143-
transformOptions == null ||
144-
transformOptions.returnSourceString == null ||
145-
transformOptions.returnSourceString === true;
146-
147-
return shouldReturnCodeOnly ? transformResult.code : transformResult;
138+
return transformResult || src;
148139
},
149140
};
150141
};

packages/jest-runtime/src/script_transformer.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ export default class ScriptTransformer {
217217
if (transform && shouldCallTransform) {
218218
const processed = transform.process(content, filename, this._config, {
219219
instrument,
220-
returnSourceString: false,
221220
});
222221

223222
if (typeof processed === 'string') {

types/Transform.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export type TransformResult = {|
2323

2424
export type TransformOptions = {|
2525
instrument: boolean,
26-
returnSourceString?: boolean,
2726
|};
2827

2928
export type CacheKeyOptions = {|

0 commit comments

Comments
 (0)