Skip to content

Commit eaaa08b

Browse files
committed
fix: idk
1 parent 1eb35a8 commit eaaa08b

File tree

2 files changed

+79
-49
lines changed

2 files changed

+79
-49
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"test:nolint": "npm run test:integration && npm run coverage",
1212
"test:unit": "AWS_ACCESS_KEY_ID=\"blah\" AWS_SECRET_ACCESS_KEY=\"blah\" node --test --test-reporter=spec 'test/unit/**/*-test.js'",
1313
"test:slow": "node --test --test-reporter=spec 'test/slow/**/*-test.js'",
14-
"test:integration": "AWS_ACCESS_KEY_ID=\"blah\" AWS_SECRET_ACCESS_KEY=\"blah\" node --test --test-reporter=spec 'test/integration/**/*-test.js'",
14+
"test:integration": "AWS_ACCESS_KEY_ID=\"blah\" AWS_SECRET_ACCESS_KEY=\"blah\" node test/integration/static/index-test.js && AWS_ACCESS_KEY_ID=\"blah\" AWS_SECRET_ACCESS_KEY=\"blah\" node --test --test-reporter=spec 'test/integration/static/publish/*-test.js' 'test/integration/macros-n-plugins-test.js'",
1515
"coverage": "mkdir -p coverage && AWS_ACCESS_KEY_ID=\"blah\" AWS_SECRET_ACCESS_KEY=\"blah\" node --test --experimental-test-coverage --test-reporter=spec --test-reporter-destination=stdout --test-reporter=lcov --test-reporter-destination=coverage/lcov.info 'test/unit/**/*-test.js'",
1616
"lint": "eslint . --fix",
1717
"rc": "npm version prerelease --preid RC"

test/integration/static/index-test.js

100644100755
Lines changed: 78 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
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
33
const { join } = require('path')
44
const { mkdtempSync, mkdirSync, writeFileSync, rmSync } = require('fs')
55
const { tmpdir } = require('os')
66
const inventory = require('@architect/inventory')
77
const { updater } = require('@architect/utils')
88
const staticDeployMod = require(join(process.cwd(), 'src', 'static', 'index.js'))
99

10+
let passed = 0
11+
let failed = 0
1012
let tmpDirs = []
1113

1214
function 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

4749
function 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

Comments
 (0)