Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

always return object from babel-jest transform #5991

Merged
merged 2 commits into from
Apr 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,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