Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<typeof ComponentAnnotation>()),
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 = () => <div />;', id)).resolves.toBeNull();
}

expect(warn).toHaveBeenCalledTimes(1);
expect(warn).toHaveBeenCalledWith(`[@sentry/bundler-plugins] ${MESSAGE}`);
});
});
Original file line number Diff line number Diff line change
@@ -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 => {
Expand All @@ -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 });

Expand All @@ -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 = () => <div />;', id)).resolves.toBeNull();
}

expect(warn).toHaveBeenCalledTimes(1);
expect(warn).toHaveBeenCalledWith(`[@sentry/bundler-plugins] ${MESSAGE}`);
});
});
Loading