From 752a2c00c921f598fe8cbd094c87f3c81faea616 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Tue, 29 Mar 2022 23:25:54 -0700 Subject: [PATCH] fixup! --- docs/test/index.js | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/docs/test/index.js b/docs/test/index.js index b484aca411bb1..cee4cc3ab8cff 100644 --- a/docs/test/index.js +++ b/docs/test/index.js @@ -7,24 +7,28 @@ const cwd = resolve(__dirname, '..') const output = join(cwd, 'output') const cli = require.resolve(resolve(cwd, '..')) -// remove npm config when spawning so config set by test commands don't interfere -const env = Object.fromEntries( - Object.entries(process.env).filter(([k]) => !k.toLowerCase().startsWith('npm_config_')) -) +const rmOutput = () => fs.rm(output, { recursive: true, force: true }).catch(() => {}) -const rm = (d) => fs.rm(d, { recursive: true, force: true }).catch(() => {}) +const spawnNpm = (args, opts) => { + // remove npm config when spawning so config set by test commands don't interfere + const env = Object.entries(process.env) + .filter(([k]) => !k.toLowerCase().startsWith('npm_config_')) + + return spawn('node', [cli, ...args], { + env: Object.fromEntries(env), + stdioString: true, + ...opts, + }) +} t.test('docs', async (t) => { - t.teardown(() => rm(output)) + t.teardown(rmOutput) - await rm(output) + await rmOutput() t.rejects(() => fs.stat(output)) - const docs = await spawn('node', [cli, 'run', 'build'], { - cwd, - env, - stdioString: true, - }) + // calling run build will rebuild cmark-gfm with a prebuild script + const docs = await spawnNpm(['run', 'build'], { cwd }) t.equal(docs.code, 0) t.ok((await fs.stat(output)).isDirectory())