1
- import { execa } from "execa" ;
2
- import { readFileSync } from "node:fs" ;
1
+ import { execa , execaNode } from "execa" ;
3
2
import { mkdir , rename , rm } from "node:fs/promises" ;
4
3
import { join , resolve } from "node:path" ;
5
4
@@ -12,14 +11,17 @@ import { compile } from "./compile";
12
11
import { handleDependencies } from "./handleDependencies" ;
13
12
import { createContainerFile } from "./createContainerFile" ;
14
13
import { createDeployHash } from "./createDeployHash" ;
14
+ import { readFileSync } from "node:fs" ;
15
15
16
16
type TestCase = {
17
17
name : string ;
18
18
skipTypecheck ?: boolean ;
19
19
wantConfigNotFoundError ?: boolean ;
20
20
wantBadConfigError ?: boolean ;
21
21
wantCompilationError ?: boolean ;
22
+ wantWorkerError ?: boolean ;
22
23
wantDependenciesError ?: boolean ;
24
+ wantInstallationError ?: boolean ;
23
25
} ;
24
26
25
27
const allTestCases : TestCase [ ] = [
@@ -71,7 +73,9 @@ if (testCases.length > 0) {
71
73
wantConfigNotFoundError,
72
74
wantBadConfigError,
73
75
wantCompilationError,
76
+ wantWorkerError,
74
77
wantDependenciesError,
78
+ wantInstallationError,
75
79
} : TestCase ) => {
76
80
const fixtureDir = resolve ( join ( process . cwd ( ) , "e2e/fixtures" , name ) ) ;
77
81
@@ -108,19 +112,25 @@ if (testCases.length > 0) {
108
112
console . log (
109
113
`Detected ${ packageManager } @${ version } from package.json 'engines' field`
110
114
) ;
111
- const { stdout } = await execa (
115
+ const { stdout, stderr } = await execa (
112
116
"corepack" ,
113
117
[ "use" , `${ packageManager } @${ version } ` ] ,
114
118
{
115
119
cwd : fixtureDir ,
116
120
}
117
121
) ;
118
122
console . log ( stdout ) ;
123
+ if ( stderr ) console . error ( stderr ) ;
119
124
} else {
120
- const { stdout } = await execa ( packageManager , installArgs ( packageManager ) , {
121
- cwd : fixtureDir ,
122
- } ) ;
125
+ const { stdout, stderr } = await execa (
126
+ packageManager ,
127
+ installArgs ( packageManager ) ,
128
+ {
129
+ cwd : fixtureDir ,
130
+ }
131
+ ) ;
123
132
console . log ( stdout ) ;
133
+ if ( stderr ) console . error ( stderr ) ;
124
134
}
125
135
} ) ( )
126
136
) . resolves . not . toThrowError ( ) ;
@@ -262,6 +272,56 @@ if (testCases.length > 0) {
262
272
} ) ( )
263
273
) . resolves . not . toThrowError ( ) ;
264
274
} ) ;
275
+
276
+ describe ( "with Containerfile ready" , ( ) => {
277
+ test (
278
+ "installs dependencies" ,
279
+ async ( ) => {
280
+ const expectation = expect (
281
+ ( async ( ) => {
282
+ const { stdout, stderr } = await execa (
283
+ "npm" ,
284
+ [ "ci" , "--no-audit" , "--no-fund" ] ,
285
+ {
286
+ cwd : resolve ( join ( fixtureDir , ".trigger" ) ) ,
287
+ }
288
+ ) ;
289
+ console . log ( stdout ) ;
290
+ if ( stderr ) console . error ( stderr ) ;
291
+ } ) ( )
292
+ ) ;
293
+
294
+ if ( wantInstallationError ) {
295
+ await expectation . rejects . toThrowError ( ) ;
296
+ } else {
297
+ await expectation . resolves . not . toThrowError ( ) ;
298
+ }
299
+ } ,
300
+ { timeout : 60_000 }
301
+ ) ;
302
+
303
+ test (
304
+ wantWorkerError ? "'node worker.js' fails" : "'node worker.js' succeeds" ,
305
+ async ( ) => {
306
+ const expectation = expect (
307
+ ( async ( ) => {
308
+ const { stdout, stderr } = await execaNode ( "worker.js" , {
309
+ cwd : resolve ( join ( fixtureDir , ".trigger" ) ) ,
310
+ } ) ;
311
+ console . log ( stdout ) ;
312
+ if ( stderr ) console . error ( stderr ) ;
313
+ } ) ( )
314
+ ) ;
315
+
316
+ if ( wantWorkerError ) {
317
+ await expectation . rejects . toThrowError ( ) ;
318
+ } else {
319
+ await expectation . resolves . not . toThrowError ( ) ;
320
+ }
321
+ } ,
322
+ { timeout : 60_000 }
323
+ ) ;
324
+ } ) ;
265
325
} ) ;
266
326
} ) ;
267
327
} ) ;
0 commit comments