Skip to content

Commit

Permalink
fixup!
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Mar 30, 2022
1 parent db0f5aa commit 752a2c0
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions docs/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit 752a2c0

Please # to comment.