1- const { test , after } = require ( ' node:test' )
2- const assert = require ( 'node:assert/strict' )
1+ #!/usr/bin/env node
2+ // Custom test runner to avoid Node.js test runner serialization issues
33const { join } = require ( 'path' )
44const { mkdtempSync, mkdirSync, writeFileSync, rmSync } = require ( 'fs' )
55const { tmpdir } = require ( 'os' )
66const inventory = require ( '@architect/inventory' )
77const { updater } = require ( '@architect/utils' )
88const staticDeployMod = require ( join ( process . cwd ( ) , 'src' , 'static' , 'index.js' ) )
99
10+ let passed = 0
11+ let failed = 0
1012let tmpDirs = [ ]
1113
1214function createTmpDir ( structure ) {
@@ -33,7 +35,7 @@ function createTmpDir (structure) {
3335 return tmpDir
3436}
3537
36- after ( ( ) => {
38+ function cleanup ( ) {
3739 tmpDirs . forEach ( dir => {
3840 try {
3941 rmSync ( dir , { recursive : true , force : true } )
@@ -42,7 +44,7 @@ after(() => {
4244 // Ignore cleanup errors
4345 }
4446 } )
45- } )
47+ }
4648
4749function staticDeploy ( cwd , testParams , callback ) {
4850 inventory ( { cwd } , function ( err , result ) {
@@ -66,57 +68,85 @@ function staticDeploy (cwd, testParams, callback) {
6668 } )
6769}
6870
69- test ( 'Set up env' , ( ) => {
70- assert . ok ( staticDeployMod , 'Static asset deployment module is present' )
71- } )
72-
73- test ( 'Skip static deploy if @static is not defined' , async ( ) => {
74- let arc = '@app\n an-app'
75- let cwd = createTmpDir ( { 'app.arc' : arc } )
76- await new Promise ( ( resolve , reject ) => {
77- staticDeploy ( cwd , { } , err => {
78- if ( err ) reject ( err )
79- else resolve ( )
80- } )
71+ async function test ( name , fn ) {
72+ try {
73+ await fn ( )
74+ console . log ( `✔ ${ name } ` )
75+ passed ++
76+ }
77+ catch ( err ) {
78+ console . error ( `✖ ${ name } ` )
79+ console . error ( err )
80+ failed ++
81+ }
82+ }
83+
84+ async function main ( ) {
85+ await test ( 'Set up env' , async ( ) => {
86+ if ( ! staticDeployMod ) throw new Error ( 'Static asset deployment module is not present' )
8187 } )
82- } )
83-
84- test ( 'Static deploy exits gracefully if @http is defined but public folder is not present' , async ( ) => {
85- let arc = '@ app\n an-app\n @http'
86- let cwd = createTmpDir ( { 'app.arc' : arc } )
87- await new Promise ( ( resolve , reject ) => {
88- staticDeploy ( cwd , { } , err => {
89- if ( err ) reject ( err )
90- else resolve ( )
88+
89+ await test ( 'Skip static deploy if @static is not defined' , async ( ) => {
90+ let arc = '@app\n an-app'
91+ let cwd = createTmpDir ( { ' app.arc' : arc } )
92+ await new Promise ( ( resolve , reject ) => {
93+ staticDeploy ( cwd , { } , err => {
94+ if ( err ) reject ( err )
95+ else resolve ( )
96+ } )
9197 } )
9298 } )
93- } )
9499
95- test ( 'Static deploy skips when isDryRun is true' , async ( ) => {
96- let arc = '@app\n an-app\n @static'
97- let cwd = createTmpDir ( {
98- 'app.arc' : arc ,
99- 'public' : { } ,
100+ await test ( 'Static deploy exits gracefully if @http is defined but public folder is not present' , async ( ) => {
101+ let arc = '@app\n an-app\n @http'
102+ let cwd = createTmpDir ( { 'app.arc' : arc } )
103+ await new Promise ( ( resolve , reject ) => {
104+ staticDeploy ( cwd , { } , err => {
105+ if ( err ) reject ( err )
106+ else resolve ( )
107+ } )
108+ } )
100109 } )
101- await new Promise ( ( resolve , reject ) => {
102- staticDeploy ( cwd , { isDryRun : true , bucket : 'test-bucket' } , err => {
103- if ( err ) reject ( err )
104- else resolve ( )
110+
111+ await test ( 'Static deploy skips when isDryRun is true' , async ( ) => {
112+ let arc = '@app\n an-app\n @static'
113+ let cwd = createTmpDir ( {
114+ 'app.arc' : arc ,
115+ 'public' : { } ,
116+ } )
117+ await new Promise ( ( resolve , reject ) => {
118+ staticDeploy ( cwd , { isDryRun : true , bucket : 'test-bucket' } , err => {
119+ if ( err ) reject ( err )
120+ else resolve ( )
121+ } )
105122 } )
106123 } )
107- } )
108-
109- test ( 'Static deploy skips when @http is defined and public folder is not present' , async ( ) => {
110- let arc = '@ app\n an-app\n @http'
111- let cwd = createTmpDir ( { 'app.arc' : arc } )
112- await new Promise ( ( resolve , reject ) => {
113- staticDeploy ( cwd , { bucket : 'test-bucket' } , err => {
114- if ( err ) reject ( err )
115- else resolve ( )
124+
125+ await test ( 'Static deploy skips when @http is defined and public folder is not present' , async ( ) => {
126+ let arc = '@app\n an-app\n @http'
127+ let cwd = createTmpDir ( { ' app.arc' : arc } )
128+ await new Promise ( ( resolve , reject ) => {
129+ staticDeploy ( cwd , { bucket : 'test-bucket' } , err => {
130+ if ( err ) reject ( err )
131+ else resolve ( )
132+ } )
116133 } )
117134 } )
118- } )
119135
120- test ( 'Teardown' , ( ) => {
121- assert . ok ( true , 'Done' )
122- } )
136+ await test ( 'Teardown' , async ( ) => {
137+ // Cleanup complete
138+ } )
139+
140+ cleanup ( )
141+
142+ console . log ( `\nℹ tests ${ passed + failed } ` )
143+ console . log ( `ℹ pass ${ passed } ` )
144+ console . log ( `ℹ fail ${ failed } ` )
145+
146+ process . exit ( failed > 0 ? 1 : 0 )
147+ }
148+
149+ // Only run if executed directly
150+ if ( require . main === module ) {
151+ main ( )
152+ }
0 commit comments