Skip to content

Commit

Permalink
change way of fixing uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
framini committed May 2, 2022
1 parent 020fd4f commit 4a5f220
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
5 changes: 1 addition & 4 deletions packages/js/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,5 @@ module.exports = {
transform: {
'\\.[jt]sx?$': ['babel-jest', { configFile: './../../babel.config.js' }],
},
transformIgnorePatterns: [
'<rootDir>/node_modules/uuid',
],
setupFiles: ['./src/setupTests.ts'],
resolver: '<rootDir>/test/resolver.js',
}
8 changes: 0 additions & 8 deletions packages/js/src/setupTests.ts

This file was deleted.

28 changes: 28 additions & 0 deletions packages/js/test/resolver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// @see https://github.com/microsoft/accessibility-insights-web/pull/5421/commits/9ad4e618019298d82732d49d00aafb846fb6bac7
module.exports = (path, options) => {
// Call the defaultResolver, so we leverage its cache, error handling, etc.
return options.defaultResolver(path, {
...options,
// Use packageFilter to process parsed `package.json` before the resolution (see https://www.npmjs.com/package/resolve#resolveid-opts-cb)
packageFilter: (pkg) => {
// This is a workaround for https://github.com/uuidjs/uuid/pull/616
//
// jest-environment-jsdom 28+ tries to use browser exports instead of default exports,
// but uuid only offers an ESM browser export and not a CommonJS one. Jest does not yet
// support ESM modules natively, so this causes a Jest error related to trying to parse
// "export" syntax.
//
// This workaround prevents Jest from considering uuid's module-based exports at all;
// it falls back to uuid's CommonJS+node "main" property.
//
// Once we're able to migrate our Jest config to ESM and a browser crypto
// implementation is available for the browser+ESM version of uuid to use (eg, via
// https://github.com/jsdom/jsdom/pull/3352 or a similar polyfill), this can go away.
if (pkg.name === 'uuid') {
delete pkg['exports']
delete pkg['module']
}
return pkg
},
})
}

0 comments on commit 4a5f220

Please sign in to comment.