Skip to content

Commit 7d6fb1b

Browse files
committed
fix: move to node test runner
1 parent 1f80e42 commit 7d6fb1b

22 files changed

Lines changed: 779 additions & 941 deletions

package.json

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
"scripts": {
1010
"test": "npm run lint && npm run test:integration && npm run coverage",
1111
"test:nolint": "npm run test:integration && npm run coverage",
12-
"test:unit": "cross-env AWS_ACCESS_KEY_ID=\"blah\" AWS_SECRET_ACCESS_KEY=\"blah\" tape 'test/unit/**/*-test.js' | tap-arc",
13-
"test:slow": "cross-env tape 'test/slow/**/*-test.js' | tap-arc",
14-
"test:integration": "cross-env AWS_ACCESS_KEY_ID=\"blah\" AWS_SECRET_ACCESS_KEY=\"blah\" tape 'test/integration/**/*-test.js' | tap-arc",
15-
"coverage": "nyc --reporter=lcov --reporter=text npm run test:unit",
12+
"test:unit": "AWS_ACCESS_KEY_ID=\"blah\" AWS_SECRET_ACCESS_KEY=\"blah\" node --test --test-reporter=spec 'test/unit/**/*-test.js'",
13+
"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'",
15+
"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"
1818
},
@@ -33,31 +33,25 @@
3333
},
3434
"homepage": "https://github.com/architect/deploy#readme",
3535
"dependencies": {
36-
"@architect/create": "~7.0.0",
36+
"@architect/create": "~7.0.1",
3737
"@architect/hydrate": "~6.0.0",
3838
"@architect/inventory": "~6.0.0",
39-
"@architect/package": "~11.0.0",
40-
"@architect/utils": "~6.0.0",
39+
"@architect/package": "~11.0.1",
40+
"@architect/utils": "~6.0.1",
4141
"@aws-lite/apigatewayv2": "^0.0.9",
4242
"@aws-lite/client": "^0.23.2",
4343
"@aws-lite/cloudformation": "^0.1.3",
4444
"@aws-lite/cloudfront": "^0.0.11",
4545
"@aws-lite/lambda": "^0.1.5",
4646
"@aws-lite/s3": "^0.2.6",
4747
"@aws-lite/ssm": "^0.2.3",
48-
"fs-extra": "11.3.0",
49-
"mime-types": "3.0.1",
48+
"fs-extra": "~11.3.2",
49+
"mime-types": "~3.0.2",
5050
"zip-dir": "2.0.0",
5151
"zipit": "2.0.0"
5252
},
5353
"devDependencies": {
5454
"@architect/eslint-config": "~3.0.0",
55-
"cross-env": "~10.0.0",
56-
"eslint": "~9.39.1",
57-
"mock-tmp": "~0.0.4",
58-
"nyc": "~17.1.0",
59-
"proxyquire": "~2.1.3",
60-
"tap-arc": "~1.3.2",
61-
"tape": "~5.9.0"
55+
"eslint": "~9.39.1"
6256
}
6357
}

test/integration/macros-n-plugins-test.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
let test = require('tape')
2-
let { join } = require('path')
3-
let origDir = process.cwd()
1+
const { test } = require('node:test')
2+
const assert = require('node:assert/strict')
3+
const { join } = require('path')
4+
const origDir = process.cwd()
45
// let sam = require('../../src/sam')
5-
let inventory = require('@architect/inventory')
6+
const inventory = require('@architect/inventory')
67
// let inv
78

8-
test('end-to-end sam setup', t => {
9-
t.plan(3)
9+
test('end-to-end sam setup', () => {
1010
process.chdir(join(__dirname, '..', 'mocks', 'app-with-extensions'))
11-
t.pass('chdir to mock app')
11+
assert.ok(true, 'chdir to mock app')
1212
inventory({}, (err, result) => {
13-
t.notOk(err, 'no error retrieving inventory from mock app')
14-
t.ok(result, 'got some manner of inventory')
13+
assert.ok(!err, 'no error retrieving inventory from mock app')
14+
assert.ok(result, 'got some manner of inventory')
1515
// inv = result
1616
})
1717
})
@@ -44,8 +44,7 @@ test('(hydrate=true) multiple macro and plugin cfn additions honoured', t => {
4444
})
4545
})
4646
*/
47-
test('end-to-end sam teardown', t => {
48-
t.plan(1)
47+
test('end-to-end sam teardown', () => {
4948
process.chdir(origDir)
50-
t.pass('chdir to original')
49+
assert.ok(true, 'chdir to original')
5150
})
Lines changed: 113 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,66 @@
1-
let test = require('tape')
2-
let { join } = require('path')
3-
let mockTmp = require('mock-tmp')
4-
let proxyquire = require('proxyquire')
5-
let inventory = require('@architect/inventory')
6-
let { updater } = require('@architect/utils')
1+
const { test, after } = require('node:test')
2+
const assert = require('node:assert/strict')
3+
const { join } = require('path')
4+
const { mkdtempSync, mkdirSync, writeFileSync, rmSync } = require('fs')
5+
const { tmpdir } = require('os')
6+
const inventory = require('@architect/inventory')
7+
const { updater } = require('@architect/utils')
8+
9+
let tmpDirs = []
10+
11+
function createTmpDir (structure) {
12+
const tmpDir = mkdtempSync(join(tmpdir(), 'arc-test-'))
13+
tmpDirs.push(tmpDir)
14+
const { dirname } = require('path')
15+
16+
function createStructure (base, obj) {
17+
for (const [ key, value ] of Object.entries(obj)) {
18+
const path = join(base, key)
19+
if (typeof value === 'object' && value !== null && !Buffer.isBuffer(value)) {
20+
mkdirSync(path, { recursive: true })
21+
createStructure(path, value)
22+
}
23+
else {
24+
// Ensure parent directory exists for files
25+
const dir = dirname(path)
26+
mkdirSync(dir, { recursive: true })
27+
writeFileSync(path, value || '')
28+
}
29+
}
30+
}
31+
32+
createStructure(tmpDir, structure)
33+
return tmpDir
34+
}
35+
36+
after(() => {
37+
tmpDirs.forEach(dir => {
38+
try {
39+
rmSync(dir, { recursive: true, force: true })
40+
}
41+
catch {
42+
// Ignore cleanup errors
43+
}
44+
})
45+
})
746

847
let published
948
function publish (params, callback) {
1049
published = params
1150
callback(null, params)
1251
}
1352

14-
let staticDeployPath = join(process.cwd(), 'src', 'static', 'index.js')
15-
let staticDeployMod = proxyquire(staticDeployPath, {
16-
'./publish': publish,
17-
})
53+
// Mock the publish module using Module._load interception
54+
const Module = require('module')
55+
const originalLoad = Module._load
56+
Module._load = function (request, parent) {
57+
if (request === './publish' && parent.filename.includes('src/static/index.js')) {
58+
return publish
59+
}
60+
return originalLoad.apply(this, arguments)
61+
}
62+
63+
const staticDeployMod = require(join(process.cwd(), 'src', 'static', 'index.js'))
1864

1965
let defaultParams = () => ({
2066
bucket: 'a-bucket',
@@ -36,12 +82,11 @@ function setup () {
3682
}
3783
function reset () {
3884
params = defaultParams()
39-
mockTmp.reset()
4085
}
4186

42-
function staticDeploy (t, cwd, callback) {
87+
function staticDeploy (cwd, callback) {
4388
inventory({ cwd }, function (err, result) {
44-
if (err) t.fail(err)
89+
if (err) callback(err)
4590
else {
4691
params.inventory = result
4792
staticDeployMod(params, err => {
@@ -54,113 +99,109 @@ function staticDeploy (t, cwd, callback) {
5499

55100
/**
56101
* Notes:
57-
* - Unfortunately, proxyquire seems to have a nested file folder + `@global` bug, so we can't run this from index
58-
* - Instead, we have to run inventory ourselves on each test, which kinda sucks
59102
* - Also, it'd be nice to test the CloudFormation stackname code path
60103
*/
61-
test('Set up env', t => {
62-
t.plan(1)
63-
t.ok(staticDeployMod, 'Static asset deployment module is present')
104+
test('Set up env', () => {
105+
assert.ok(staticDeployMod, 'Static asset deployment module is present')
64106
})
65107

66-
test(`Skip static deploy if @static isn't defined`, t => {
67-
t.plan(1)
108+
test(`Skip static deploy if @static isn't defined`, (t, done) => {
68109
setup()
69110
let arc = '@app\n an-app'
70-
let cwd = mockTmp({ 'app.arc': arc })
71-
staticDeploy(t, cwd, err => {
72-
if (err) t.fail(err)
73-
t.notOk(published, 'Publish not called')
111+
let cwd = createTmpDir({ 'app.arc': arc })
112+
staticDeploy(cwd, err => {
113+
if (err) assert.fail(err)
114+
assert.ok(!published, 'Publish not called')
115+
done()
74116
})
75117
})
76118

77-
test(`Static deploy exits gracefully if @http is defined, but public/ folder is not present`, t => {
78-
t.plan(1)
119+
test(`Static deploy exits gracefully if @http is defined, but public/ folder is not present`, (t, done) => {
79120
setup()
80121
let arc = '@app\n an-app\n @http'
81-
let cwd = mockTmp({ 'app.arc': arc })
82-
staticDeploy(t, cwd, err => {
83-
if (err) t.fail(err)
84-
t.notOk(published, 'Publish not called')
122+
let cwd = createTmpDir({ 'app.arc': arc })
123+
staticDeploy(cwd, err => {
124+
if (err) assert.fail(err)
125+
assert.ok(!published, 'Publish not called')
126+
done()
85127
})
86128
})
87129

88-
test(`Publish static deploy if @static is defined`, t => {
89-
t.plan(4)
130+
test(`Publish static deploy if @static is defined`, (t, done) => {
90131
setup()
91132
let arc = '@app\n an-app\n @static'
92-
let cwd = mockTmp({
133+
let cwd = createTmpDir({
93134
'app.arc': arc,
94135
'public': {},
95136
})
96-
staticDeploy(t, cwd, err => {
97-
if (err) t.fail(err)
98-
t.equal(published.Bucket, params.bucket, 'Bucket is unchanged')
99-
t.equal(published.prefix, null, 'Prefix set to null by default')
100-
t.equal(published.prune, null, 'Prune set to null by default')
101-
t.equal(published.region, params.region, 'Region is unchaged')
137+
staticDeploy(cwd, err => {
138+
if (err) assert.fail(err)
139+
assert.strictEqual(published.Bucket, params.bucket, 'Bucket is unchanged')
140+
assert.strictEqual(published.prefix, null, 'Prefix set to null by default')
141+
assert.strictEqual(published.prune, null, 'Prune set to null by default')
142+
assert.strictEqual(published.region, params.region, 'Region is unchaged')
143+
done()
102144
})
103145
})
104146

105-
test(`Publish static deploy if @http is defined and public/ folder is present`, t => {
106-
t.plan(1)
147+
test(`Publish static deploy if @http is defined and public/ folder is present`, (t, done) => {
107148
setup()
108149
let arc = '@app\n an-app\n @http'
109-
let cwd = mockTmp({ 'app.arc': arc, 'public': {} })
110-
staticDeploy(t, cwd, err => {
111-
if (err) t.fail(err)
112-
t.ok(published, 'Publish was called')
150+
let cwd = createTmpDir({ 'app.arc': arc, 'public': {} })
151+
staticDeploy(cwd, err => {
152+
if (err) assert.fail(err)
153+
assert.ok(published, 'Publish was called')
154+
done()
113155
})
114156
})
115157

116-
test(`Respect prune param`, t => {
117-
t.plan(1)
158+
test(`Respect prune param`, (t, done) => {
118159
setup()
119160
let arc = '@app\n an-app\n @static'
120-
let cwd = mockTmp({ 'app.arc': arc, 'public': {} })
161+
let cwd = createTmpDir({ 'app.arc': arc, 'public': {} })
121162
params.prune = true
122-
staticDeploy(t, cwd, err => {
123-
if (err) t.fail(err)
124-
t.ok(published.prune, 'Prune is unchaged')
163+
staticDeploy(cwd, err => {
164+
if (err) assert.fail(err)
165+
assert.ok(published.prune, 'Prune is unchaged')
166+
done()
125167
})
126168
})
127169

128-
test(`Respect prune setting in project manifest`, t => {
129-
t.plan(1)
170+
test(`Respect prune setting in project manifest`, (t, done) => {
130171
setup()
131172
let arc = '@app\n an-app\n @static\n prune true'
132-
let cwd = mockTmp({ 'app.arc': arc, 'public': {} })
133-
staticDeploy(t, cwd, err => {
134-
if (err) t.fail(err)
135-
t.ok(published.prune, 'Prune is enabled')
173+
let cwd = createTmpDir({ 'app.arc': arc, 'public': {} })
174+
staticDeploy(cwd, err => {
175+
if (err) assert.fail(err)
176+
assert.ok(published.prune, 'Prune is enabled')
177+
done()
136178
})
137179
})
138180

139-
test(`Respect prefix param`, t => {
140-
t.plan(1)
181+
test(`Respect prefix param`, (t, done) => {
141182
setup()
142183
let arc = '@app\n an-app\n @static'
143-
let cwd = mockTmp({ 'app.arc': arc, 'public': {} })
184+
let cwd = createTmpDir({ 'app.arc': arc, 'public': {} })
144185
params.prefix = 'some-prefix'
145-
staticDeploy(t, cwd, err => {
146-
if (err) t.fail(err)
147-
t.equal(published.prefix, 'some-prefix', 'Prefix is unchanged')
186+
staticDeploy(cwd, err => {
187+
if (err) assert.fail(err)
188+
assert.strictEqual(published.prefix, 'some-prefix', 'Prefix is unchanged')
189+
done()
148190
})
149191
})
150192

151-
test(`Respect prefix setting in project manifest`, t => {
152-
t.plan(1)
193+
test(`Respect prefix setting in project manifest`, (t, done) => {
153194
setup()
154195
let arc = '@app\n an-app\n @static\n prefix some-prefix'
155-
let cwd = mockTmp({ 'app.arc': arc, 'public': {} })
156-
staticDeploy(t, cwd, err => {
157-
if (err) t.fail(err)
158-
t.equal(published.prefix, 'some-prefix', 'Got correct prefix setting')
196+
let cwd = createTmpDir({ 'app.arc': arc, 'public': {} })
197+
staticDeploy(cwd, err => {
198+
if (err) assert.fail(err)
199+
assert.strictEqual(published.prefix, 'some-prefix', 'Got correct prefix setting')
200+
done()
159201
})
160202
})
161203

162-
test('Teardown', t => {
163-
t.plan(1)
204+
test('Teardown', () => {
164205
reset()
165-
t.pass('Done')
206+
assert.ok(true, 'Done')
166207
})

0 commit comments

Comments
 (0)