diff options
Diffstat (limited to 'deps/npm/test/index.js')
-rw-r--r-- | deps/npm/test/index.js | 32 |
1 files changed, 9 insertions, 23 deletions
diff --git a/deps/npm/test/index.js b/deps/npm/test/index.js index 747d75b5fd..44fb0989df 100644 --- a/deps/npm/test/index.js +++ b/deps/npm/test/index.js @@ -1,34 +1,20 @@ const t = require('tap') +const spawn = require('@npmcli/promise-spawn') const index = require.resolve('../index.js') const packageIndex = require.resolve('../') +const { load: loadMockNpm } = require('./fixtures/mock-npm') t.equal(index, packageIndex, 'index is main package require() export') t.throws(() => require(index), { message: 'The programmatic API was removed in npm v8.0.0', }) -t.test('loading as main module will load the cli', t => { - const cwd = t.testdir() - const { spawn } = require('child_process') +t.test('loading as main module will load the cli', async t => { + const { npm, cache } = await loadMockNpm(t) const LS = require('../lib/commands/ls.js') - const ls = new LS({ - config: { - validate: () => {}, - get: (key) => { - if (key === 'location') { - return 'project' - } - }, - isDefault: () => {}, - }, - }) - const p = spawn(process.execPath, [index, 'ls', '-h', '--cache', cwd]) - const out = [] - p.stdout.on('data', c => out.push(c)) - p.on('close', (code, signal) => { - t.equal(code, 0) - t.equal(signal, null) - t.match(Buffer.concat(out).toString(), ls.usage) - t.end() - }) + const ls = new LS(npm) + const p = await spawn(process.execPath, [index, 'ls', '-h', '--cache', cache]) + t.equal(p.code, 0) + t.equal(p.signal, null) + t.match(p.stdout, ls.usage) }) |