1- import { strict as assert } from 'node:assert' ;
1+ import assert from 'node:assert/strict' ;
2+
23import { mm } from 'mm' ;
34import { request } from '@eggjs/supertest' ;
45import coffee from 'coffee' ;
6+
57import { utils } from '../src/index.js' ;
6- import { Application , createApp , getFilepath } from './helper.js' ;
8+ import { createApp , getFilepath , type Application } from './helper.js' ;
79
810describe ( 'test/egg-ts.test.ts' , ( ) => {
911 let app : Application | undefined ;
@@ -14,7 +16,9 @@ describe('test/egg-ts.test.ts', () => {
1416 } ) ;
1517
1618 afterEach ( async ( ) => {
17- app && await app . close ( ) ;
19+ if ( app ) {
20+ await app . close ( ) ;
21+ }
1822 app = undefined ;
1923 return mm . restore ( ) ;
2024 // delete require.extensions['.ts'];
@@ -143,7 +147,7 @@ describe('test/egg-ts.test.ts', () => {
143147
144148 it . skip ( 'should not load ts files while EGG_TYPESCRIPT was true but no extensions' , async ( ) => {
145149 mm ( process . env , 'EGG_TYPESCRIPT' , 'true' ) ;
146- mm ( utils , 'extensions' , [ '.js' , '.json' ] ) ;
150+ mm ( utils , 'extensions' , [ '.js' , '.json' ] ) ;
147151 app = createApp ( 'egg-ts-js' ) ;
148152 await app . loader . loadService ( ) ;
149153 assert ( app . serviceClasses . lord ) ;
@@ -152,26 +156,50 @@ describe('test/egg-ts.test.ts', () => {
152156
153157 it . skip ( 'should compile app-ts without error' , async ( ) => {
154158 await coffee
155- . spawn ( 'node' , [ '--require' , 'ts-node/register/type-check' , getFilepath ( 'app-ts/app.ts' ) ] , {
156- env : Object . assign ( { } , process . env , {
157- TS_NODE_PROJECT : getFilepath ( 'app-ts/tsconfig.json' ) ,
158- } ) ,
159- } )
159+ . spawn (
160+ 'node' ,
161+ [
162+ '--require' ,
163+ 'ts-node/register/type-check' ,
164+ getFilepath ( 'app-ts/app.ts' ) ,
165+ ] ,
166+ {
167+ env : {
168+ ...process . env ,
169+ TS_NODE_PROJECT : getFilepath ( 'app-ts/tsconfig.json' ) ,
170+ } ,
171+ }
172+ )
160173 . debug ( )
161174 . expect ( 'code' , 0 )
162175 . end ( ) ;
163176 } ) ;
164177
165178 it . skip ( 'should compile error with app-ts/error' , async ( ) => {
166179 await coffee
167- . spawn ( 'node' , [ '--require' , 'ts-node/register/type-check' , getFilepath ( 'app-ts/app-error.ts' ) ] , {
168- env : Object . assign ( { } , process . env , {
169- TS_NODE_PROJECT : getFilepath ( 'app-ts/tsconfig.json' ) ,
170- } ) ,
171- } )
180+ . spawn (
181+ 'node' ,
182+ [
183+ '--require' ,
184+ 'ts-node/register/type-check' ,
185+ getFilepath ( 'app-ts/app-error.ts' ) ,
186+ ] ,
187+ {
188+ env : {
189+ ...process . env ,
190+ TS_NODE_PROJECT : getFilepath ( 'app-ts/tsconfig.json' ) ,
191+ } ,
192+ }
193+ )
172194 . debug ( )
173- . expect ( 'stderr' , / P r o p e r t y ' a b b ' d o e s n o t e x i s t o n t y p e ' E g g C o r e < { e n v : s t r i n g ; } > ' / )
174- . expect ( 'stderr' , / P r o p e r t y ' a b c ' d o e s n o t e x i s t o n t y p e ' t y p e o f B a s e C o n t e x t C l a s s ' / )
195+ . expect (
196+ 'stderr' ,
197+ / P r o p e r t y ' a b b ' d o e s n o t e x i s t o n t y p e ' E g g C o r e < { e n v : s t r i n g ; } > ' /
198+ )
199+ . expect (
200+ 'stderr' ,
201+ / P r o p e r t y ' a b c ' d o e s n o t e x i s t o n t y p e ' t y p e o f B a s e C o n t e x t C l a s s ' /
202+ )
175203 . expect ( 'stderr' , / ' l o a d P l u g i n ' i s p r o t e c t e d / )
176204 . expect ( 'stderr' , / ' l o a d C o n f i g ' i s p r o t e c t e d / )
177205 . expect ( 'stderr' , / ' l o a d A p p l i c a t i o n E x t e n d ' i s p r o t e c t e d / )
@@ -183,7 +211,10 @@ describe('test/egg-ts.test.ts', () => {
183211 . expect ( 'stderr' , / ' l o a d C u s t o m A g e n t ' i s p r o t e c t e d / )
184212 . expect ( 'stderr' , / ' l o a d S e r v i c e ' i s p r o t e c t e d / )
185213 . expect ( 'stderr' , / ' l o a d C o n t r o l l e r ' i s p r o t e c t e d / )
186- . expect ( 'stderr' , / P r o p e r t y ' c h e c k E n v T y p e ' d o e s n o t e x i s t o n t y p e ' s t r i n g ' / )
214+ . expect (
215+ 'stderr' ,
216+ / P r o p e r t y ' c h e c k E n v T y p e ' d o e s n o t e x i s t o n t y p e ' s t r i n g ' /
217+ )
187218 . expect ( 'stderr' , / ' c t x ' i s p r o t e c t e d / )
188219 . expect ( 'code' , 1 )
189220 . end ( ) ;
0 commit comments