Skip to content

Commit

Permalink
fix(preprocessor): return object, not just code (facebook#33576)
Browse files Browse the repository at this point in the history
Summary:
Jest 28 will error if only a string is returned from a transfomer, it needs to be an object of `{code: string, map?: object}`. Returning an object has been supported since jestjs/jest#2290, released in Jest v20.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[Internal] [Fixed] - Return object from Jest preprocessor

Pull Request resolved: facebook#33576

Test Plan: Green CI?

Reviewed By: motiz88

Differential Revision: D35426748

Pulled By: robhogan

fbshipit-source-id: 3edb79b62b2d34274be192061817d3fcd8a7ba17
  • Loading branch information
SimenB authored and Saadnajmi committed Jan 14, 2023
1 parent 6480d37 commit 578bddd
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions jest/preprocessor_DO_NOT_USE.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ babelRegisterOnly([]);

const transformer = require('metro-react-native-babel-transformer');
module.exports = {
process(src /*: string */, file /*: string */) /*: string */ {
process(src /*: string */, file /*: string */) /*: {code: string, ...} */ {
if (nodeFiles.test(file)) {
// node specific transforms only
return babelTransformSync(src, {
filename: file,
sourceType: 'script',
...nodeOptions,
ast: false,
}).code;
});
}

const {ast} = transformer.transform({
Expand Down Expand Up @@ -111,7 +111,7 @@ module.exports = {
sourceMaps: true,
},
src,
).code;
);
},

getCacheKey: (createCacheKeyFunction([
Expand Down

0 comments on commit 578bddd

Please sign in to comment.