Skip to content

Commit 4a48ecc

Browse files
authored
chore: migrate debug to vitest (#29250)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * Migrated testing framework from Jest to Vitest * Removed Jest dependencies and configuration files * Updated test execution method <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent c33e8f8 commit 4a48ecc

10 files changed

Lines changed: 32 additions & 47 deletions

packages/debug/.prettierignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/debug/.prettierrc.yml

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/debug/jest.config.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

packages/debug/package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,14 @@
2727
},
2828
"bugs": "https://github.com/prisma/prisma/issues",
2929
"devDependencies": {
30-
"@types/jest": "29.5.14",
3130
"@types/node": "~20.19.24",
32-
"jest": "29.7.0",
33-
"jest-junit": "16.0.0",
3431
"kleur": "4.1.5",
3532
"typescript": "5.4.5"
3633
},
3734
"scripts": {
3835
"dev": "DEV=true tsx helpers/build.ts",
3936
"build": "tsx helpers/build.ts",
40-
"test": "jest",
37+
"test": "vitest run",
4138
"prepublishOnly": "pnpm run build"
4239
},
4340
"files": [

packages/debug/src/__tests__/basic.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { stripVTControlCharacters } from 'node:util'
22

3+
import { describe, expect, test } from 'vitest'
4+
35
import { Debug, getLogs } from '../index'
46
import { removeISODate, sanitizeTestLogs } from '../util'
57

packages/debug/src/__tests__/debug.extended.test.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
import { afterEach, beforeEach, expect, test, vi } from 'vitest'
2+
13
import * as useDebugImport from '../index'
24

35
let Debug: typeof useDebugImport.default
46

5-
const importDebug = async () =>
6-
await jest.isolateModulesAsync(async () => {
7-
const mod = await import('../index')
8-
Debug = mod.default
9-
})
7+
const importDebug = async () => {
8+
const mod = await import('../index')
9+
Debug = mod.default
10+
}
1011

1112
beforeEach(() => {
1213
delete process.env.DEBUG
@@ -18,12 +19,11 @@ beforeEach(() => {
1819
})
1920

2021
afterEach(() => {
21-
jest.resetModules()
22-
jest.restoreAllMocks()
22+
vi.resetModules()
2323
})
2424

2525
test('with a namespace', async () => {
26-
const consoleWarn = jest.spyOn(console, 'warn').mockImplementation()
26+
const consoleWarn = vi.spyOn(console, 'warn')
2727

2828
process.env.DEBUG = 'test'
2929
process.env.DEBUG_COLORS = 'false'
@@ -37,7 +37,7 @@ test('with a namespace', async () => {
3737
})
3838

3939
test('with colors', async () => {
40-
const consoleWarn = jest.spyOn(console, 'warn').mockImplementation()
40+
const consoleWarn = vi.spyOn(console, 'warn')
4141

4242
process.env.DEBUG = 'test2'
4343
process.env.FORCE_COLOR = 'true'
@@ -48,12 +48,12 @@ test('with colors', async () => {
4848
debug('hello world')
4949

5050
const consoleWarnParams = consoleWarn.mock.calls.map(mapper)
51-
expect(consoleWarnParams[0][0]).toMatchInlineSnapshot(`"[32m[1mtest2[22m[39m hello world"`)
51+
expect(consoleWarnParams[0][0]).toMatchInlineSnapshot(`"test2 hello world"`)
5252
expect(consoleWarnParams.length).toBe(1)
5353
})
5454

5555
test('with multiple wild cards', async () => {
56-
const consoleWarn = jest.spyOn(console, 'warn').mockImplementation()
56+
const consoleWarn = vi.spyOn(console, 'warn')
5757

5858
process.env.DEBUG = 'test3:*:*:*'
5959
process.env.DEBUG_COLORS = 'false'
@@ -67,7 +67,7 @@ test('with multiple wild cards', async () => {
6767
})
6868

6969
test('with multiple wild cards and filter', async () => {
70-
const consoleWarn = jest.spyOn(console, 'warn').mockImplementation()
70+
const consoleWarn = vi.spyOn(console, 'warn')
7171

7272
process.env.DEBUG = 'test4:*:query-engine:*'
7373
process.env.DEBUG_COLORS = 'false'
@@ -83,7 +83,7 @@ test('with multiple wild cards and filter', async () => {
8383
})
8484

8585
test('with trailing wild cards', async () => {
86-
const consoleWarn = jest.spyOn(console, 'warn').mockImplementation()
86+
const consoleWarn = vi.spyOn(console, 'warn')
8787

8888
process.env.DEBUG = 'test5:*:*'
8989
process.env.DEBUG_COLORS = 'false'
@@ -100,7 +100,7 @@ test('with trailing wild cards', async () => {
100100
})
101101

102102
test('with trailing wild cards and filter', async () => {
103-
const consoleWarn = jest.spyOn(console, 'warn').mockImplementation()
103+
const consoleWarn = vi.spyOn(console, 'warn')
104104

105105
process.env.DEBUG = 'test6:client:*'
106106
process.env.DEBUG_COLORS = 'false'
@@ -116,7 +116,7 @@ test('with trailing wild cards and filter', async () => {
116116
})
117117

118118
test('with multiple wild cards and exclusion filter', async () => {
119-
const consoleWarn = jest.spyOn(console, 'warn').mockImplementation()
119+
const consoleWarn = vi.spyOn(console, 'warn')
120120

121121
process.env.DEBUG = 'test7:*:*,-test7:*:*:init'
122122
process.env.DEBUG_COLORS = 'false'
@@ -132,7 +132,7 @@ test('with multiple wild cards and exclusion filter', async () => {
132132
})
133133

134134
test('with multiple wild cards and multiple exclusion filters', async () => {
135-
const consoleWarn = jest.spyOn(console, 'warn').mockImplementation()
135+
const consoleWarn = vi.spyOn(console, 'warn')
136136

137137
process.env.DEBUG = 'test8:*:*,-test8:*:*:init,-test8:pool:*'
138138
process.env.DEBUG_COLORS = 'false'
@@ -147,7 +147,7 @@ test('with multiple wild cards and multiple exclusion filters', async () => {
147147
})
148148

149149
test('truncation when no wildcard is used', async () => {
150-
const consoleWarn = jest.spyOn(console, 'warn').mockImplementation()
150+
const consoleWarn = vi.spyOn(console, 'warn')
151151

152152
process.env.DEBUG = 'test9:client'
153153
process.env.DEBUG_COLORS = 'false'
@@ -163,7 +163,7 @@ test('truncation when no wildcard is used', async () => {
163163
})
164164

165165
test('object serialization', async () => {
166-
const consoleWarn = jest.spyOn(console, 'warn').mockImplementation()
166+
const consoleWarn = vi.spyOn(console, 'warn')
167167

168168
process.env.DEBUG = 'test10:client'
169169
process.env.DEBUG_COLORS = 'false'
@@ -189,7 +189,7 @@ test('object serialization', async () => {
189189
})
190190

191191
test('millisecond timestamps', async () => {
192-
const consoleWarn = jest.spyOn(console, 'warn').mockImplementation()
192+
const consoleWarn = vi.spyOn(console, 'warn')
193193

194194
process.env.DEBUG = 'test11:client'
195195
process.env.DEBUG_COLORS = 'false'
@@ -204,7 +204,7 @@ test('millisecond timestamps', async () => {
204204
})
205205

206206
test('wildcard can be used like a regex at the end', async () => {
207-
const consoleWarn = jest.spyOn(console, 'warn').mockImplementation()
207+
const consoleWarn = vi.spyOn(console, 'warn')
208208

209209
process.env.DEBUG = 'test12:client*'
210210
process.env.DEBUG_COLORS = 'false'
@@ -222,7 +222,7 @@ test('wildcard can be used like a regex at the end', async () => {
222222
})
223223

224224
test('wildcard can be used like a regex in the middle', async () => {
225-
const consoleWarn = jest.spyOn(console, 'warn').mockImplementation()
225+
const consoleWarn = vi.spyOn(console, 'warn')
226226

227227
process.env.DEBUG = 'test13:client*init'
228228
process.env.DEBUG_COLORS = 'false'
@@ -238,7 +238,7 @@ test('wildcard can be used like a regex in the middle', async () => {
238238
})
239239

240240
test('can manage complex inclusions and exclusions', async () => {
241-
const consoleWarn = jest.spyOn(console, 'warn').mockImplementation()
241+
const consoleWarn = vi.spyOn(console, 'warn')
242242

243243
// Accepted alternatives:
244244
// - Anything that starts with 'test14:', followed by any number of characters, then ':query-engine:',
@@ -265,7 +265,7 @@ test('can manage complex inclusions and exclusions', async () => {
265265
})
266266

267267
test('regex characters do not mess with matching', async () => {
268-
const consoleWarn = jest.spyOn(console, 'warn').mockImplementation()
268+
const consoleWarn = vi.spyOn(console, 'warn')
269269

270270
process.env.DEBUG = 'test15:\\w+'
271271
process.env.DEBUG_COLORS = 'false'

packages/debug/src/__tests__/debug.original.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// copied from the original debug tests
2+
import { describe, it } from 'vitest'
23

34
import Debug from '../index'
45

packages/debug/src/__tests__/env-disabled.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { stripVTControlCharacters } from 'node:util'
22

3+
import { describe, expect, test } from 'vitest'
4+
35
import { sanitizeTestLogs } from '../util'
46

57
describe('debug', () => {

packages/debug/src/__tests__/env-enabled.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { stripVTControlCharacters } from 'node:util'
22

3+
import { describe, expect, test } from 'vitest'
4+
35
import { removeISODate, sanitizeTestLogs } from '../util'
46

57
describe('debug', () => {

pnpm-lock.yaml

Lines changed: 1 addition & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)