-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathjest.config.js
More file actions
78 lines (72 loc) · 2.79 KB
/
Copy pathjest.config.js
File metadata and controls
78 lines (72 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// force timezone to UTC to allow tests to work regardless of local timezone
// generally used by snapshots, but can affect specific tests
process.env.TZ = 'UTC';
const path = require('path');
const { grafanaESModules, nodeModulesToTransform } = require('./.config/jest/utils');
const baseConfig = require('./.config/jest.config');
const swcTransform = [
'@swc/jest',
{
sourceMaps: 'inline',
jsc: {
parser: {
syntax: 'typescript',
tsx: true,
decorators: false,
dynamicImport: true,
},
transform: {
react: {
runtime: 'automatic',
},
},
},
module: {
type: 'commonjs',
},
},
];
// Project 1: the Grafana plugin source (jsdom + DOM-aware setup).
const pluginProject = {
...baseConfig,
displayName: 'plugin',
rootDir: __dirname,
// Resolve @grafana/prometheus to its TypeScript source so tests don't require
// a pre-built dist (which may not exist in CI before the package is compiled).
moduleNameMapper: {
...baseConfig.moduleNameMapper,
'^@grafana/prometheus$': '<rootDir>/packages/grafana-prometheus/src/index.ts',
// Force all code (including packages/grafana-prometheus) to share the root React instance.
// Without this, the nested node_modules/react in that package causes "Invalid hook call" errors.
'^react$': '<rootDir>/node_modules/react',
'^react-dom$': '<rootDir>/node_modules/react-dom',
'^react/jsx-runtime$': '<rootDir>/node_modules/react/jsx-runtime',
'^react/jsx-dev-runtime$': '<rootDir>/node_modules/react/jsx-dev-runtime',
},
transform: { '^.+\\.(t|j)sx?$': swcTransform },
// monaco-promql ships ESM only; add it to the transform allowlist
transformIgnorePatterns: [nodeModulesToTransform([...grafanaESModules, 'monaco-promql', '@marcbachmann/cel-js'])],
};
// Project 2: the @grafana/prometheus library source under packages/grafana-prometheus.
// Reuses the plugin project's swc + jsdom + module mappers; only the discovered paths differ.
// Without this, the package's own unit tests are never run from the repo root. The package's
// own jest.config.js reuses this project (looked up by displayName) to avoid config drift.
const libraryProject = {
...pluginProject,
displayName: 'library',
testMatch: [
'<rootDir>/packages/grafana-prometheus/src/**/__tests__/**/*.{js,jsx,ts,tsx}',
'<rootDir>/packages/grafana-prometheus/src/**/*.{spec,test,jest}.{js,jsx,ts,tsx}',
],
};
// Project 3: the repo-management scripts (node env, no DOM setup).
const scriptsProject = {
displayName: 'scripts',
rootDir: __dirname,
testEnvironment: 'node',
testMatch: ['<rootDir>/scripts/**/__tests__/*.{test,spec}.{js,ts}'],
transform: { '^.+\\.(t|j)sx?$': swcTransform },
};
module.exports = {
projects: [pluginProject, libraryProject, scriptsProject],
};