1+ import { afterEach , beforeEach , expect , test , vi } from 'vitest'
2+
13import * as useDebugImport from '../index'
24
35let 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
1112beforeEach ( ( ) => {
1213 delete process . env . DEBUG
@@ -18,12 +19,11 @@ beforeEach(() => {
1819} )
1920
2021afterEach ( ( ) => {
21- jest . resetModules ( )
22- jest . restoreAllMocks ( )
22+ vi . resetModules ( )
2323} )
2424
2525test ( '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
3939test ( '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
5555test ( '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
6969test ( '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
8585test ( '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
102102test ( '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
118118test ( '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
134134test ( '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
149149test ( '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
165165test ( '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
191191test ( '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
206206test ( '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
224224test ( '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
240240test ( '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
267267test ( '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'
0 commit comments