// Same settings in every environment, otherwise tests that format dates depend on the machine process.env.TZ = 'UTC'; // The setup follows the one of the Rancher dashboard and of the Rancher extension template (rancher/ui-plugin-examples) module.exports = { roots: ['/pkg'], testEnvironment: 'jsdom', // Jest 28+ (jest-environment-jsdom) defaults package resolution to the "browser" export condition, which makes // packages like @vue/test-utils resolve their browser (global-Vue) build and throw "Vue is not defined". testEnvironmentOptions: { customExportConditions: ['node', 'node-addons'] }, setupFilesAfterEnv: ['/jest.setup.js'], watchman: false, moduleFileExtensions: ['js', 'mjs', 'json', 'vue', 'ts'], modulePaths: [''], moduleNameMapper: { '^~/(.*)$': '/$1', '^@/(.*)$': '/$1', '^@shell/(.*)$': '/node_modules/@rancher/shell/$1', '^@components/(.*)$': '/node_modules/@rancher/shell/rancher-components/$1', // At build time @pkg/ is resolved to the package that imports it (see vue.config.js of @rancher/shell) '^@pkg/harvester/(.*)$': '/pkg/harvester/$1', '^@pkg/(.*)$': '/pkg/harvester/$1', // clipboard-polyfill's package `exports` only declares an `import` condition, so map it to its ESM build // (transpiled via transformIgnorePatterns below) '^clipboard-polyfill$': '/node_modules/clipboard-polyfill/dist/es6/clipboard-polyfill.es6.js', '\\.(jpe?g|png|gif|webp|svg|mp4|webm|ogg|mp3|wav|flac|aac|woff2?|eot|ttf|otf)$': '/svgTransform.js', }, modulePathIgnorePatterns: ['/pkg/harvester/node_modules'], testPathIgnorePatterns: ['/node_modules/', '(/.*)*/__tests__/utils/'], transform: { // vue3-jest, but with TypeScript registered for the Vue compiler first, see vue3JestRegisterTs.js '^.+\\.vue$': '/vue3JestRegisterTs.js', // isolatedModules: transpile only, the types are not checked while testing '^.+\\.tsx?$': ['ts-jest', { tsconfig: { sourceMap: true, isolatedModules: true } }], // Use the project babel config (babel.config.js, which extends the one of @rancher/shell) '^.+\\.js$': '/node_modules/babel-jest', // process mjs (e.g. vee-validate ESM) with babel-jest '^.+\\.mjs$': '/node_modules/babel-jest', '^.+\\.svg$': '/svgTransform.js', }, transformIgnorePatterns: [ // @rancher/shell is shipped untranspiled, the other packages are ESM-only '/node_modules/(?!(@rancher/shell|color|color-string|color-convert|color-name|vee-validate|@vee-validate|clipboard-polyfill|intl-messageformat|@formatjs)/)', ], };