1
- 'use strict' ;
2
-
3
- const path = require ( 'path' ) ;
4
- const assert = require ( 'assert' ) ;
5
- const request = require ( 'supertest' ) ;
6
- const mm = require ( '..' ) ;
7
-
8
- const fixtures = path . join ( __dirname , 'fixtures' ) ;
9
-
10
- describe ( 'test/cluster.test.js' , ( ) => {
1
+ import { strict as assert } from 'node:assert' ;
2
+ import { getFixtures } from './helper.js' ;
3
+ import mm , { MockApplication } from '../src/index.js' ;
11
4
5
+ describe ( 'test/cluster.test.ts' , ( ) => {
12
6
afterEach ( mm . restore ) ;
13
7
14
8
describe ( 'normal' , ( ) => {
15
- let app ;
9
+ let app : MockApplication ;
16
10
before ( ( ) => {
17
11
app = mm . cluster ( {
18
- baseDir : path . join ( fixtures , 'demo' ) ,
12
+ baseDir : getFixtures ( 'demo' ) ,
19
13
cache : false ,
20
14
coverage : false ,
21
15
} ) ;
@@ -25,8 +19,8 @@ describe('test/cluster.test.js', () => {
25
19
after ( ( ) => app . close ( ) ) ;
26
20
27
21
it ( 'should have members' , async ( ) => {
28
- assert ( app . callback ( ) === app ) ;
29
- assert ( app . listen ( ) === app ) ;
22
+ assert . equal ( app . callback ( ) , app ) ;
23
+ assert . equal ( app . listen ( ) , app ) ;
30
24
await app . ready ( ) ;
31
25
assert ( app . process ) ;
32
26
} ) ;
@@ -43,10 +37,10 @@ describe('test/cluster.test.js', () => {
43
37
} ) ;
44
38
45
39
describe ( 'cluster with fullpath baseDir' , ( ) => {
46
- let app ;
40
+ let app : MockApplication ;
47
41
before ( done => {
48
42
app = mm . cluster ( {
49
- baseDir : path . join ( fixtures , 'demo' ) ,
43
+ baseDir : getFixtures ( 'demo' ) ,
50
44
cache : false ,
51
45
coverage : false ,
52
46
} ) ;
@@ -55,15 +49,15 @@ describe('test/cluster.test.js', () => {
55
49
after ( ( ) => app . close ( ) ) ;
56
50
57
51
it ( 'should work' , done => {
58
- request ( app . callback ( ) )
52
+ app . httpRequest ( )
59
53
. get ( '/hello' )
60
54
. expect ( 'hi' )
61
55
. expect ( 200 , done ) ;
62
56
} ) ;
63
57
} ) ;
64
58
65
59
describe ( 'cluster with shortpath baseDir' , ( ) => {
66
- let app ;
60
+ let app : MockApplication ;
67
61
before ( done => {
68
62
app = mm . cluster ( {
69
63
baseDir : 'demo' ,
@@ -75,19 +69,43 @@ describe('test/cluster.test.js', () => {
75
69
after ( ( ) => app . close ( ) ) ;
76
70
77
71
it ( 'should work' , done => {
78
- request ( app . callback ( ) )
72
+ app . httpRequest ( )
79
73
. get ( '/hello' )
80
74
. expect ( 'hi' )
81
75
. expect ( 200 , done ) ;
82
76
} ) ;
83
77
} ) ;
84
78
85
79
describe ( 'cluster with customEgg=string' , ( ) => {
86
- let app ;
80
+ let app : MockApplication ;
81
+ before ( done => {
82
+ app = mm . cluster ( {
83
+ baseDir : 'apps/barapp' ,
84
+ customEgg : getFixtures ( 'bar' ) ,
85
+ cache : false ,
86
+ coverage : false ,
87
+ } ) ;
88
+ app . ready ( done ) ;
89
+ } ) ;
90
+ after ( ( ) => app . close ( ) ) ;
91
+
92
+ it ( 'should work' , done => {
93
+ app . httpRequest ( )
94
+ . get ( '/' )
95
+ . expect ( {
96
+ foo : 'bar' ,
97
+ foobar : 'bar' ,
98
+ } )
99
+ . expect ( 200 , done ) ;
100
+ } ) ;
101
+ } ) ;
102
+
103
+ describe ( 'cluster with framework=string' , ( ) => {
104
+ let app : MockApplication ;
87
105
before ( done => {
88
106
app = mm . cluster ( {
89
107
baseDir : 'apps/barapp' ,
90
- customEgg : path . join ( fixtures , 'bar' ) ,
108
+ framework : getFixtures ( 'bar' ) ,
91
109
cache : false ,
92
110
coverage : false ,
93
111
} ) ;
@@ -96,7 +114,7 @@ describe('test/cluster.test.js', () => {
96
114
after ( ( ) => app . close ( ) ) ;
97
115
98
116
it ( 'should work' , done => {
99
- request ( app . callback ( ) )
117
+ app . httpRequest ( )
100
118
. get ( '/' )
101
119
. expect ( {
102
120
foo : 'bar' ,
@@ -107,13 +125,13 @@ describe('test/cluster.test.js', () => {
107
125
} ) ;
108
126
109
127
describe ( 'cluster with customEgg=true' , ( ) => {
110
- let app ;
128
+ let app : MockApplication ;
111
129
before ( done => {
112
130
mm ( process , 'cwd' , ( ) => {
113
- return path . join ( fixtures , 'bar' ) ;
131
+ return getFixtures ( 'bar' ) ;
114
132
} ) ;
115
133
app = mm . cluster ( {
116
- baseDir : path . join ( fixtures , 'apps/barapp' ) ,
134
+ baseDir : getFixtures ( 'apps/barapp' ) ,
117
135
customEgg : true ,
118
136
cache : false ,
119
137
coverage : false ,
@@ -123,7 +141,34 @@ describe('test/cluster.test.js', () => {
123
141
after ( ( ) => app . close ( ) ) ;
124
142
125
143
it ( 'should work' , done => {
126
- request ( app . callback ( ) )
144
+ app . httpRequest ( )
145
+ . get ( '/' )
146
+ . expect ( {
147
+ foo : 'bar' ,
148
+ foobar : 'bar' ,
149
+ } )
150
+ . expect ( 200 , done ) ;
151
+ } ) ;
152
+ } ) ;
153
+
154
+ describe ( 'cluster with framework=true' , ( ) => {
155
+ let app : MockApplication ;
156
+ before ( done => {
157
+ mm ( process , 'cwd' , ( ) => {
158
+ return getFixtures ( 'bar' ) ;
159
+ } ) ;
160
+ app = mm . cluster ( {
161
+ baseDir : getFixtures ( 'apps/barapp' ) ,
162
+ framework : true ,
163
+ cache : false ,
164
+ coverage : false ,
165
+ } ) ;
166
+ app . ready ( done ) ;
167
+ } ) ;
168
+ after ( ( ) => app . close ( ) ) ;
169
+
170
+ it ( 'should work' , done => {
171
+ app . httpRequest ( )
127
172
. get ( '/' )
128
173
. expect ( {
129
174
foo : 'bar' ,
@@ -134,8 +179,8 @@ describe('test/cluster.test.js', () => {
134
179
} ) ;
135
180
136
181
describe ( 'cluster with cache' , ( ) => {
137
- let app1 ;
138
- let app2 ;
182
+ let app1 : MockApplication ;
183
+ let app2 : MockApplication ;
139
184
afterEach ( ( ) => {
140
185
const promises = [ ] ;
141
186
app1 && promises . push ( app1 . close ( ) ) ;
@@ -179,17 +224,17 @@ describe('test/cluster.test.js', () => {
179
224
} ) ;
180
225
181
226
describe ( 'cluster with eggPath' , ( ) => {
182
- let app ;
227
+ let app : MockApplication ;
183
228
after ( ( ) => app . close ( ) ) ;
184
229
185
230
it ( 'should get eggPath' , async ( ) => {
186
231
app = mm . cluster ( {
187
232
baseDir : 'demo' ,
188
- customEgg : path . join ( __dirname , 'fixtures/ chair') ,
233
+ customEgg : getFixtures ( ' chair') ,
189
234
eggPath : '/path/to/eggPath' ,
190
235
cache : false ,
191
236
coverage : false ,
192
- } ) ;
237
+ } as any ) ;
193
238
await app
194
239
. debug ( )
195
240
. expect ( 'stdout' , / \/ p a t h \/ t o \/ e g g P a t h / )
@@ -198,13 +243,13 @@ describe('test/cluster.test.js', () => {
198
243
} ) ;
199
244
200
245
describe ( 'cluster with workers' , ( ) => {
201
- let app ;
246
+ let app : MockApplication ;
202
247
after ( ( ) => app . close ( ) ) ;
203
248
204
249
it ( 'should get 2 workers' , async ( ) => {
205
250
app = mm . cluster ( {
206
251
baseDir : 'demo' ,
207
- customEgg : path . join ( __dirname , 'fixtures/ chair') ,
252
+ customEgg : getFixtures ( ' chair') ,
208
253
workers : 2 ,
209
254
cache : false ,
210
255
coverage : false ,
@@ -217,13 +262,13 @@ describe('test/cluster.test.js', () => {
217
262
} ) ;
218
263
219
264
describe ( 'cluster with opts.customEgg' , ( ) => {
220
- let app ;
265
+ let app : MockApplication ;
221
266
after ( ( ) => app . close ( ) ) ;
222
267
223
268
it ( 'should pass execArgv' , async ( ) => {
224
269
app = mm . cluster ( {
225
270
baseDir : 'custom_egg' ,
226
- customEgg : path . join ( __dirname , 'fixtures/ bar') ,
271
+ customEgg : getFixtures ( ' bar') ,
227
272
workers : 1 ,
228
273
cache : false ,
229
274
coverage : false ,
@@ -239,7 +284,7 @@ describe('test/cluster.test.js', () => {
239
284
} ) ;
240
285
241
286
describe ( 'cluster with egg.framework=yadan' , ( ) => {
242
- let app ;
287
+ let app : MockApplication ;
243
288
after ( ( ) => app . close ( ) ) ;
244
289
245
290
it ( 'should pass execArgv' , async ( ) => {
@@ -254,8 +299,8 @@ describe('test/cluster.test.js', () => {
254
299
} ) ;
255
300
} ) ;
256
301
257
- describe ( 'prerequire' , ( ) => {
258
- let app ;
302
+ describe . skip ( 'prerequire' , ( ) => {
303
+ let app : MockApplication ;
259
304
after ( ( ) => app . close ( ) ) ;
260
305
261
306
it ( 'should load files' , async ( ) => {
@@ -275,12 +320,12 @@ describe('test/cluster.test.js', () => {
275
320
} ) ;
276
321
277
322
describe ( 'custom port' , ( ) => {
278
- let app ;
323
+ let app : MockApplication ;
279
324
after ( ( ) => app . close ( ) ) ;
280
325
281
326
it ( 'should use it' , async ( ) => {
282
327
app = mm . cluster ( {
283
- baseDir : path . join ( fixtures , 'demo' ) ,
328
+ baseDir : getFixtures ( 'demo' ) ,
284
329
cache : false ,
285
330
coverage : false ,
286
331
port : 5566 ,
0 commit comments