Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: replace requireInject with t.mock tap api #2370

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
690 changes: 11 additions & 679 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -189,7 +189,7 @@
"json-parse-even-better-errors": "^2.3.1",
"marked-man": "^0.7.0",
"require-inject": "^1.4.4",
"tap": "^14.11.0",
"tap": "npm:@ruyadorno/tap-with-mocks@^14.10.8-patch.9",
"yaml": "^1.10.0"
},
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions test/bin/npm-cli.js
@@ -1,7 +1,7 @@
const t = require('tap')
const requireInject = require('require-inject')

t.test('loading the bin calls the implementation', t => {
requireInject('../../bin/npm-cli.js', {
t.mock('../../bin/npm-cli.js', {
'../../lib/cli.js': proc => {
t.equal(proc, process, 'called implementation with process object')
t.end()
Expand Down
13 changes: 6 additions & 7 deletions test/bin/npx-cli.js
@@ -1,5 +1,4 @@
const t = require('tap')
const requireInject = require('require-inject')
const npx = require.resolve('../../bin/npx-cli.js')
const cli = require.resolve('../../lib/cli.js')
const npm = require.resolve('../../bin/npm-cli.js')
Expand All @@ -14,35 +13,35 @@ t.afterEach(cb => {

t.test('npx foo -> npm exec -- foo', t => {
process.argv = ['node', npx, 'foo']
requireInject(npx, { [cli]: () => {} })
t.mock(npx, { [cli]: () => {} })
t.strictSame(process.argv, ['node', npm, 'exec', '--', 'foo'])
t.end()
})

t.test('npx -- foo -> npm exec -- foo', t => {
process.argv = ['node', npx, '--', 'foo']
requireInject(npx, { [cli]: () => {} })
t.mock(npx, { [cli]: () => {} })
t.strictSame(process.argv, ['node', npm, 'exec', '--', 'foo'])
t.end()
})

t.test('npx -x y foo -z -> npm exec -x y -- foo -z', t => {
process.argv = ['node', npx, '-x', 'y', 'foo', '-z']
requireInject(npx, { [cli]: () => {} })
t.mock(npx, { [cli]: () => {} })
t.strictSame(process.argv, ['node', npm, 'exec', '-x', 'y', '--', 'foo', '-z'])
t.end()
})

t.test('npx --x=y --no-install foo -z -> npm exec --x=y -- foo -z', t => {
process.argv = ['node', npx, '--x=y', '--no-install', 'foo', '-z']
requireInject(npx, { [cli]: () => {} })
t.mock(npx, { [cli]: () => {} })
t.strictSame(process.argv, ['node', npm, 'exec', '--x=y', '--yes=false', '--', 'foo', '-z'])
t.end()
})

t.test('transform renamed options into proper values', t => {
process.argv = ['node', npx, '-y', '--shell=bash', '-p', 'foo', '-c', 'asdf']
requireInject(npx, { [cli]: () => {} })
t.mock(npx, { [cli]: () => {} })
t.strictSame(process.argv, ['node', npm, 'exec', '--yes', '--script-shell=bash', '--package', 'foo', '--call', 'asdf'])
t.end()
})
Expand Down Expand Up @@ -80,7 +79,7 @@ t.test('use a bunch of deprecated switches and options', t => {
'--',
'foobar',
]
requireInject(npx, { [cli]: () => {} })
t.mock(npx, { [cli]: () => {} })
t.strictSame(process.argv, expect)
t.strictSame(logs, [
['npx: the --npm argument has been removed.'],
Expand Down