Skip to content
Open
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
3 changes: 0 additions & 3 deletions packages/bench/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ export default defineConfig({
testTimeout: 300_000,
hookTimeout: 300_000,
pool: 'forks',
poolOptions: {
forks: { singleFork: true },
},
fileParallelism: false,
},
benchmark: {
Expand Down
5 changes: 4 additions & 1 deletion packages/cli/src/__tests__/database-url.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ afterEach(() => {
})
// restoreAllMocks (not clearAllMocks) is what fully reverts spies on
// global objects like `process.exit`. Without restoration the spy stays
// attached and bleeds into later tests.
// attached and bleeds into later tests. Since Vitest 4, restoreAllMocks only
// reverts vi.spyOn spies; resetAllMocks is what clears the module-mock
// vi.fn()s' calls and per-test implementations.
vi.resetAllMocks()
vi.restoreAllMocks()
if (tmpDir && fs.existsSync(tmpDir)) {
fs.rmSync(tmpDir, { recursive: true, force: true })
Expand Down
33 changes: 18 additions & 15 deletions packages/cli/src/__tests__/installer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,24 @@ const mockEnd = vi.fn()

vi.mock('pg', () => ({
default: {
Client: vi.fn(() => ({
connect: mockConnect,
query: async (...args: unknown[]) => {
const result = await mockQuery(...args)
if (
typeof args[0] === 'string' &&
args[0].includes('pg_try_advisory') &&
result?.rows?.[0]?.acquired === undefined
) {
return { ...result, rows: [{ acquired: true }] }
}
return result
},
end: mockEnd,
})),
// biome-ignore lint/complexity/useArrowFunction: Vitest 4 mocks called with `new` need a constructible (non-arrow) implementation.
Client: vi.fn(function () {
return {
connect: mockConnect,
query: async (...args: unknown[]) => {
const result = await mockQuery(...args)
if (
typeof args[0] === 'string' &&
args[0].includes('pg_try_advisory') &&
result?.rows?.[0]?.acquired === undefined
) {
return { ...result, rows: [{ acquired: true }] }
}
return result
},
end: mockEnd,
}
}),
},
}))

Expand Down
3 changes: 3 additions & 0 deletions packages/cli/src/commands/auth/__tests__/region.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ afterEach(() => {
process.env.CI = originalCi
}
setTty(originalIsTty)
// Vitest 4: restoreAllMocks only reverts vi.spyOn spies; resetAllMocks
// clears the module-mock vi.fn()s' calls and per-test implementations.
vi.resetAllMocks()
vi.restoreAllMocks()
})

Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/commands/eql/__tests__/repair.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ const pgMock = vi.hoisted(() => ({
}))
vi.mock('pg', () => ({
default: {
Client: vi.fn((config: { connectionString?: string }) => {
// biome-ignore lint/complexity/useArrowFunction: Vitest 4 mocks called with `new` need a constructible (non-arrow) implementation.
Client: vi.fn(function (config: { connectionString?: string }) {
pgMock.connectionStrings.push(config?.connectionString)
return {
connect: pgMock.connect,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ const pgMock = vi.hoisted(() => ({
}))
vi.mock('pg', () => ({
default: {
Client: vi.fn((config: { connectionString?: string }) => {
// biome-ignore lint/complexity/useArrowFunction: Vitest 4 mocks called with `new` need a constructible (non-arrow) implementation.
Client: vi.fn(function (config: { connectionString?: string }) {
pgMock.connectionStrings.push(config?.connectionString)
return { connect: pgMock.connect, query: pgMock.query, end: pgMock.end }
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ vi.mock('@clack/prompts', () => ({
const queryMock = vi.fn()
vi.mock('pg', () => ({
default: {
Client: vi.fn(() => ({
connect: vi.fn(async () => {}),
query: queryMock,
end: vi.fn(async () => {}),
})),
// biome-ignore lint/complexity/useArrowFunction: Vitest 4 mocks called with `new` need a constructible (non-arrow) implementation.
Client: vi.fn(function () {
return {
connect: vi.fn(async () => {}),
query: queryMock,
end: vi.fn(async () => {}),
}
}),
},
}))

Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/db/__tests__/client-wrap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const mockEnd = vi.fn()

vi.mock('pg', () => ({
default: {
Client: vi.fn(() => {
// biome-ignore lint/complexity/useArrowFunction: Vitest 4 mocks called with `new` need a constructible (non-arrow) implementation.
Client: vi.fn(function () {
const client: Record<string, unknown> = {
connect: (...args: unknown[]) => mockConnect(...args),
end: mockEnd,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ describe('telemetry lifecycle (emitter + flush)', () => {
beforeEach(() => {
h.capture.mockReset()
h.shutdown.mockReset().mockResolvedValue(undefined)
h.PostHog.mockReset().mockImplementation(() => ({
capture: h.capture,
shutdown: h.shutdown,
}))
// biome-ignore lint/complexity/useArrowFunction: Vitest 4 mocks called with `new` need a constructible (non-arrow) implementation.
h.PostHog.mockReset().mockImplementation(function () {
return { capture: h.capture, shutdown: h.shutdown }
})
h.writeState.mockReset()
h.state.value = { ...ENABLED }
// Enabled by default; neutralize every gate so status is { enabled: true }.
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export default defineConfig({
test: {
name: 'live',
include: ['src/**/*.live.test.ts'],
poolOptions: { forks: { singleFork: true } },
// Vitest 4 removed `poolOptions.forks.singleFork`; running one file
// at a time is what serialises the live suites.
fileParallelism: false,
},
},
],
Expand Down
Loading
Loading