Skip to content

Commit 3173ed7

Browse files
committed
promote: convert check_assets tests to node:test
Refs: #3958
1 parent 5886bcd commit 3173ed7

File tree

2 files changed

+316
-387
lines changed

2 files changed

+316
-387
lines changed

ansible/www-standalone/tools/promote/check_assets.js

-387
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
const fs = require('fs').promises
44
const path = require('path')
5-
const childProcess = require('child_process')
6-
const assert = require('assert')
75

86
const versionRe = /^v\d+\.\d+\.\d+/
97
const additionalDistAssets = [
@@ -217,388 +215,3 @@ async function execute () {
217215
console.log(' \u001b[33mPromote if you are certain this is the the correct course of action\u001b[39m')
218216
}
219217
}
220-
221-
/* TESTS ***********************************************************************/
222-
223-
function test () {
224-
// makes a staging or dist directory given a version string
225-
async function makeFixture (version, isStaging, dir, assets) {
226-
if (!assets) {
227-
assets = await loadExpectedAssets(version)
228-
}
229-
for (let asset of assets) {
230-
let absoluteAsset = path.join(dir, asset)
231-
if (asset.endsWith('/')) {
232-
await fs.mkdir(absoluteAsset, { recursive: true })
233-
} else {
234-
await fs.writeFile(absoluteAsset, asset, 'utf8')
235-
}
236-
let dashPos = isStaging && asset.indexOf('/')
237-
if (isStaging && (dashPos === -1 || dashPos === asset.length - 1)) {
238-
// in staging, all files and directories that are ready have a
239-
// duplicate empty file with .done in the name
240-
await fs.writeFile(absoluteAsset.replace(/\/?$/, '.done'), asset, 'utf8')
241-
}
242-
}
243-
return assets
244-
}
245-
246-
async function rimraf (dir) {
247-
const stat = await fs.stat(dir)
248-
if (!stat.isDirectory()) {
249-
await fs.unlink(dir)
250-
return
251-
}
252-
const ls = await fs.readdir(dir)
253-
for (let f of ls) {
254-
f = path.join(dir, f)
255-
const stat = await fs.stat(f)
256-
if (stat.isDirectory()) {
257-
await rimraf(f)
258-
} else {
259-
await fs.unlink(f)
260-
}
261-
}
262-
await fs.rmdir(dir)
263-
}
264-
265-
// execute check_assets.js with the given staging and dist dirs, collect output
266-
async function executeMe (stagingDir, distDir) {
267-
return new Promise((resolve, reject) => {
268-
const args = [ '--no-warnings', __filename, stagingDir, distDir ]
269-
childProcess.execFile(process.execPath, args, (err, stdout, stderr) => {
270-
if (err) {
271-
return reject(err)
272-
}
273-
if (stderr) {
274-
console.log('STDERR:', stderr)
275-
}
276-
resolve(stdout)
277-
})
278-
})
279-
}
280-
281-
async function runTest (number, version, expectedStdout, setup) {
282-
const testDir = await fs.mkdtemp(`${__filename}_`)
283-
const fixtureStagingDir = path.join(testDir, `staging/${version}`)
284-
const fixtureDistDir = path.join(testDir, `dist/${version}`)
285-
await setup(fixtureStagingDir, fixtureDistDir)
286-
287-
const stdout = await executeMe(fixtureStagingDir, fixtureDistDir)
288-
console.log(`\nTest ${number} Assertions ???`)
289-
console.log(`STDOUT------------------------------------------\n\n${stdout}\n------------------------------------------------`)
290-
assert.equal(stdout, expectedStdout)
291-
console.log(`Test ${number} Assertions ✓✓✓`)
292-
293-
await rimraf(testDir)
294-
}
295-
// TEST 1: Everything is in staging, nothing in dist, good to go
296-
async function test1 () {
297-
const version = 'v8.13.0'
298-
const expectedStdout =
299-
'... Checking assets\n' +
300-
'... Expecting a total of 44 assets for v8.x\n' +
301-
'... 44 assets waiting in staging\n' +
302-
'... 0 assets already promoted\n' +
303-
' \u001b[32m\u001b[1m✓\u001b[22m\u001b[39m Complete set of expected assets in place for v8.x\n'
304-
305-
async function setup (fixtureStagingDir, fixtureDistDir) {
306-
await makeFixture(version, true, fixtureStagingDir)
307-
}
308-
309-
return runTest(1, version, expectedStdout, setup)
310-
}
311-
312-
// TEST 2: Not quite everything is in staging, missing two assets, nothing in dist
313-
async function test2 () {
314-
const version = 'v10.1.0'
315-
const expectedStdout =
316-
'... Checking assets\n' +
317-
'... Expecting a total of 41 assets for v10.x\n' +
318-
'... 38 assets waiting in staging\n' +
319-
'... 0 assets already promoted\n' +
320-
' \u001b[33m\u001b[1m⚠\u001b[22m\u001b[39m The following assets are expected for v10.x but are currently missing from staging:\n' +
321-
' • node-v10.1.0-linux-armv6l.tar.gz\n' +
322-
' • node-v10.1.0-linux-armv6l.tar.xz\n' +
323-
' • node-v10.1.0.pkg\n' +
324-
' \u001b[33mPromote if you are certain this is the the correct course of action\u001b[39m\n'
325-
326-
async function setup (fixtureStagingDir, fixtureDistDir) {
327-
await makeFixture(version, true, fixtureStagingDir)
328-
await Promise.all([
329-
fs.unlink(path.join(fixtureStagingDir, 'node-v10.1.0-linux-armv6l.tar.gz')),
330-
fs.unlink(path.join(fixtureStagingDir, 'node-v10.1.0-linux-armv6l.tar.gz.done')),
331-
fs.unlink(path.join(fixtureStagingDir, 'node-v10.1.0-linux-armv6l.tar.xz')),
332-
fs.unlink(path.join(fixtureStagingDir, 'node-v10.1.0-linux-armv6l.tar.xz.done')),
333-
fs.unlink(path.join(fixtureStagingDir, 'node-v10.1.0.pkg')),
334-
fs.unlink(path.join(fixtureStagingDir, 'node-v10.1.0.pkg.done'))
335-
])
336-
}
337-
338-
return runTest(2, version, expectedStdout, setup)
339-
}
340-
341-
// TEST 3: Everything in staging, 3 files in dist
342-
async function test3 () {
343-
const version = 'v6.0.1'
344-
const expectedStdout =
345-
'... Checking assets\n' +
346-
'... Expecting a total of 46 assets for v6.x\n' +
347-
'... 46 assets waiting in staging\n' +
348-
' \u001b[33m\u001b[1m⚠\u001b[22m\u001b[39m 3 assets already promoted will be overwritten, is this OK?\n' +
349-
' • node-v6.0.1-headers.tar.gz\n' +
350-
' • node-v6.0.1-x86.msi\n' +
351-
' • node-v6.0.1.tar.gz\n' +
352-
' \u001b[32m\u001b[1m✓\u001b[22m\u001b[39m Complete set of expected assets in place for v6.x\n' +
353-
' \u001b[33mPromote if you are certain this is the the correct course of action\u001b[39m\n'
354-
355-
async function setup (fixtureStagingDir, fixtureDistDir) {
356-
await makeFixture(version, true, fixtureStagingDir)
357-
const distAssets = await makeFixture(version, false, fixtureDistDir)
358-
await Promise.all(
359-
distAssets.filter((a) => {
360-
return a !== 'node-v6.0.1-headers.tar.gz' &&
361-
a !== 'node-v6.0.1.tar.gz' &&
362-
a !== 'node-v6.0.1-x86.msi' &&
363-
// deleting all directories, so we don't need to delete the children
364-
!/^win-x64\/.+/.test(a) &&
365-
!/^win-x86\/.+/.test(a) &&
366-
!/^docs\/.+/.test(a)
367-
}).map((e) => rimraf(path.join(fixtureDistDir, e)))
368-
)
369-
}
370-
371-
return runTest(3, version, expectedStdout, setup)
372-
}
373-
374-
// TEST 4: Everything in staging and everything in dist
375-
async function test4 () {
376-
const version = 'v11.11.11'
377-
const expectedStdout =
378-
'... Checking assets\n' +
379-
'... Expecting a total of 41 assets for v11.x\n' +
380-
'... 41 assets waiting in staging\n' +
381-
' \u001b[33m\u001b[1m⚠\u001b[22m\u001b[39m 41 assets already promoted will be overwritten, is this OK?\n' +
382-
' \u001b[32m\u001b[1m✓\u001b[22m\u001b[39m Complete set of expected assets in place for v11.x\n' +
383-
' \u001b[33mPromote if you are certain this is the the correct course of action\u001b[39m\n'
384-
385-
async function setup (fixtureStagingDir, fixtureDistDir) {
386-
await makeFixture(version, true, fixtureStagingDir)
387-
await makeFixture(version, false, fixtureDistDir)
388-
}
389-
390-
return runTest(4, version, expectedStdout, setup)
391-
}
392-
393-
// TEST 5: No expected files list is available for this version, it has to guess
394-
async function test5 () {
395-
const version = 'v9.9.9'
396-
const expectedStdout =
397-
'... Checking assets\n' +
398-
' \u001b[33m\u001b[1m⚠\u001b[22m\u001b[39m No expected asset list is available for v9.x, using the list for v8.x instead\n' +
399-
' Should a new list be created for v9.x?\n' +
400-
' https://github.com/nodejs/build/tree/main/ansible/www-standalone/tools/promote/expected_assets/v9.x\n' +
401-
'... Expecting a total of 44 assets for v9.x\n' +
402-
'... 41 assets waiting in staging\n' +
403-
'... 0 assets already promoted\n' +
404-
' \u001b[33m\u001b[1m⚠\u001b[22m\u001b[39m The following assets are expected for v9.x but are currently missing from staging:\n' +
405-
' • node-v9.9.9-linux-x86.tar.gz\n' +
406-
' • node-v9.9.9-linux-x86.tar.xz\n' +
407-
' • node-v9.9.9-sunos-x86.tar.gz\n' +
408-
' • node-v9.9.9-sunos-x86.tar.xz\n' +
409-
' \u001b[31m\u001b[1m✖\u001b[22m\u001b[39m The following assets were found in staging but are not expected for v9.x:\n' +
410-
' • docs/apilinks.json\n' +
411-
' Does the expected assets list for v9.x need to be updated?\n' +
412-
' https://github.com/nodejs/build/tree/main/ansible/www-standalone/tools/promote/expected_assets/v9.x\n' +
413-
' \u001b[33mPromote if you are certain this is the the correct course of action\u001b[39m\n'
414-
415-
async function setup (fixtureStagingDir, fixtureDistDir) {
416-
// use the 10.x list, which is missing the x86 files, it'll check the 9.x
417-
const expectedAssets = await loadExpectedAssets(version, 'v10.x')
418-
await makeFixture(version, true, fixtureStagingDir, expectedAssets)
419-
}
420-
421-
return runTest(5, version, expectedStdout, setup)
422-
}
423-
424-
// TEST 6: Everything is in dist except for the armv6l files, but they are in staging
425-
async function test6 () {
426-
const version = 'v10.0.0'
427-
const expectedStdout =
428-
'... Checking assets\n' +
429-
'... Expecting a total of 41 assets for v10.x\n' +
430-
'... 2 assets waiting in staging\n' +
431-
'... 39 assets already promoted\n' +
432-
' \u001b[32m\u001b[1m✓\u001b[22m\u001b[39m Complete set of expected assets in place for v10.x\n'
433-
434-
async function setup (fixtureStagingDir, fixtureDistDir) {
435-
await fs.mkdir(fixtureStagingDir, { recursive: true })
436-
await makeFixture(version, true, fixtureStagingDir, [
437-
'node-v10.0.0-linux-armv6l.tar.gz',
438-
'node-v10.0.0-linux-armv6l.tar.xz'
439-
])
440-
await makeFixture(version, false, fixtureDistDir)
441-
await Promise.all([
442-
fs.unlink(path.join(fixtureDistDir, 'node-v10.0.0-linux-armv6l.tar.gz')),
443-
fs.unlink(path.join(fixtureDistDir, 'node-v10.0.0-linux-armv6l.tar.xz'))
444-
])
445-
}
446-
447-
return runTest(6, version, expectedStdout, setup)
448-
}
449-
450-
// TEST 7: Some unexpected files in staging
451-
async function test7 () {
452-
const version = 'v10.0.0'
453-
const expectedStdout =
454-
'... Checking assets\n' +
455-
'... Expecting a total of 41 assets for v10.x\n' +
456-
'... 2 assets waiting in staging\n' +
457-
'... 41 assets already promoted\n' +
458-
' \u001b[32m\u001b[1m✓\u001b[22m\u001b[39m Complete set of expected assets in place for v10.x\n' +
459-
' \u001b[31m\u001b[1m✖\u001b[22m\u001b[39m The following assets were found in staging but are not expected for v10.x:\n' +
460-
' • ooolaalaa.tar.gz\n' +
461-
' • whatdis.tar.xz\n' +
462-
' Does the expected assets list for v10.x need to be updated?\n' +
463-
' https://github.com/nodejs/build/tree/main/ansible/www-standalone/tools/promote/expected_assets/v10.x\n' +
464-
' \u001b[33mPromote if you are certain this is the the correct course of action\u001b[39m\n'
465-
466-
async function setup (fixtureStagingDir, fixtureDistDir) {
467-
await fs.mkdir(fixtureStagingDir, { recursive: true })
468-
await makeFixture(version, true, fixtureStagingDir, [
469-
'ooolaalaa.tar.gz',
470-
'whatdis.tar.xz'
471-
])
472-
await makeFixture(version, false, fixtureDistDir)
473-
}
474-
475-
return runTest(7, version, expectedStdout, setup)
476-
}
477-
478-
// TEST 8: Unexpected files in subdirectories, only check 2 levels deep
479-
async function test8 () {
480-
const version = 'v11.11.1'
481-
const expectedStdout =
482-
'... Checking assets\n' +
483-
'... Expecting a total of 41 assets for v11.x\n' +
484-
'... 43 assets waiting in staging\n' +
485-
'... 0 assets already promoted\n' +
486-
' \u001b[32m\u001b[1m✓\u001b[22m\u001b[39m Complete set of expected assets in place for v11.x\n' +
487-
' \u001b[31m\u001b[1m✖\u001b[22m\u001b[39m The following assets were found in staging but are not expected for v11.x:\n' +
488-
' • docs/bar\n' +
489-
' • docs/foo\n' +
490-
' Does the expected assets list for v11.x need to be updated?\n' +
491-
' https://github.com/nodejs/build/tree/main/ansible/www-standalone/tools/promote/expected_assets/v11.x\n' +
492-
' \u001b[33mPromote if you are certain this is the the correct course of action\u001b[39m\n'
493-
494-
async function setup (fixtureStagingDir, fixtureDistDir) {
495-
await fs.mkdir(fixtureStagingDir, { recursive: true })
496-
await makeFixture(version, true, fixtureStagingDir)
497-
await Promise.all([
498-
fs.writeFile(path.join(fixtureStagingDir, 'docs/foo'), 'foo'),
499-
fs.writeFile(path.join(fixtureStagingDir, 'docs/bar'), 'foo'),
500-
fs.writeFile(path.join(fixtureStagingDir, 'docs/api/baz'), 'bar')
501-
])
502-
}
503-
504-
return runTest(8, version, expectedStdout, setup)
505-
}
506-
507-
// TEST 9: Some unexpected files in dist
508-
async function test9 () {
509-
const version = 'v6.7.8'
510-
const expectedStdout =
511-
'... Checking assets\n' +
512-
'... Expecting a total of 46 assets for v6.x\n' +
513-
'... 46 assets waiting in staging\n' +
514-
'... 2 assets already promoted\n' +
515-
' \u001b[32m\u001b[1m✓\u001b[22m\u001b[39m Complete set of expected assets in place for v6.x\n' +
516-
' \u001b[31m\u001b[1m✖\u001b[22m\u001b[39m The following assets were already promoted but are not expected for v6.x:\n' +
517-
' • ooolaalaa.tar.gz\n' +
518-
' • whatdis.tar.xz\n' +
519-
' Does the expected assets list for v6.x need to be updated?\n' +
520-
' https://github.com/nodejs/build/tree/main/ansible/www-standalone/tools/promote/expected_assets/v6.x\n' +
521-
' \u001b[33mPromote if you are certain this is the the correct course of action\u001b[39m\n'
522-
523-
async function setup (fixtureStagingDir, fixtureDistDir) {
524-
await fs.mkdir(fixtureDistDir, { recursive: true })
525-
await makeFixture(version, false, fixtureDistDir, [
526-
'ooolaalaa.tar.gz',
527-
'whatdis.tar.xz'
528-
])
529-
await makeFixture(version, true, fixtureStagingDir)
530-
}
531-
532-
return runTest(9, version, expectedStdout, setup)
533-
}
534-
535-
// TEST 10: SHASUMS in dist already, shouldn't bother us
536-
async function test10 () {
537-
const version = 'v8.0.0'
538-
const expectedStdout =
539-
'... Checking assets\n' +
540-
'... Expecting a total of 44 assets for v8.x\n' +
541-
'... 44 assets waiting in staging\n' +
542-
' \u001b[33m\u001b[1m⚠\u001b[22m\u001b[39m 4 assets already promoted will be overwritten, is this OK?\n' +
543-
' • docs/\n' +
544-
' • docs/api/\n' +
545-
' • node-v8.0.0-linux-armv6l.tar.gz\n' +
546-
' • node-v8.0.0-linux-armv6l.tar.xz\n' +
547-
' \u001b[32m\u001b[1m✓\u001b[22m\u001b[39m Complete set of expected assets in place for v8.x\n' +
548-
' \u001b[33mPromote if you are certain this is the the correct course of action\u001b[39m\n'
549-
550-
async function setup (fixtureStagingDir, fixtureDistDir) {
551-
await fs.mkdir(fixtureDistDir, { recursive: true })
552-
await Promise.all([
553-
makeFixture(version, true, fixtureStagingDir),
554-
makeFixture(version, false, fixtureDistDir, [
555-
'SHASUMS256.txt',
556-
'SHASUMS256.txt.asc',
557-
'SHASUMS256.txt.sig',
558-
'docs/',
559-
'docs/api/',
560-
'docs/api/bar',
561-
'node-v8.0.0-linux-armv6l.tar.gz',
562-
'node-v8.0.0-linux-armv6l.tar.xz'
563-
])
564-
])
565-
}
566-
567-
return runTest(10, version, expectedStdout, setup)
568-
}
569-
570-
// run in parallel and just print failures to stderr
571-
let failures = 0
572-
let passes = 0
573-
const tests = [
574-
test1,
575-
test2,
576-
test3,
577-
test4,
578-
test5,
579-
test6,
580-
test7,
581-
test8,
582-
test9,
583-
test10
584-
]
585-
586-
tests.forEach((test) => {
587-
test()
588-
.then(() => passes++)
589-
.catch((err) => {
590-
failures++
591-
console.error(err)
592-
})
593-
})
594-
595-
process.on('exit', () => {
596-
if (failures) {
597-
console.error(`\n\u001b[31mThere were ${failures} test failures\u001b[39m`)
598-
} else if (passes === tests.length) {
599-
console.error('\n\u001b[32mAll tests have passed!\u001b[39m')
600-
} else {
601-
console.error(`\n\u001b[31mNot all tests seem to have run, something's wrong\u001b[39m`)
602-
}
603-
})
604-
}

0 commit comments

Comments
 (0)