Skip to content

Commit

Permalink
test(root): clear vitest mocks by default
Browse files Browse the repository at this point in the history
  • Loading branch information
diego-aquino committed Jan 12, 2025
1 parent a190408 commit facfe8e
Show file tree
Hide file tree
Showing 12 changed files with 10 additions and 24 deletions.
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
10 changes: 4 additions & 6 deletions packages/zimic/vitest.config.mts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
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,
testTimeout: 5000,
hookTimeout: 5000,
retry: process.env.CI === 'true' ? 1 : 0,
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 +54,4 @@ export const defaultConfig: ViteUserConfig = {
include: ['@vitest/coverage-istanbul'],
},
plugins: [],
};

export default defineConfig(defaultConfig);
});

0 comments on commit facfe8e

Please sign in to comment.