From 5a47d736b0e45ba977c333afd60a5894fd44d18b Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Mon, 2 Nov 2026 09:08:37 +0000 Subject: [PATCH] test(bundler-plugins): Fix flaky parser-unavailable annotation test The first test in the file timed out on loaded CI runners because it re-imported `src/core` after `vi.resetModules()`, so the cold transform of that module graph counted against the 5s test timeout. Import the leaf module statically and move the console variant into its own file, which gives it fresh "warn once" module state without `vi.resetModules()`. --- ...otation-parser-unavailable-console.test.ts | 31 +++++++++++++++++++ ...nent-annotation-parser-unavailable.test.ts | 22 ++----------- 2 files changed, 34 insertions(+), 19 deletions(-) create mode 100644 packages/bundler-plugins/test/core/component-annotation-parser-unavailable-console.test.ts diff --git a/packages/bundler-plugins/test/core/component-annotation-parser-unavailable-console.test.ts b/packages/bundler-plugins/test/core/component-annotation-parser-unavailable-console.test.ts new file mode 100644 index 000000000000..1294e1d9c43d --- /dev/null +++ b/packages/bundler-plugins/test/core/component-annotation-parser-unavailable-console.test.ts @@ -0,0 +1,31 @@ +import { afterEach, describe, expect, it, vi } from 'vitest'; + +import { createComponentNameAnnotateHooks } from '../../src/core/component-annotate-hooks'; +import type * as ComponentAnnotation from '../../src/core/component-annotation-oxc'; + +vi.mock('../../src/core/component-annotation-oxc', async importOriginal => { + return { + ...(await importOriginal()), + getOxcParseAstAsync: vi.fn(async () => null), + }; +}); + +const MESSAGE = 'Could not load `oxc-parser` for this platform. React components will not be annotated.'; + +describe('createComponentNameAnnotateHooks without a parser or logger', () => { + afterEach(() => { + vi.restoreAllMocks(); + }); + + it('warns once through the console across hooks', async () => { + const warn = vi.spyOn(console, 'warn').mockImplementation(() => {}); + + for (const id of ['/src/app.jsx', '/src/other.jsx']) { + const { transform } = createComponentNameAnnotateHooks([], false); + await expect(transform('export const App = () =>
;', id)).resolves.toBeNull(); + } + + expect(warn).toHaveBeenCalledTimes(1); + expect(warn).toHaveBeenCalledWith(`[@sentry/bundler-plugins] ${MESSAGE}`); + }); +}); diff --git a/packages/bundler-plugins/test/core/component-annotation-parser-unavailable.test.ts b/packages/bundler-plugins/test/core/component-annotation-parser-unavailable.test.ts index fc60b926ddf9..6ea45b4916f3 100644 --- a/packages/bundler-plugins/test/core/component-annotation-parser-unavailable.test.ts +++ b/packages/bundler-plugins/test/core/component-annotation-parser-unavailable.test.ts @@ -1,5 +1,6 @@ -import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import { afterEach, describe, expect, it, vi } from 'vitest'; +import { createComponentNameAnnotateHooks } from '../../src/core/component-annotate-hooks'; import type * as ComponentAnnotation from '../../src/core/component-annotation-oxc'; vi.mock('../../src/core/component-annotation-oxc', async importOriginal => { @@ -11,17 +12,13 @@ vi.mock('../../src/core/component-annotation-oxc', async importOriginal => { const MESSAGE = 'Could not load `oxc-parser` for this platform. React components will not be annotated.'; +// The "warn once" flag is module state, so the console variant lives in its own file to get a fresh module. describe('createComponentNameAnnotateHooks without a parser', () => { - beforeEach(() => { - vi.resetModules(); - }); - afterEach(() => { vi.restoreAllMocks(); }); it('leaves files unchanged and warns once through the logger', async () => { - const { createComponentNameAnnotateHooks } = await import('../../src/core'); const logger = { info: vi.fn(), warn: vi.fn(), error: vi.fn(), debug: vi.fn() }; const { transform } = createComponentNameAnnotateHooks([], false, { logger }); @@ -31,17 +28,4 @@ describe('createComponentNameAnnotateHooks without a parser', () => { expect(logger.warn).toHaveBeenCalledTimes(1); expect(logger.warn).toHaveBeenCalledWith(MESSAGE); }); - - it('warns once through the console across hooks created without a logger', async () => { - const { createComponentNameAnnotateHooks } = await import('../../src/core'); - const warn = vi.spyOn(console, 'warn').mockImplementation(() => {}); - - for (const id of ['/src/app.jsx', '/src/other.jsx']) { - const { transform } = createComponentNameAnnotateHooks([], false); - await expect(transform('export const App = () =>
;', id)).resolves.toBeNull(); - } - - expect(warn).toHaveBeenCalledTimes(1); - expect(warn).toHaveBeenCalledWith(`[@sentry/bundler-plugins] ${MESSAGE}`); - }); });