mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Add custom jest resolver to fix requiring "uuid" module
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
parent
1a6b11525d
commit
7627d7a426
34
packages/infrastructure/jest/jest-28-resolver.js
Normal file
34
packages/infrastructure/jest/jest-28-resolver.js
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
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.
|
||||||
|
switch (pkg.name) {
|
||||||
|
case "uuid":
|
||||||
|
delete pkg["exports"];
|
||||||
|
delete pkg["module"];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return pkg;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
@ -1,5 +1,9 @@
|
|||||||
|
const path = require('path');
|
||||||
|
|
||||||
module.exports = (rootDir) => {
|
module.exports = (rootDir) => {
|
||||||
const shared = {
|
const shared = {
|
||||||
|
"resolver": path.join(__dirname, "jest-28-resolver.js"),
|
||||||
|
|
||||||
transform: {
|
transform: {
|
||||||
"^.+\\.(t|j)sx?$": ["@swc/jest", { cwd: rootDir }],
|
"^.+\\.(t|j)sx?$": ["@swc/jest", { cwd: rootDir }],
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user