Skip to content

Commit

Permalink
refactor: upgrade jest to v28
Browse files Browse the repository at this point in the history
  • Loading branch information
mdalpozzo authored and Brian-Holland committed Jun 20, 2024
1 parent 834aeae commit 5f07cdc
Show file tree
Hide file tree
Showing 4 changed files with 836 additions and 717 deletions.
1 change: 1 addition & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const config: Config.InitialOptions = {
setupFilesAfterEnv: ['<rootDir>src/tooling/helpers.ts'],
testEnvironment: 'jsdom',
coveragePathIgnorePatterns: ['tooling'],
resolver: `<rootDir>/src/tests/common/resolver.js`,
};

export default config;
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"@babel/preset-react": "^7.24.7",
"@babel/preset-typescript": "^7.24.7",
"@chromatic-com/storybook": "^1.5.0",
"@jest/types": "^27.5.1",
"@jest/types": "^28.1.3",
"@storybook/addon-a11y": "^8.1.5",
"@storybook/addon-actions": "^8.1.5",
"@storybook/addon-controls": "^8.1.5",
Expand All @@ -111,7 +111,7 @@
"@types/enzyme": "^3.10.8",
"@types/enzyme-adapter-react-16": "^1.0.6",
"@types/invariant": "^2.2.35",
"@types/jest": "^27.4.1",
"@types/jest": "^28.1.3",
"@types/lodash.flow": "^3.5.6",
"@types/lodash.isequal": "^4.5.5",
"@types/lodash.noop": "^3.0.6",
Expand Down Expand Up @@ -143,7 +143,8 @@
"fs-extra": "10.0.1",
"glob": "^7.1.6",
"identity-obj-proxy": "^3.0.0",
"jest": "^27.5.1",
"jest": "^28.1.3",
"jest-environment-jsdom": "^29.7.0",
"jsdom": "^11.12.0",
"jsdom-global": "^3.0.2",
"prettier": "^2.5.1",
Expand Down
33 changes: 33 additions & 0 deletions src/tests/common/resolver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

// see the following docs for more info:
// https://jest-archive-august-2023.netlify.app/docs/28.x/upgrading-to-jest28/#packagejson-exports
// https://github.com/microsoft/accessibility-insights-web/pull/5421#issuecomment-1109168149

// Call the defaultResolver, so we leverage its cache, error handling, etc.
module.exports = (path, options) =>
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;
},
});
Loading

0 comments on commit 5f07cdc

Please sign in to comment.