Skip to content
Open
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
@@ -1,5 +1,6 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

import type * as ComponentAnnotateHooks 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 @@ -12,18 +13,20 @@ 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.';

describe('createComponentNameAnnotateHooks without a parser', () => {
beforeEach(() => {
let hooks: typeof ComponentAnnotateHooks;

beforeEach(async () => {
vi.resetModules();
hooks = await import('../../src/core/component-annotate-hooks');
});

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 });
const { transform } = hooks.createComponentNameAnnotateHooks([], false, { logger });

await expect(transform('export const App = () => <div />;', '/src/app.jsx')).resolves.toBeNull();
await expect(transform('export const Other = () => <span />;', '/src/other.jsx')).resolves.toBeNull();
Expand All @@ -33,11 +36,10 @@ describe('createComponentNameAnnotateHooks without a parser', () => {
});

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);
const { transform } = hooks.createComponentNameAnnotateHooks([], false);
await expect(transform('export const App = () => <div />;', id)).resolves.toBeNull();
}

Expand Down
Loading