1
- const assert = require ( ' assert') ;
2
- const mm = require ( 'egg-mock' ) ;
3
- const fs = require ( 'fs /promises') ;
4
- const utils = require ( '../../utils' ) ;
1
+ import { strict as assert } from 'node: assert';
2
+ import fs from 'node:fs/promises' ;
3
+ import { scheduler } from 'node:timers /promises';
4
+ import { createApp , MockApplication , restore , cluster } from '../../utils.js' ;
5
5
6
- describe ( 'test/app/middleware/meta.test.js' , ( ) => {
7
- afterEach ( mm . restore ) ;
6
+ describe ( 'test/app/middleware/meta.test.ts' , ( ) => {
7
+ afterEach ( restore ) ;
8
+
9
+ let app : MockApplication ;
8
10
9
11
describe ( 'default config' , ( ) => {
10
- let app ;
11
12
before ( ( ) => {
12
- app = utils . app ( 'apps/middlewares' ) ;
13
+ app = createApp ( 'apps/middlewares' ) ;
13
14
return app . ready ( ) ;
14
15
} ) ;
15
16
after ( ( ) => app . close ( ) ) ;
@@ -23,9 +24,8 @@ describe('test/app/middleware/meta.test.js', () => {
23
24
} ) ;
24
25
25
26
describe ( 'config.logger.enablePerformanceTimer = true' , ( ) => {
26
- let app ;
27
27
before ( ( ) => {
28
- app = utils . app ( 'apps/middlewares-meta-enablePerformanceTimer' ) ;
28
+ app = createApp ( 'apps/middlewares-meta-enablePerformanceTimer' ) ;
29
29
return app . ready ( ) ;
30
30
} ) ;
31
31
after ( ( ) => app . close ( ) ) ;
@@ -41,9 +41,8 @@ describe('test/app/middleware/meta.test.js', () => {
41
41
} ) ;
42
42
43
43
describe ( 'meta.logging = true' , ( ) => {
44
- let app ;
45
44
before ( ( ) => {
46
- app = utils . app ( 'apps/meta-logging-app' ) ;
45
+ app = createApp ( 'apps/meta-logging-app' ) ;
47
46
return app . ready ( ) ;
48
47
} ) ;
49
48
after ( ( ) => app . close ( ) ) ;
@@ -54,16 +53,18 @@ describe('test/app/middleware/meta.test.js', () => {
54
53
. expect ( 'X-Readtime' , / \d + / )
55
54
. expect ( 'hello world' )
56
55
. expect ( 200 ) ;
57
- if ( process . platform === 'win32' ) await utils . sleep ( 2000 ) ;
56
+ if ( process . platform === 'win32' ) {
57
+ await scheduler . wait ( 2000 ) ;
58
+ }
58
59
const content = ( await fs . readFile ( app . coreLogger . options . file , 'utf8' ) ) . split ( '\n' ) . slice ( - 2 , - 1 ) [ 0 ] ;
59
- assert ( content . includes ( ' [meta] request started, host: ' ) ) ;
60
+ assert . match ( content , / \ [m e t a ] r e q u e s t s t a r t e d , h o s t : / ) ;
60
61
} ) ;
61
62
} ) ;
62
63
63
64
describe ( 'cluster start' , ( ) => {
64
- let app ;
65
+ let app : MockApplication ;
65
66
before ( ( ) => {
66
- app = utils . cluster ( 'apps/middlewares' ) ;
67
+ app = cluster ( 'apps/middlewares' ) ;
67
68
return app . ready ( ) ;
68
69
} ) ;
69
70
after ( ( ) => app . close ( ) ) ;
0 commit comments