@@ -5,7 +5,7 @@ import { join, resolve } from "node:path";
5
5
import { rimraf } from "rimraf" ;
6
6
7
7
import { typecheckProject } from "../src/commands/deploy" ;
8
- import { readConfig , ReadConfigFileResult } from "../src/utilities/configFiles" ;
8
+ import { readConfig , ReadConfigFileResult , ReadConfigResult } from "../src/utilities/configFiles" ;
9
9
import {
10
10
detectPackageManagerFromArtifacts ,
11
11
LOCKFILES ,
@@ -18,14 +18,15 @@ import { createDeployHash } from "./createDeployHash";
18
18
import { handleDependencies } from "./handleDependencies" ;
19
19
import { E2EOptions , E2EOptionsSchema } from "./schemas" ;
20
20
import { fixturesConfig , TestCase } from "./fixtures.config" ;
21
+ import { Metafile , OutputFile } from "esbuild" ;
21
22
22
23
interface E2EFixtureTest extends TestCase {
23
24
dir : string ;
24
- tempDir : string ;
25
25
packageManager : PackageManager ;
26
+ tempDir : string ;
26
27
}
27
28
28
- const TIMEOUT = 180_000 ;
29
+ const TIMEOUT = 120_000 ;
29
30
30
31
const testCases : TestCase [ ] = process . env . MOD
31
32
? fixturesConfig . filter ( ( { id } ) => process . env . MOD === id )
@@ -65,18 +66,11 @@ if (testCases.length > 0) {
65
66
await rename ( resolve ( join ( dir , "yarn.lock.copy" ) ) , resolve ( join ( dir , "yarn.lock" ) ) ) ;
66
67
}
67
68
}
68
- } ) ;
69
-
70
- afterEach < E2EFixtureTest > ( async ( { dir, packageManager } ) => {
71
- delete global . resolvedConfig ;
72
-
73
- delete global . entryPointMetaOutput ;
74
- delete global . entryPointOutputFile ;
75
- delete global . workerMetaOutput ;
76
- delete global . workerOutputFile ;
77
69
78
- delete global . dependencies ;
70
+ await installFixtureDeps ( dir , packageManager ) ;
71
+ } , TIMEOUT ) ;
79
72
73
+ afterEach < E2EFixtureTest > ( async ( { dir, packageManager } ) => {
80
74
if ( packageManager === "npm" ) {
81
75
try {
82
76
await rename ( resolve ( join ( dir , "yarn.lock.copy" ) ) , resolve ( join ( dir , "yarn.lock" ) ) ) ;
@@ -123,86 +117,53 @@ if (testCases.length > 0) {
123
117
skip ( ) ;
124
118
}
125
119
126
- await expect (
127
- ( async ( ) => {
128
- if ( [ "pnpm" , "yarn" ] . includes ( packageManager ) ) {
129
- const buffer = readFileSync ( resolve ( join ( dir , "package.json" ) ) , "utf8" ) ;
130
- const pkgJSON = JSON . parse ( buffer . toString ( ) ) ;
131
- const version = pkgJSON . engines [ packageManager ] ;
132
- console . log (
133
- `Detected ${ packageManager } @${ version } from package.json 'engines' field`
134
- ) ;
135
- const { stdout, stderr } = await execa (
136
- "corepack" ,
137
- [ "use" , `${ packageManager } @${ version } ` ] ,
138
- {
139
- cwd : dir ,
140
- }
141
- ) ;
142
- console . log ( stdout ) ;
143
- if ( stderr ) console . error ( stderr ) ;
144
- } else {
145
- const { stdout, stderr } = await execa (
146
- packageManager ,
147
- installArgs ( packageManager ) ,
148
- {
149
- cwd : dir ,
150
- NODE_PATH : resolve ( join ( dir , "node_modules" ) ) ,
151
- }
152
- ) ;
153
- console . log ( stdout ) ;
154
- if ( stderr ) console . error ( stderr ) ;
155
- }
156
- } ) ( ) ,
157
- "installs fixture dependencies"
158
- ) . resolves . not . toThrowError ( ) ;
159
-
120
+ let resolvedConfig : ReadConfigResult ;
160
121
const configExpect = expect (
161
122
( async ( ) => {
162
- global . resolvedConfig = await readConfig ( dir , { cwd : dir } ) ;
123
+ resolvedConfig = await readConfig ( dir , { cwd : dir } ) ;
163
124
} ) ( ) ,
164
125
wantConfigNotFoundError || wantConfigInvalidError
165
126
? "does not resolve config"
166
127
: "resolves config"
167
128
) ;
129
+
168
130
if ( wantConfigNotFoundError ) {
169
131
await configExpect . rejects . toThrowError ( ) ;
170
- } else {
171
- await configExpect . resolves . not . toThrowError ( ) ;
132
+ return ;
172
133
}
173
134
174
- if ( wantConfigNotFoundError || wantConfigInvalidError ) {
175
- if ( wantConfigInvalidError ) {
176
- expect ( global . resolvedConfig ! . status ) . toBe ( "error" ) ;
177
- }
135
+ await configExpect . resolves . not . toThrowError ( ) ;
136
+
137
+ if ( wantConfigInvalidError ) {
138
+ expect ( resolvedConfig ! . status ) . toBe ( "error" ) ;
178
139
return ;
179
140
}
180
141
181
- expect ( global . resolvedConfig ) . not . toBe ( "error" ) ;
142
+ expect ( resolvedConfig ! ) . not . toBe ( "error" ) ;
182
143
183
144
if ( ! skipTypecheck ) {
184
145
await expect (
185
146
( async ( ) =>
186
- await typecheckProject ( ( global . resolvedConfig as ReadConfigFileResult ) . config ) ) ( ) ,
147
+ await typecheckProject ( ( resolvedConfig ! as ReadConfigFileResult ) . config ) ) ( ) ,
187
148
"typechecks"
188
149
) . resolves . not . toThrowError ( ) ;
189
150
}
190
151
152
+ let entryPointMetaOutput : Metafile [ "outputs" ] [ "out/stdin.js" ] ;
153
+ let entryPointOutputFile : OutputFile ;
154
+ let workerMetaOutput : Metafile [ "outputs" ] [ "out/stdin.js" ] ;
155
+ let workerOutputFile : OutputFile ;
156
+
191
157
const compileExpect = expect (
192
158
( async ( ) => {
193
- const {
194
- workerMetaOutput,
195
- workerOutputFile,
196
- entryPointMetaOutput,
197
- entryPointOutputFile,
198
- } = await compile ( {
199
- resolvedConfig : global . resolvedConfig ! ,
159
+ const compilationResult = await compile ( {
160
+ resolvedConfig : resolvedConfig ! ,
200
161
tempDir,
201
162
} ) ;
202
- global . entryPointMetaOutput = entryPointMetaOutput ;
203
- global . entryPointOutputFile = entryPointOutputFile ;
204
- global . workerMetaOutput = workerMetaOutput ;
205
- global . workerOutputFile = workerOutputFile ;
163
+ entryPointMetaOutput = compilationResult . entryPointMetaOutput ;
164
+ entryPointOutputFile = compilationResult . entryPointOutputFile ;
165
+ workerMetaOutput = compilationResult . workerMetaOutput ;
166
+ workerOutputFile = compilationResult . workerOutputFile ;
206
167
} ) ( ) ,
207
168
wantCompilationError ? "does not compile" : "compiles"
208
169
) ;
@@ -214,6 +175,8 @@ if (testCases.length > 0) {
214
175
215
176
await compileExpect . resolves . not . toThrowError ( ) ;
216
177
178
+ let dependencies : { [ k : string ] : string } ;
179
+
217
180
if ( resolveEnv ) {
218
181
for ( let envKey in resolveEnv ) {
219
182
vi . stubEnv ( envKey , resolveEnv [ envKey ] ! ) ;
@@ -222,14 +185,13 @@ if (testCases.length > 0) {
222
185
223
186
const depsExpectation = expect (
224
187
( async ( ) => {
225
- const { dependencies } = await handleDependencies ( {
226
- entryPointMetaOutput : global . entryPointMetaOutput ! ,
227
- metaOutput : global . workerMetaOutput ! ,
228
- resolvedConfig : global . resolvedConfig ! ,
188
+ dependencies = await handleDependencies ( {
189
+ entryPointMetaOutput : entryPointMetaOutput ! ,
190
+ metaOutput : workerMetaOutput ! ,
191
+ resolvedConfig : resolvedConfig ! ,
229
192
tempDir,
230
193
packageManager,
231
194
} ) ;
232
- global . dependencies = dependencies ;
233
195
} ) ( ) ,
234
196
wantDependenciesError ? "does not resolve dependencies" : "resolves dependencies"
235
197
) ;
@@ -248,7 +210,7 @@ if (testCases.length > 0) {
248
210
await expect (
249
211
( async ( ) => {
250
212
await createContainerFile ( {
251
- resolvedConfig : global . resolvedConfig ! ,
213
+ resolvedConfig : resolvedConfig ! ,
252
214
tempDir,
253
215
} ) ;
254
216
} ) ( ) ,
@@ -258,9 +220,9 @@ if (testCases.length > 0) {
258
220
await expect (
259
221
( async ( ) => {
260
222
await createDeployHash ( {
261
- dependencies : global . dependencies ! ,
262
- entryPointOutputFile : global . entryPointOutputFile ! ,
263
- workerOutputFile : global . workerOutputFile ! ,
223
+ dependencies : dependencies ! ,
224
+ entryPointOutputFile : entryPointOutputFile ! ,
225
+ workerOutputFile : workerOutputFile ! ,
264
226
} ) ;
265
227
} ) ( ) ,
266
228
"creates deploy hash"
@@ -278,13 +240,6 @@ if (testCases.length > 0) {
278
240
) ;
279
241
console . log ( installStdout ) ;
280
242
if ( installStderr ) console . error ( installStderr ) ;
281
-
282
- const { stdout, stderr } = await execa ( "npm" , [ "cache" , "clean" , "--force" ] , {
283
- cwd : tempDir ,
284
- NODE_PATH : resolve ( join ( tempDir , "node_modules" ) ) ,
285
- } ) ;
286
- console . log ( stdout ) ;
287
- if ( stderr ) console . error ( stderr ) ;
288
243
} ) ( ) ,
289
244
wantInstallationError ? "does not install dependencies" : "installs dependencies"
290
245
) ;
@@ -327,6 +282,27 @@ if (testCases.length > 0) {
327
282
throw new Error ( "Nothing to test" ) ;
328
283
}
329
284
285
+ async function installFixtureDeps ( dir : string , packageManager : PackageManager ) {
286
+ if ( [ "pnpm" , "yarn" ] . includes ( packageManager ) ) {
287
+ const buffer = readFileSync ( resolve ( join ( dir , "package.json" ) ) , "utf8" ) ;
288
+ const pkgJSON = JSON . parse ( buffer . toString ( ) ) ;
289
+ const version = pkgJSON . engines [ packageManager ] ;
290
+ console . log ( `Detected ${ packageManager } @${ version } from package.json 'engines' field` ) ;
291
+ const { stdout, stderr } = await execa ( "corepack" , [ "use" , `${ packageManager } @${ version } ` ] , {
292
+ cwd : dir ,
293
+ } ) ;
294
+ console . log ( stdout ) ;
295
+ if ( stderr ) console . error ( stderr ) ;
296
+ } else {
297
+ const { stdout, stderr } = await execa ( packageManager , installArgs ( packageManager ) , {
298
+ cwd : dir ,
299
+ NODE_PATH : resolve ( join ( dir , "node_modules" ) ) ,
300
+ } ) ;
301
+ console . log ( stdout ) ;
302
+ if ( stderr ) console . error ( stderr ) ;
303
+ }
304
+ }
305
+
330
306
function installArgs ( packageManager : string ) {
331
307
switch ( packageManager ) {
332
308
case "bun" :
0 commit comments