diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 28a1e75cab7..8a77a2911dc 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -453,7 +453,7 @@ /lerna.json @grafana/frontend-ops /.prettierrc.js @grafana/frontend-ops /.vim @zoltanbedi -/jest.config.js @grafana/frontend-ops +/jest.config.cjs @grafana/frontend-ops /latest.json @grafana/frontend-ops /stylelint.config.js @grafana/frontend-ops /tools/ @grafana/frontend-ops diff --git a/jest.config.js b/jest.config.cjs similarity index 88% rename from jest.config.js rename to jest.config.cjs index 5418ede2e38..f00b4d9e987 100644 --- a/jest.config.js +++ b/jest.config.cjs @@ -27,7 +27,10 @@ module.exports = { verbose: false, testEnvironment: 'jsdom', transform: { - '^.+\\.(ts|tsx|js|jsx)$': [require.resolve('ts-jest'), { isolatedModules: true }], + '^.+\\.(ts|tsx|js|jsx)$': [ + require.resolve('ts-jest'), + { tsconfig: '/tsconfig.test.json', isolatedModules: true }, + ], }, transformIgnorePatterns: [ `/node_modules/(?!${esModules})`, // exclude es modules to prevent TS complaining @@ -38,7 +41,7 @@ module.exports = { moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'], setupFiles: ['jest-canvas-mock', './public/test/jest-setup.ts'], testTimeout: 30000, - resolver: `/public/test/jest-resolver.js`, + resolver: '/public/test/jest-resolver.cjs', setupFilesAfterEnv: ['./public/test/setupTests.ts'], globals: { __webpack_public_path__: '', // empty string @@ -58,6 +61,6 @@ module.exports = { '@bsull/augurs': '/public/test/mocks/augurs.ts', }, // Log the test results with dynamic Loki tags. Drone CI only - reporters: ['default', ['/public/test/log-reporter.js', { enable: process.env.DRONE === 'true' }]], + reporters: ['default', ['/public/test/log-reporter.cjs', { enable: process.env.DRONE === 'true' }]], watchPlugins: ['jest-watch-typeahead/filename', 'jest-watch-typeahead/testname'], }; diff --git a/public/test/jest-resolver.js b/public/test/jest-resolver.cjs similarity index 100% rename from public/test/jest-resolver.js rename to public/test/jest-resolver.cjs diff --git a/public/test/log-reporter.js b/public/test/log-reporter.cjs similarity index 100% rename from public/test/log-reporter.js rename to public/test/log-reporter.cjs diff --git a/tsconfig.test.json b/tsconfig.test.json new file mode 100644 index 00000000000..08c8c401ff7 --- /dev/null +++ b/tsconfig.test.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + // Vite uses `bundler` module resolution but Jest doesn't like it so we use `node`. + "moduleResolution": "node" + } +}