@@ -2,11 +2,11 @@ import * as assert from 'node:assert/strict'
22import { readFileSync } from 'node:fs'
33import { access , rm } from 'node:fs/promises'
44import type { AddressInfo } from 'node:net'
5- import { describe , it , mock } from 'node:test'
65import { App } from '@tinyhttp/app'
6+ import * as mock from '@vitest/spy'
77import { bold , cyan , magenta , red } from 'colorette'
8- import { expect } from 'expect'
98import { makeFetch } from 'supertest-fetch'
9+ import { describe , expect , it , vi } from 'vitest'
1010import { LogLevel , logger } from '../src/index.ts'
1111
1212async function checkFileExists ( file : string ) {
@@ -99,35 +99,37 @@ it('should ignore route paths listed in the "ignore" option', async () => {
9999
100100 const logs : string [ ] = [ ]
101101
102- const callback = mock . fn ( ( path : string ) => {
102+ const callback = vi . fn ( ( path : string ) => {
103103 logs . push ( path )
104104 } )
105105
106- app . use (
107- logger ( {
108- output : {
109- color : false ,
110- level : undefined ,
111- callback
112- } ,
113- ignore : [ '/ignore' ]
114- } )
115- )
106+ app . use ( logger ( { output : { color : false , level : undefined , callback } , ignore : [ '/ignore' ] } ) )
116107
117108 const server = app . listen ( )
118109
119- const address = ( server . address ( ) as AddressInfo ) . port
120-
121- const baseUrl = `http://localhost:${ address } `
122-
123- await fetch ( new URL ( '/ignor' , baseUrl ) )
124- await fetch ( new URL ( '/ignore' , baseUrl ) )
125- await fetch ( new URL ( '/ignore/path' , baseUrl ) )
126- await fetch ( new URL ( '/ignore?query=string' , baseUrl ) )
127- await fetch ( new URL ( '/path/ignore' , baseUrl ) )
110+ const fetch = makeFetch ( server )
128111
129- expect ( callback . mock . callCount ( ) ) . toEqual ( 2 )
130- expect ( logs ) . toEqual ( [ 'GET 404 Not Found /ignor' , 'GET 404 Not Found /path/ignore' ] )
112+ fetch ( '/ignor' )
113+ . expect ( 404 )
114+ . then ( ( ) => {
115+ fetch ( '/ignore' )
116+ . expect ( 404 )
117+ . then ( ( ) => {
118+ fetch ( '/path/ignore' )
119+ . expect ( 404 )
120+ . then ( ( ) => {
121+ fetch ( '/ignore?query=string' )
122+ . expect ( 404 )
123+ . then ( ( ) => {
124+ expect ( callback ) . toHaveBeenCalledTimes ( 2 )
125+ expect ( logs ) . toEqual ( [ 'GET 404 Not Found /ignor' , 'GET 404 Not Found /path/ignore' ] )
126+
127+ vi . clearAllMocks ( )
128+ server . close ( )
129+ } )
130+ } )
131+ } )
132+ } )
131133} )
132134
133135describe ( 'Log file tests' , ( ) => {
0 commit comments