Skip to content

Commit

Permalink
fix(jest): make assetFileTransformer return an object (#33756)
Browse files Browse the repository at this point in the history
Summary:
Fixes #33751
Relates to #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: #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 facebook-github-bot committed Jun 17, 2022
1 parent ea29ae1 commit b5ff26b
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]),
};

1 comment on commit b5ff26b

@cristea2017
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it works, thx ;)

Please sign in to comment.