Skip to content

Commit

Permalink
fix(jest): make assetFileTransformer return an object (facebook#33756)
Browse files Browse the repository at this point in the history
Summary:
Fixes facebook#33751
Relates to facebook#33576

Jest 28 removed support for returning a string in the process method of a transformer (https://jestjs.io/docs/upgrading-to-jest28#transformer).

This PR changes assetFileTransformer to return an object instead of a string.

## Changelog

[Internal] [Fixed] - Return object from assetFileTransformer

Pull Request resolved: facebook#33756

Test Plan: Tests pass with Jest 28 when this change is made.

Reviewed By: cipolleschi

Differential Revision: D37242038

Pulled By: cortinico

fbshipit-source-id: d8a5054f5378183f644cd1458785084b26782193
  • Loading branch information
geraintwhite authored and danilobuerger committed Aug 10, 2022
1 parent bece810 commit a729d57
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions jest/assetFileTransformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ module.exports = {
// the correct images are loaded for components. Essentially
// require('img1.png') becomes `Object { "testUri": 'path/to/img1.png' }` in
// the Jest snapshot.
process: (_, filename) =>
`module.exports = {
process: (_, filename) => ({
code: `module.exports = {
testUri:
${JSON.stringify(
path.relative(__dirname, filename).replace(/\\/g, '/'),
)}
};`,
}),
getCacheKey: createCacheKeyFunction([__filename]),
};

0 comments on commit a729d57

Please sign in to comment.