1
- import { strict as assert } from 'node:assert' ;
1
+ import assert from 'node:assert/strict' ;
2
+
2
3
import { mm } from 'mm' ;
3
4
import { request } from '@eggjs/supertest' ;
4
5
import coffee from 'coffee' ;
6
+
5
7
import { utils } from '../src/index.js' ;
6
- import { Application , createApp , getFilepath } from './helper.js' ;
8
+ import { createApp , getFilepath , type Application } from './helper.js' ;
7
9
8
10
describe ( 'test/egg-ts.test.ts' , ( ) => {
9
11
let app : Application | undefined ;
@@ -14,7 +16,9 @@ describe('test/egg-ts.test.ts', () => {
14
16
} ) ;
15
17
16
18
afterEach ( async ( ) => {
17
- app && await app . close ( ) ;
19
+ if ( app ) {
20
+ await app . close ( ) ;
21
+ }
18
22
app = undefined ;
19
23
return mm . restore ( ) ;
20
24
// delete require.extensions['.ts'];
@@ -143,7 +147,7 @@ describe('test/egg-ts.test.ts', () => {
143
147
144
148
it . skip ( 'should not load ts files while EGG_TYPESCRIPT was true but no extensions' , async ( ) => {
145
149
mm ( process . env , 'EGG_TYPESCRIPT' , 'true' ) ;
146
- mm ( utils , 'extensions' , [ '.js' , '.json' ] ) ;
150
+ mm ( utils , 'extensions' , [ '.js' , '.json' ] ) ;
147
151
app = createApp ( 'egg-ts-js' ) ;
148
152
await app . loader . loadService ( ) ;
149
153
assert ( app . serviceClasses . lord ) ;
@@ -152,26 +156,50 @@ describe('test/egg-ts.test.ts', () => {
152
156
153
157
it . skip ( 'should compile app-ts without error' , async ( ) => {
154
158
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
+ )
160
173
. debug ( )
161
174
. expect ( 'code' , 0 )
162
175
. end ( ) ;
163
176
} ) ;
164
177
165
178
it . skip ( 'should compile error with app-ts/error' , async ( ) => {
166
179
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
+ )
172
194
. 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
+ )
175
203
. expect ( 'stderr' , / ' l o a d P l u g i n ' i s p r o t e c t e d / )
176
204
. expect ( 'stderr' , / ' l o a d C o n f i g ' i s p r o t e c t e d / )
177
205
. 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', () => {
183
211
. 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 / )
184
212
. expect ( 'stderr' , / ' l o a d S e r v i c e ' i s p r o t e c t e d / )
185
213
. 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
+ )
187
218
. expect ( 'stderr' , / ' c t x ' i s p r o t e c t e d / )
188
219
. expect ( 'code' , 1 )
189
220
. end ( ) ;
0 commit comments