Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(root): clear vitest mocks by default #532

Merged
merged 2 commits into from
Jan 12, 2025
Merged
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
1 change: 1 addition & 0 deletions apps/zimic-test-client/vitest.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default defineConfig({
minWorkers: 1,
maxWorkers,
maxConcurrency: maxWorkers,
clearMocks: true,
coverage: {
provider: 'istanbul',
reporter: ['text', 'html'],
Expand Down
1 change: 1 addition & 0 deletions examples/with-openapi-typegen/vitest.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ export default defineConfig({
environment: 'node',
include: ['./tests/**/*.test.ts'],
setupFiles: ['./tests/setup.ts'],
clearMocks: true,
},
});
1 change: 1 addition & 0 deletions examples/with-vitest-browser/vitest.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default defineConfig({
globals: true,
include: ['./tests/**/*.test.ts'],
setupFiles: ['./tests/setup.ts'],
clearMocks: true,
browser: {
name: 'chromium',
provider: 'playwright',
Expand Down
1 change: 1 addition & 0 deletions examples/with-vitest-jsdom/vitest.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export default defineConfig({
environment: 'jsdom',
include: ['./tests/**/*.test.ts'],
setupFiles: ['./tests/setup.ts'],
clearMocks: true,
},
});
1 change: 1 addition & 0 deletions examples/with-vitest-node/vitest.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ export default defineConfig({
environment: 'node',
include: ['./tests/**/*.test.ts'],
setupFiles: ['./tests/setup.ts'],
clearMocks: true,
},
});
4 changes: 0 additions & 4 deletions packages/zimic/src/cli/__tests__/cli.node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import runCLI from '../cli';

describe('CLI', () => {
const processArgvSpy = vi.spyOn(process, 'argv', 'get');
const processOnSpy = vi.spyOn(process, 'on');

const rootHelpOutput = [
'zimic [command]',
Expand All @@ -24,10 +23,7 @@ describe('CLI', () => {
].join('\n');

beforeEach(() => {
processArgvSpy.mockClear();
processArgvSpy.mockReturnValue([]);

processOnSpy.mockClear();
});

it('should not throw an error if no command is provided', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ describe('CLI (browser)', () => {
const processArgvSpy = vi.spyOn(process, 'argv', 'get');

beforeEach(() => {
processArgvSpy.mockClear();
processArgvSpy.mockReturnValue([]);
});

Expand Down
6 changes: 0 additions & 6 deletions packages/zimic/src/cli/server/__tests__/server.node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,11 @@ describe('CLI (server)', async () => {
const crypto = await importCrypto();

const processArgvSpy = vi.spyOn(process, 'argv', 'get');
const processOnSpy = vi.spyOn(process, 'on');
const processOffSpy = vi.spyOn(process, 'off');
const processExitSpy = vi.spyOn(process, 'exit').mockReturnValue(undefined as never);

beforeEach(() => {
processArgvSpy.mockClear();
processArgvSpy.mockReturnValue([]);

processOnSpy.mockClear();
processOffSpy.mockClear();
processExitSpy.mockClear();
});

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ describe('Type generation (OpenAPI)', () => {
});

beforeEach(() => {
processArgvSpy.mockClear();
processArgvSpy.mockReturnValue([]);

schemaInterceptor.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ describe('Type generation', () => {
const processArgvSpy = vi.spyOn(process, 'argv', 'get');

beforeEach(() => {
processArgvSpy.mockClear();
processArgvSpy.mockReturnValue([]);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest';

import { HttpResponse } from '@/http';
import HttpHeaders from '@/http/headers/HttpHeaders';
Expand Down Expand Up @@ -92,10 +92,6 @@ export function declareMethodHttpInterceptorWorkerTests(options: SharedHttpInter
}
}

beforeEach(() => {
spiedRequestHandler.mockClear();
});

it(`should intercept ${method} requests after started`, async () => {
await usingHttpInterceptorWorker(workerOptions, async (worker) => {
const interceptor = createDefaultHttpInterceptor();
Expand Down
9 changes: 4 additions & 5 deletions packages/zimic/vitest.config.mts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path';
import { ViteUserConfig, defineConfig } from 'vitest/config';
import { defineConfig } from 'vitest/config';

export const defaultConfig: ViteUserConfig = {
export default defineConfig({
publicDir: './public',
test: {
globals: false,
Expand All @@ -11,6 +11,7 @@ export const defaultConfig: ViteUserConfig = {
setupFiles: ['./tests/setup/shared.ts'],
maxWorkers: process.env.CI === 'true' ? '100%' : '50%',
minWorkers: 1,
clearMocks: true,
coverage: {
provider: 'istanbul',
reporter: ['text', 'html'],
Expand Down Expand Up @@ -54,6 +55,4 @@ export const defaultConfig: ViteUserConfig = {
include: ['@vitest/coverage-istanbul'],
},
plugins: [],
};

export default defineConfig(defaultConfig);
});
Loading