diff --git a/jest.config.ts b/jest.config.ts index 81bfa61527463d..03c34f6c609b69 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -323,15 +323,7 @@ const config: Config.InitialOptions = { '/tests/js/setupFramework.ts', ], testMatch: testMatch || ['/(static|tests/js)/**/?(*.)+(spec|test).[jt]s?(x)'], - testPathIgnorePatterns: [ - '/tests/sentry/lang/javascript/', - // ESM-style helper scripts (e.g. scripts/genPlatformProductInfo.ts use - // `const __dirname = path.dirname(fileURLToPath(import.meta.url))`) that - // SWC's CJS transform redeclares — collides with Node's module wrapper. - // None of these are tests; keep them out of Jest's discovery entirely. - '/scripts/', - ], - modulePathIgnorePatterns: ['/scripts/'], + testPathIgnorePatterns: ['/tests/sentry/lang/javascript/'], unmockedModulePathPatterns: [ '/node_modules/react', diff --git a/scripts/extractFormFields.ts b/scripts/extractFormFields.ts index 736b94314ff6b0..da0385aeb58363 100644 --- a/scripts/extractFormFields.ts +++ b/scripts/extractFormFields.ts @@ -11,8 +11,14 @@ import {fileURLToPath} from 'node:url'; import * as ts from 'typescript'; -const __filename = fileURLToPath(import.meta.url); -const __dirname = path.dirname(__filename); +// Named THIS_FILE / THIS_DIR rather than the conventional __filename / +// __dirname so SWC's CJS transform (used by Jest) doesn't emit a +// `const __dirname = ...` that collides with the wrapper-provided +// binding and crashes the frontend test run with a SyntaxError. +// Behavior-equivalent at runtime — the originals only shadowed the +// wrapper inside this module. +const THIS_FILE = fileURLToPath(import.meta.url); +const THIS_DIR = path.dirname(THIS_FILE); interface ExtractedField { formId: string; @@ -480,14 +486,14 @@ ${registryEntries} // Main execution try { - const configPath = path.join(__dirname, '../tsconfig.json'); + const configPath = path.join(THIS_DIR, '../tsconfig.json'); const extractor = new FormFieldExtractor(configPath); console.log('🔍 Extracting form fields from TypeScript files...'); const fields = extractor.extractAllFields(); const outputPath = path.join( - __dirname, + THIS_DIR, '../static/app/components/core/form/generatedFieldRegistry.ts' ); diff --git a/scripts/genPlatformProductInfo.ts b/scripts/genPlatformProductInfo.ts index 16b31ac937ca7f..b91cb215cb7b36 100644 --- a/scripts/genPlatformProductInfo.ts +++ b/scripts/genPlatformProductInfo.ts @@ -26,8 +26,13 @@ import {fileURLToPath} from 'node:url'; import * as ts from 'typescript'; import {parse as parseYaml} from 'yaml'; -const __dirname = path.dirname(fileURLToPath(import.meta.url)); -const SENTRY_ROOT = path.resolve(__dirname, '..'); +// Named THIS_DIR rather than __dirname so SWC's CJS transform (used by Jest) +// doesn't emit a `const __dirname = ...` that collides with the wrapper- +// provided binding and crashes the whole frontend test run with a +// SyntaxError. The original `__dirname` only shadowed the wrapper inside +// this module anyway, so the rename is behavior-equivalent at runtime. +const THIS_DIR = path.dirname(fileURLToPath(import.meta.url)); +const SENTRY_ROOT = path.resolve(THIS_DIR, '..'); const DOCS_ROOT = process.env.SENTRY_DOCS_PATH ? path.resolve(process.env.SENTRY_DOCS_PATH) : path.resolve(SENTRY_ROOT, '..', 'sentry-docs');