Skip to content

Commit 169df80

Browse files
committed
fix(plugin-typescript): refine testing types; use ui logger
1 parent fb1bbad commit 169df80

File tree

3 files changed

+13
-24
lines changed

3 files changed

+13
-24
lines changed

packages/plugin-typescript/src/lib/schema.unit.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ describe('typescriptPluginConfigSchema', () => {
1111
expect(() => typescriptPluginConfigSchema.parse({})).not.toThrow();
1212
});
1313

14-
it('accepts a configuration with tsConfigPath set', () => {
14+
it('accepts a configuration with tsconfig set', () => {
1515
expect(() =>
1616
typescriptPluginConfigSchema.parse({
1717
tsconfig,
1818
} satisfies TypescriptPluginOptions),
1919
).not.toThrow();
2020
});
2121

22-
it('accepts a configuration with tsConfigPath and empty onlyAudits', () => {
22+
it('accepts a configuration with tsconfig and empty onlyAudits', () => {
2323
expect(() =>
2424
typescriptPluginConfigSchema.parse({
2525
tsconfig,
@@ -28,7 +28,7 @@ describe('typescriptPluginConfigSchema', () => {
2828
).not.toThrow();
2929
});
3030

31-
it('accepts a configuration with tsConfigPath and full onlyAudits', () => {
31+
it('accepts a configuration with tsconfig and full onlyAudits', () => {
3232
expect(() =>
3333
typescriptPluginConfigSchema.parse({
3434
tsconfig,

packages/plugin-typescript/src/lib/utils.unit.test.ts

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
2-
import { type Audit, categoryRefSchema } from '@code-pushup/models';
3-
import { AUDITS } from './constants.js';
1+
import {describe, expect, it} from 'vitest';
2+
import {type Audit, categoryRefSchema} from '@code-pushup/models';
3+
import {ui} from '@code-pushup/utils';
4+
import {AUDITS} from './constants.js';
45
import {
56
filterAuditsByCompilerOptions,
67
filterAuditsBySlug,
@@ -99,31 +100,21 @@ describe('getCategoryRefsFromGroups', () => {
99100

100101
it('should return all groups as categoryRefs if compiler options are given', async () => {
101102
const categoryRefs = await getCategoryRefsFromGroups({
102-
tsConfigPath: 'tsconfig.json',
103+
tsconfig: 'tsconfig.json',
103104
});
104105
expect(categoryRefs).toHaveLength(3);
105106
});
106107

107108
it('should return a subset of all groups as categoryRefs if compiler options contain onlyAudits filter', async () => {
108109
const categoryRefs = await getCategoryRefsFromGroups({
109-
tsConfigPath: 'tsconfig.json',
110+
tsconfig: 'tsconfig.json',
110111
onlyAudits: ['semantic-errors'],
111112
});
112113
expect(categoryRefs).toHaveLength(1);
113114
});
114115
});
115116

116117
describe('logSkippedAudits', () => {
117-
beforeEach(() => {
118-
vi.mock('console', () => ({
119-
warn: vi.fn(),
120-
}));
121-
});
122-
123-
afterEach(() => {
124-
vi.restoreAllMocks();
125-
});
126-
127118
it('should not warn when all audits are included', () => {
128119
logSkippedAudits(AUDITS);
129120

@@ -133,18 +124,15 @@ describe('logSkippedAudits', () => {
133124
it('should warn about skipped audits', () => {
134125
logSkippedAudits(AUDITS.slice(0, -1));
135126

136-
expect(console.warn).toHaveBeenCalledTimes(1);
137-
expect(console.warn).toHaveBeenCalledWith(
127+
expect(ui()).toHaveLogged(
128+
'info',
138129
expect.stringContaining(`Skipped audits: [`),
139130
);
140131
});
141132

142133
it('should camel case the slugs in the audit message', () => {
143134
logSkippedAudits(AUDITS.slice(0, -1));
144135

145-
expect(console.warn).toHaveBeenCalledTimes(1);
146-
expect(console.warn).toHaveBeenCalledWith(
147-
expect.stringContaining(`unknownCodes`),
148-
);
136+
expect(ui()).toHaveLogged('info', expect.stringContaining(`unknownCodes`));
149137
});
150138
});

packages/plugin-typescript/vite.config.unit.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export default defineConfig({
2323
globalSetup: ['../../global-setup.ts'],
2424
setupFiles: [
2525
'../../testing/test-setup/src/lib/cliui.mock.ts',
26+
'../../testing/test-setup/src/lib/extend/ui-logger.matcher.ts',
2627
'../../testing/test-setup/src/lib/fs.mock.ts',
2728
'../../testing/test-setup/src/lib/console.mock.ts',
2829
'../../testing/test-setup/src/lib/reset.mocks.ts',

0 commit comments

Comments
 (0)