Repository navigation
Expand file tree
/
Copy pathjest.config.snapshots.ts
More file actions
126 lines (115 loc) · 4.57 KB
/
Copy pathjest.config.snapshots.ts
File metadata and controls
126 lines (115 loc) · 4.57 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import process from 'node:process';
import type {Config} from '@jest/types';
import type {Options as SwcOptions} from '@swc/core';
const {CI, GITHUB_PR_SHA, GITHUB_PR_REF, GITHUB_RUN_ID, GITHUB_RUN_ATTEMPT, SENTRY_DSN} =
process.env;
// `GITHUB_PR_REF` is the head branch name on pull requests, but a fully qualified
// ref (`refs/heads/master`) on pushes. Normalize both down to a bare branch name
// for tagging. Keep the master check on the raw ref: only a push to master is
// `refs/heads/master`, so a pull request opened from a branch named `master`
// stays `ci:pull_request`.
const BRANCH = GITHUB_PR_REF?.replace(/^refs\/heads\//, '');
const IS_MASTER_BRANCH = GITHUB_PR_REF === 'refs/heads/master';
const swcConfig: SwcOptions = {
isModule: true,
module: {
type: 'commonjs',
},
sourceMaps: 'inline',
jsc: {
target: 'esnext',
parser: {
syntax: 'typescript',
tsx: true,
dynamicImport: true,
},
transform: {
react: {
runtime: 'automatic',
importSource: '@emotion/react',
},
},
experimental: {
plugins: [
['@swc-contrib/mut-cjs-exports', {}],
[
'@swc/plugin-emotion',
{
sourceMap: false,
autoLabel: 'never',
},
],
],
},
},
};
/**
* ESM packages that need to be transformed.
*/
const ESM_NODE_MODULES = ['screenfull', 'cbor2', 'nuqs', 'color'];
const config: Config.InitialOptions = {
testTimeout: 30_000,
cacheDirectory: '.cache/jest-snapshots',
// testEnvironment and testMatch are the core differences between this and the main config
testEnvironment: '<rootDir>/tests/js/sentry-test/jest-environment-node.js',
testMatch: ['<rootDir>/static/**/*.snapshots.tsx'],
testPathIgnorePatterns: ['/node_modules/', '<rootDir>/static/packages/scraps/'],
// Coding agents check out nested git worktrees under .claude/worktrees/, each a
// full copy of this repo. jest-haste-map crawls all of rootDir, so every manual
// mock in static/ collides with its copies and the file that ends up backing
// jest.mock() is decided by crawl order. Keep the module map to this checkout.
modulePathIgnorePatterns: ['<rootDir>/\\.claude/'],
testEnvironmentOptions: {
sentryConfig: {
init: {
dsn: Boolean(CI) && Boolean(GITHUB_PR_REF) && SENTRY_DSN ? SENTRY_DSN : false,
environment: CI ? (IS_MASTER_BRANCH ? 'ci:master' : 'ci:pull_request') : 'local',
tracesSampleRate: CI ? 0.75 : 0,
profilesSampleRate: 0,
transportOptions: {keepAlive: true},
},
// Set as tags (for error events) and, via withTagsAsSpanAttributes, as span
// attributes, so every span in the trace can be filtered by them.
tags: {
'ci.branch': BRANCH,
'ci.commit': GITHUB_PR_SHA,
'ci.github_run_attempt': GITHUB_RUN_ATTEMPT,
'ci.github_actions_run': `https://github.com/getsentry/sentry/actions/runs/${GITHUB_RUN_ID}`,
},
},
},
setupFiles: ['<rootDir>/tests/js/sentry-test/snapshots/snapshot-setup.ts'],
setupFilesAfterEnv: ['<rootDir>/tests/js/sentry-test/snapshots/snapshot-framework.ts'],
moduleNameMapper: {
'\\.(css|less|png|gif|jpg|woff|mp4)$':
'<rootDir>/tests/js/sentry-test/mocks/importStyleMock.js',
'^sentry/(.*)': '<rootDir>/static/app/$1',
'^@sentry/scraps/text$': '<rootDir>/static/app/components/core/text',
'^@sentry/scraps$': '<rootDir>/static/packages/scraps/src/index.ts',
// The app falls back to core components until they move into scraps.
'^@sentry/scraps/(.*)$': [
'<rootDir>/static/packages/scraps/src/$1',
'<rootDir>/static/app/components/core/$1',
],
'^getsentry/(.*)': '<rootDir>/static/gsApp/$1',
'^admin/(.*)': '<rootDir>/static/gsAdmin/$1',
'^sentry-fixture/(.*)': '<rootDir>/tests/js/fixtures/$1',
'^sentry-test/(.*)': '<rootDir>/tests/js/sentry-test/$1',
'^getsentry-test/(.*)': '<rootDir>/tests/js/getsentry-test/$1',
'^sentry-locale/(.*)': '<rootDir>/src/sentry/locale/$1',
'\\.(svg)$': '<rootDir>/tests/js/sentry-test/mocks/svgMock.js',
'^echarts/(.*)': '<rootDir>/tests/js/sentry-test/mocks/echartsMock.js',
'^zrender/(.*)': '<rootDir>/tests/js/sentry-test/mocks/echartsMock.js',
},
transform: {
'^.+\\.[mc]?[jt]sx?$': ['@swc/jest', swcConfig],
'^.+\\.pegjs?$': '<rootDir>/tests/js/jest-pegjs-transform.js',
},
transformIgnorePatterns: [
ESM_NODE_MODULES.length
? `/node_modules/.pnpm/(?!${ESM_NODE_MODULES.join('|')})`
: '/node_modules/',
],
moduleFileExtensions: ['js', 'ts', 'jsx', 'tsx', 'pegjs'],
};
export default config;