Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGar <gar+gh@danger.computer>2021-04-13 20:07:46 +0300
committerGar <gar+gh@danger.computer>2021-04-14 19:35:29 +0300
commitdfcd0c1e2331c1f4b6573466b50505772eddaf22 (patch)
tree9c0f72e605e26d279ad9f2b92d01ef000f550122 /test
parentf1e6743a6e8e32ddad6d1964eb05d17e6c50a456 (diff)
tap@15.0.2
PR-URL: https://github.com/npm/cli/pull/3069 Credit: @isaacs Close: #3069 Reviewed-by: @ruyadorno, @nlf
Diffstat (limited to 'test')
-rw-r--r--test/bin/npm-cli.js3
-rw-r--r--test/bin/npx-cli.js18
-rw-r--r--test/lib/access.js97
-rw-r--r--test/lib/adduser.js31
-rw-r--r--test/lib/audit.js7
-rw-r--r--test/lib/auth/legacy.js37
-rw-r--r--test/lib/auth/oauth.js7
-rw-r--r--test/lib/auth/saml.js7
-rw-r--r--test/lib/auth/sso.js25
-rw-r--r--test/lib/bin.js23
-rw-r--r--test/lib/bugs.js3
-rw-r--r--test/lib/cache.js13
-rw-r--r--test/lib/ci.js29
-rw-r--r--test/lib/cli.js3
-rw-r--r--test/lib/completion.js49
-rw-r--r--test/lib/config.js47
-rw-r--r--test/lib/dedupe.js15
-rw-r--r--test/lib/deprecate.js17
-rw-r--r--test/lib/diff.js16
-rw-r--r--test/lib/dist-tag.js74
-rw-r--r--test/lib/docs.js7
-rw-r--r--test/lib/doctor.js15
-rw-r--r--test/lib/edit.js17
-rw-r--r--test/lib/exec.js14
-rw-r--r--test/lib/explain.js10
-rw-r--r--test/lib/explore.js30
-rw-r--r--test/lib/fund.js103
-rw-r--r--test/lib/get.js7
-rw-r--r--test/lib/help-search.js17
-rw-r--r--test/lib/help.js35
-rw-r--r--test/lib/hook.js49
-rw-r--r--test/lib/init.js44
-rw-r--r--test/lib/install-ci-test.js3
-rw-r--r--test/lib/install-test.js3
-rw-r--r--test/lib/install.js35
-rw-r--r--test/lib/link.js13
-rw-r--r--test/lib/ll.js5
-rw-r--r--test/lib/load-all-commands.js7
-rw-r--r--test/lib/logout.js29
-rw-r--r--test/lib/ls.js233
-rw-r--r--test/lib/npm.js27
-rw-r--r--test/lib/org.js53
-rw-r--r--test/lib/outdated.js18
-rw-r--r--test/lib/owner.js27
-rw-r--r--test/lib/pack.js16
-rw-r--r--test/lib/ping.js21
-rw-r--r--test/lib/prefix.js2
-rw-r--r--test/lib/profile.js72
-rw-r--r--test/lib/prune.js7
-rw-r--r--test/lib/publish.js38
-rw-r--r--test/lib/rebuild.js3
-rw-r--r--test/lib/repo.js7
-rw-r--r--test/lib/root.js2
-rw-r--r--test/lib/run-script.js28
-rw-r--r--test/lib/search.js16
-rw-r--r--test/lib/set-script.js25
-rw-r--r--test/lib/set.js3
-rw-r--r--test/lib/shrinkwrap.js28
-rw-r--r--test/lib/star.js8
-rw-r--r--test/lib/stars.js6
-rw-r--r--test/lib/team.js42
-rw-r--r--test/lib/test.js3
-rw-r--r--test/lib/token.js97
-rw-r--r--test/lib/uninstall.js8
-rw-r--r--test/lib/unpublish.js42
-rw-r--r--test/lib/unstar.js5
-rw-r--r--test/lib/update.js24
-rw-r--r--test/lib/utils/audit-error.js3
-rw-r--r--test/lib/utils/cleanup-log-files.js3
-rw-r--r--test/lib/utils/completion/installed-deep.js21
-rw-r--r--test/lib/utils/completion/installed-shallow.js3
-rw-r--r--test/lib/utils/config/definitions.js53
-rw-r--r--test/lib/utils/did-you-mean.js3
-rw-r--r--test/lib/utils/error-handler.js41
-rw-r--r--test/lib/utils/error-message.js42
-rw-r--r--test/lib/utils/explain-dep.js3
-rw-r--r--test/lib/utils/explain-eresolve.js3
-rw-r--r--test/lib/utils/file-exists.js8
-rw-r--r--test/lib/utils/get-identity.js23
-rw-r--r--test/lib/utils/npm-usage.js3
-rw-r--r--test/lib/utils/open-url.js35
-rw-r--r--test/lib/utils/otplease.js17
-rw-r--r--test/lib/utils/path.js7
-rw-r--r--test/lib/utils/ping.js11
-rw-r--r--test/lib/utils/proc-log-listener.js3
-rw-r--r--test/lib/utils/pulse-till-done.js7
-rw-r--r--test/lib/utils/read-local-package.js11
-rw-r--r--test/lib/utils/read-user-info.js17
-rw-r--r--test/lib/utils/reify-finish.js5
-rw-r--r--test/lib/utils/reify-output.js4
-rw-r--r--test/lib/utils/replace-info.js4
-rw-r--r--test/lib/utils/setup-log.js6
-rw-r--r--test/lib/utils/split-package-names.js4
-rw-r--r--test/lib/utils/tar.js15
-rw-r--r--test/lib/utils/unsupported.js14
-rw-r--r--test/lib/utils/update-notifier.js7
-rw-r--r--test/lib/version.js16
-rw-r--r--test/lib/view.js51
-rw-r--r--test/lib/whoami.js15
-rw-r--r--test/lib/workspaces/get-workspaces.js16
100 files changed, 1074 insertions, 1225 deletions
diff --git a/test/bin/npm-cli.js b/test/bin/npm-cli.js
index bcca99c8c..7b4b619e2 100644
--- a/test/bin/npm-cli.js
+++ b/test/bin/npm-cli.js
@@ -1,7 +1,6 @@
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()
diff --git a/test/bin/npx-cli.js b/test/bin/npx-cli.js
index 2b7b48829..5eeee3018 100644
--- a/test/bin/npx-cli.js
+++ b/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')
@@ -7,42 +6,39 @@ const npm = require.resolve('../../bin/npm-cli.js')
const logs = []
console.error = (...msg) => logs.push(msg)
-t.afterEach(cb => {
- logs.length = 0
- cb()
-})
+t.afterEach(() => logs.length = 0)
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()
})
@@ -80,7 +76,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.'],
diff --git a/test/lib/access.js b/test/lib/access.js
index a8e28c8eb..5fd170bab 100644
--- a/test/lib/access.js
+++ b/test/lib/access.js
@@ -1,5 +1,4 @@
-const { test } = require('tap')
-const requireInject = require('require-inject')
+const t = require('tap')
const Access = require('../../lib/access.js')
@@ -7,7 +6,7 @@ const npm = {
output: () => null,
}
-test('completion', t => {
+t.test('completion', t => {
const access = new Access({ flatOptions: {} })
const testComp = (argv, expect) => {
const res = access.completion({conf: {argv: {remain: argv}}})
@@ -38,7 +37,7 @@ test('completion', t => {
t.end()
})
-test('subcommand required', t => {
+t.test('subcommand required', t => {
const access = new Access({ flatOptions: {} })
access.exec([], (err) => {
t.match(err, access.usageError('Subcommand is required.'))
@@ -46,7 +45,7 @@ test('subcommand required', t => {
})
})
-test('unrecognized subcommand', (t) => {
+t.test('unrecognized subcommand', (t) => {
const access = new Access({ flatOptions: {} })
access.exec(['blerg'], (err) => {
t.match(
@@ -58,7 +57,7 @@ test('unrecognized subcommand', (t) => {
})
})
-test('edit', (t) => {
+t.test('edit', (t) => {
const access = new Access({ flatOptions: {} })
access.exec([
'edit',
@@ -73,7 +72,7 @@ test('edit', (t) => {
})
})
-test('access public on unscoped package', (t) => {
+t.test('access public on unscoped package', (t) => {
const prefix = t.testdir({
'package.json': JSON.stringify({
name: 'npm-access-public-pkg',
@@ -92,13 +91,13 @@ test('access public on unscoped package', (t) => {
})
})
-test('access public on scoped package', (t) => {
+t.test('access public on scoped package', (t) => {
t.plan(4)
const name = '@scoped/npm-access-public-pkg'
const prefix = t.testdir({
'package.json': JSON.stringify({ name }),
})
- const Access = requireInject('../../lib/access.js', {
+ const Access = t.mock('../../lib/access.js', {
libnpmaccess: {
public: (pkg, { registry }) => {
t.equal(pkg, name, 'should use pkg name ref')
@@ -118,12 +117,12 @@ test('access public on scoped package', (t) => {
access.exec([
'public',
], (err) => {
- t.ifError(err, 'npm access')
+ t.error(err, 'npm access')
t.ok('should successfully access public on scoped package')
})
})
-test('access public on missing package.json', (t) => {
+t.test('access public on missing package.json', (t) => {
const prefix = t.testdir({
node_modules: {},
})
@@ -140,7 +139,7 @@ test('access public on missing package.json', (t) => {
})
})
-test('access public on invalid package.json', (t) => {
+t.test('access public on invalid package.json', (t) => {
const prefix = t.testdir({
'package.json': '{\n',
node_modules: {},
@@ -158,7 +157,7 @@ test('access public on invalid package.json', (t) => {
})
})
-test('access restricted on unscoped package', (t) => {
+t.test('access restricted on unscoped package', (t) => {
const prefix = t.testdir({
'package.json': JSON.stringify({
name: 'npm-access-restricted-pkg',
@@ -177,13 +176,13 @@ test('access restricted on unscoped package', (t) => {
})
})
-test('access restricted on scoped package', (t) => {
+t.test('access restricted on scoped package', (t) => {
t.plan(4)
const name = '@scoped/npm-access-restricted-pkg'
const prefix = t.testdir({
'package.json': JSON.stringify({ name }),
})
- const Access = requireInject('../../lib/access.js', {
+ const Access = t.mock('../../lib/access.js', {
libnpmaccess: {
restricted: (pkg, { registry }) => {
t.equal(pkg, name, 'should use pkg name ref')
@@ -203,12 +202,12 @@ test('access restricted on scoped package', (t) => {
access.exec([
'restricted',
], (err) => {
- t.ifError(err, 'npm access')
+ t.error(err, 'npm access')
t.ok('should successfully access restricted on scoped package')
})
})
-test('access restricted on missing package.json', (t) => {
+t.test('access restricted on missing package.json', (t) => {
const prefix = t.testdir({
node_modules: {},
})
@@ -225,7 +224,7 @@ test('access restricted on missing package.json', (t) => {
})
})
-test('access restricted on invalid package.json', (t) => {
+t.test('access restricted on invalid package.json', (t) => {
const prefix = t.testdir({
'package.json': '{\n',
node_modules: {},
@@ -243,9 +242,9 @@ test('access restricted on invalid package.json', (t) => {
})
})
-test('access grant read-only', (t) => {
+t.test('access grant read-only', (t) => {
t.plan(5)
- const Access = requireInject('../../lib/access.js', {
+ const Access = t.mock('../../lib/access.js', {
libnpmaccess: {
grant: (spec, team, permissions) => {
t.equal(spec, '@scoped/another', 'should use expected spec')
@@ -262,14 +261,14 @@ test('access grant read-only', (t) => {
'myorg:myteam',
'@scoped/another',
], (err) => {
- t.ifError(err, 'npm access')
+ t.error(err, 'npm access')
t.ok('should successfully access grant read-only')
})
})
-test('access grant read-write', (t) => {
+t.test('access grant read-write', (t) => {
t.plan(5)
- const Access = requireInject('../../lib/access.js', {
+ const Access = t.mock('../../lib/access.js', {
libnpmaccess: {
grant: (spec, team, permissions) => {
t.equal(spec, '@scoped/another', 'should use expected spec')
@@ -286,19 +285,19 @@ test('access grant read-write', (t) => {
'myorg:myteam',
'@scoped/another',
], (err) => {
- t.ifError(err, 'npm access')
+ t.error(err, 'npm access')
t.ok('should successfully access grant read-write')
})
})
-test('access grant current cwd', (t) => {
+t.test('access grant current cwd', (t) => {
t.plan(5)
const prefix = t.testdir({
'package.json': JSON.stringify({
name: 'yargs',
}),
})
- const Access = requireInject('../../lib/access.js', {
+ const Access = t.mock('../../lib/access.js', {
libnpmaccess: {
grant: (spec, team, permissions) => {
t.equal(spec, 'yargs', 'should use expected spec')
@@ -314,12 +313,12 @@ test('access grant current cwd', (t) => {
'read-write',
'myorg:myteam',
], (err) => {
- t.ifError(err, 'npm access')
+ t.error(err, 'npm access')
t.ok('should successfully access grant current cwd')
})
})
-test('access grant others', (t) => {
+t.test('access grant others', (t) => {
const access = new Access({ flatOptions: {} })
access.exec([
'grant',
@@ -336,7 +335,7 @@ test('access grant others', (t) => {
})
})
-test('access grant missing team args', (t) => {
+t.test('access grant missing team args', (t) => {
const access = new Access({ flatOptions: {} })
access.exec([
'grant',
@@ -353,7 +352,7 @@ test('access grant missing team args', (t) => {
})
})
-test('access grant malformed team arg', (t) => {
+t.test('access grant malformed team arg', (t) => {
const access = new Access({ flatOptions: {} })
access.exec([
'grant',
@@ -370,9 +369,9 @@ test('access grant malformed team arg', (t) => {
})
})
-test('access 2fa-required/2fa-not-required', t => {
+t.test('access 2fa-required/2fa-not-required', t => {
t.plan(2)
- const Access = requireInject('../../lib/access.js', {
+ const Access = t.mock('../../lib/access.js', {
libnpmaccess: {
tfaRequired: (spec) => {
t.equal(spec, '@scope/pkg', 'should use expected spec')
@@ -397,9 +396,9 @@ test('access 2fa-required/2fa-not-required', t => {
})
})
-test('access revoke', (t) => {
+t.test('access revoke', (t) => {
t.plan(4)
- const Access = requireInject('../../lib/access.js', {
+ const Access = t.mock('../../lib/access.js', {
libnpmaccess: {
revoke: (spec, team) => {
t.equal(spec, '@scoped/another', 'should use expected spec')
@@ -414,12 +413,12 @@ test('access revoke', (t) => {
'myorg:myteam',
'@scoped/another',
], (err) => {
- t.ifError(err, 'npm access')
+ t.error(err, 'npm access')
t.ok('should successfully access revoke')
})
})
-test('access revoke missing team args', (t) => {
+t.test('access revoke missing team args', (t) => {
const access = new Access({ flatOptions: {} })
access.exec([
'revoke',
@@ -435,7 +434,7 @@ test('access revoke missing team args', (t) => {
})
})
-test('access revoke malformed team arg', (t) => {
+t.test('access revoke malformed team arg', (t) => {
const access = new Access({ flatOptions: {} })
access.exec([
'revoke',
@@ -451,9 +450,9 @@ test('access revoke malformed team arg', (t) => {
})
})
-test('npm access ls-packages with no team', (t) => {
+t.test('npm access ls-packages with no team', (t) => {
t.plan(3)
- const Access = requireInject('../../lib/access.js', {
+ const Access = t.mock('../../lib/access.js', {
libnpmaccess: {
lsPackages: (entity) => {
t.equal(entity, 'foo', 'should use expected entity')
@@ -466,14 +465,14 @@ test('npm access ls-packages with no team', (t) => {
access.exec([
'ls-packages',
], (err) => {
- t.ifError(err, 'npm access')
+ t.error(err, 'npm access')
t.ok('should successfully access ls-packages with no team')
})
})
-test('access ls-packages on team', (t) => {
+t.test('access ls-packages on team', (t) => {
t.plan(3)
- const Access = requireInject('../../lib/access.js', {
+ const Access = t.mock('../../lib/access.js', {
libnpmaccess: {
lsPackages: (entity) => {
t.equal(entity, 'myorg:myteam', 'should use expected entity')
@@ -486,19 +485,19 @@ test('access ls-packages on team', (t) => {
'ls-packages',
'myorg:myteam',
], (err) => {
- t.ifError(err, 'npm access')
+ t.error(err, 'npm access')
t.ok('should successfully access ls-packages on team')
})
})
-test('access ls-collaborators on current', (t) => {
+t.test('access ls-collaborators on current', (t) => {
t.plan(3)
const prefix = t.testdir({
'package.json': JSON.stringify({
name: 'yargs',
}),
})
- const Access = requireInject('../../lib/access.js', {
+ const Access = t.mock('../../lib/access.js', {
libnpmaccess: {
lsCollaborators: (spec) => {
t.equal(spec, 'yargs', 'should use expected spec')
@@ -510,14 +509,14 @@ test('access ls-collaborators on current', (t) => {
access.exec([
'ls-collaborators',
], (err) => {
- t.ifError(err, 'npm access')
+ t.error(err, 'npm access')
t.ok('should successfully access ls-collaborators on current')
})
})
-test('access ls-collaborators on spec', (t) => {
+t.test('access ls-collaborators on spec', (t) => {
t.plan(3)
- const Access = requireInject('../../lib/access.js', {
+ const Access = t.mock('../../lib/access.js', {
libnpmaccess: {
lsCollaborators: (spec) => {
t.equal(spec, 'yargs', 'should use expected spec')
@@ -530,7 +529,7 @@ test('access ls-collaborators on spec', (t) => {
'ls-collaborators',
'yargs',
], (err) => {
- t.ifError(err, 'npm access')
+ t.error(err, 'npm access')
t.ok('should successfully access ls-packages with no team')
})
})
diff --git a/test/lib/adduser.js b/test/lib/adduser.js
index d9106e1bd..5ce61e127 100644
--- a/test/lib/adduser.js
+++ b/test/lib/adduser.js
@@ -1,5 +1,4 @@
-const requireInject = require('require-inject')
-const { test } = require('tap')
+const t = require('tap')
const { getCredentialsByURI, setCredentialsByURI } =
require('@npmcli/config').prototype
@@ -66,7 +65,7 @@ const npm = {
},
}
-const AddUser = requireInject('../../lib/adduser.js', {
+const AddUser = t.mock('../../lib/adduser.js', {
npmlog: {
disableProgress: () => null,
notice: (_, msg) => {
@@ -78,13 +77,13 @@ const AddUser = requireInject('../../lib/adduser.js', {
const adduser = new AddUser(npm)
-test('usage', (t) => {
+t.test('usage', (t) => {
t.match(adduser.usage, 'adduser', 'usage has command name in it')
t.end()
})
-test('simple login', (t) => {
+t.test('simple login', (t) => {
adduser.exec([], (err) => {
- t.ifError(err, 'npm adduser')
+ t.error(err, 'npm adduser')
t.equal(
registryOutput,
@@ -92,7 +91,7 @@ test('simple login', (t) => {
'should have correct message result'
)
- t.deepEqual(
+ t.same(
deletedConfig,
{
_token: 'user',
@@ -108,7 +107,7 @@ test('simple login', (t) => {
'should delete token in user config'
)
- t.deepEqual(
+ t.same(
setConfig,
{
'//registry.npmjs.org/:_password': { value: 'cA==', where: 'user' },
@@ -133,7 +132,7 @@ test('simple login', (t) => {
})
})
-test('bad auth type', (t) => {
+t.test('bad auth type', (t) => {
_flatOptions.authType = 'foo'
adduser.exec([], (err) => {
@@ -151,13 +150,13 @@ test('bad auth type', (t) => {
})
})
-test('scoped login', (t) => {
+t.test('scoped login', (t) => {
_flatOptions.scope = '@myscope'
adduser.exec([], (err) => {
- t.ifError(err, 'npm adduser')
+ t.error(err, 'npm adduser')
- t.deepEqual(
+ t.same(
setConfig['@myscope:registry'],
{ value: 'https://registry.npmjs.org/', where: 'user' },
'should set scoped registry config'
@@ -171,14 +170,14 @@ test('scoped login', (t) => {
})
})
-test('scoped login with valid scoped registry config', (t) => {
+t.test('scoped login with valid scoped registry config', (t) => {
_flatOptions['@myscope:registry'] = 'https://diff-registry.npmjs.com/'
_flatOptions.scope = '@myscope'
adduser.exec([], (err) => {
- t.ifError(err, 'npm adduser')
+ t.error(err, 'npm adduser')
- t.deepEqual(
+ t.same(
setConfig['@myscope:registry'],
{ value: 'https://diff-registry.npmjs.com/', where: 'user' },
'should keep scoped registry config'
@@ -193,7 +192,7 @@ test('scoped login with valid scoped registry config', (t) => {
})
})
-test('save config failure', (t) => {
+t.test('save config failure', (t) => {
failSave = true
adduser.exec([], (err) => {
diff --git a/test/lib/audit.js b/test/lib/audit.js
index a25e6b0e2..bb6f06deb 100644
--- a/test/lib/audit.js
+++ b/test/lib/audit.js
@@ -1,5 +1,4 @@
const t = require('tap')
-const requireInject = require('require-inject')
const mockNpm = require('../fixtures/mock-npm')
t.test('should audit using Arborist', t => {
@@ -19,7 +18,7 @@ t.test('should audit using Arborist', t => {
OUTPUT_CALLED = true
},
})
- const Audit = requireInject('../../lib/audit.js', {
+ const Audit = t.mock('../../lib/audit.js', {
'npm-audit-report': () => {
AUDIT_REPORT_CALLED = true
return {
@@ -74,7 +73,7 @@ t.test('should audit - json', t => {
output: () => {},
})
- const Audit = requireInject('../../lib/audit.js', {
+ const Audit = t.mock('../../lib/audit.js', {
'npm-audit-report': () => ({
report: 'there are vulnerabilities',
exitCode: 0,
@@ -115,7 +114,7 @@ t.test('report endpoint error', t => {
OUTPUT.push(msg)
},
})
- const Audit = requireInject('../../lib/audit.js', {
+ const Audit = t.mock('../../lib/audit.js', {
'npm-audit-report': () => {
throw new Error('should not call audit report when there are errors')
},
diff --git a/test/lib/auth/legacy.js b/test/lib/auth/legacy.js
index f5297c581..d06f95357 100644
--- a/test/lib/auth/legacy.js
+++ b/test/lib/auth/legacy.js
@@ -1,12 +1,11 @@
-const requireInject = require('require-inject')
-const { test } = require('tap')
+const t = require('tap')
let log = ''
const token = '24528a24f240'
const profile = {}
const read = {}
-const legacy = requireInject('../../../lib/auth/legacy.js', {
+const legacy = t.mock('../../../lib/auth/legacy.js', {
npmlog: {
info: (...msgs) => {
log += msgs.join(' ')
@@ -26,7 +25,7 @@ const npm = {
},
}
-test('login using username/password with token result', async (t) => {
+t.test('login using username/password with token result', async (t) => {
profile.login = () => {
return { token }
}
@@ -57,7 +56,7 @@ test('login using username/password with token result', async (t) => {
'should have correct message result'
)
- t.deepEqual(
+ t.same(
newCreds,
{ token },
'should return expected obj from profile.login'
@@ -67,7 +66,7 @@ test('login using username/password with token result', async (t) => {
delete profile.login
})
-test('login using username/password with user info result', async (t) => {
+t.test('login using username/password with user info result', async (t) => {
profile.login = () => {
return null
}
@@ -92,7 +91,7 @@ test('login using username/password with user info result', async (t) => {
'should have correct message result'
)
- t.deepEqual(
+ t.same(
newCreds,
{
username: 'u',
@@ -107,7 +106,7 @@ test('login using username/password with user info result', async (t) => {
delete profile.login
})
-test('login otp requested', async (t) => {
+t.test('login otp requested', async (t) => {
t.plan(5)
profile.login = () => Promise.reject(Object.assign(
@@ -143,7 +142,7 @@ test('login otp requested', async (t) => {
'should have correct message result'
)
- t.deepEqual(
+ t.same(
newCreds,
{ token },
'should return token from loginCouch result'
@@ -155,7 +154,7 @@ test('login otp requested', async (t) => {
delete read.otp
})
-test('login missing basic credential info', async (t) => {
+t.test('login missing basic credential info', async (t) => {
profile.login = () => Promise.reject(Object.assign(
new Error('missing info'),
{ code: 'ERROR' }
@@ -178,7 +177,7 @@ test('login missing basic credential info', async (t) => {
delete profile.login
})
-test('create new user when user not found', async (t) => {
+t.test('create new user when user not found', async (t) => {
t.plan(6)
profile.login = () => Promise.reject(Object.assign(
@@ -219,7 +218,7 @@ test('create new user when user not found', async (t) => {
'should have correct message result'
)
- t.deepEqual(
+ t.same(
newCreds,
{ token },
'should return expected obj from profile.login'
@@ -230,7 +229,7 @@ test('create new user when user not found', async (t) => {
delete profile.login
})
-test('prompts for user info if required', async (t) => {
+t.test('prompts for user info if required', async (t) => {
t.plan(4)
profile.login = async (opener, prompt, opts) => {
@@ -266,7 +265,7 @@ test('prompts for user info if required', async (t) => {
'should have correct message result'
)
- t.deepEqual(
+ t.same(
newCreds,
{
username: 'foo',
@@ -284,7 +283,7 @@ test('prompts for user info if required', async (t) => {
delete read.email
})
-test('request otp when creating new user', async (t) => {
+t.test('request otp when creating new user', async (t) => {
t.plan(3)
profile.login = () => Promise.reject(Object.assign(
@@ -322,7 +321,7 @@ test('request otp when creating new user', async (t) => {
delete read.otp
})
-test('unknown error during user creation', async (t) => {
+t.test('unknown error during user creation', async (t) => {
profile.login = () => Promise.reject(Object.assign(
new Error('missing info'),
{ code: 'ERROR' }
@@ -352,7 +351,7 @@ test('unknown error during user creation', async (t) => {
delete profile.login
})
-test('open url error', async (t) => {
+t.test('open url error', async (t) => {
profile.login = async (opener, prompt, opts) => {
await opener()
}
@@ -374,7 +373,7 @@ test('open url error', async (t) => {
delete profile.login
})
-test('login no credentials provided', async (t) => {
+t.test('login no credentials provided', async (t) => {
profile.login = () => ({ token })
await legacy(npm, {
@@ -398,7 +397,7 @@ test('login no credentials provided', async (t) => {
delete profile.login
})
-test('scoped login', async (t) => {
+t.test('scoped login', async (t) => {
profile.login = () => ({ token })
const { message } = await legacy(npm, {
diff --git a/test/lib/auth/oauth.js b/test/lib/auth/oauth.js
index c2f4c3443..0c317fb9a 100644
--- a/test/lib/auth/oauth.js
+++ b/test/lib/auth/oauth.js
@@ -1,7 +1,6 @@
-const requireInject = require('require-inject')
-const { test } = require('tap')
+const t = require('tap')
-test('oauth login', (t) => {
+t.test('oauth login', (t) => {
t.plan(3)
const oauthOpts = {
creds: {},
@@ -17,7 +16,7 @@ test('oauth login', (t) => {
},
},
}
- const oauth = requireInject('../../../lib/auth/oauth.js', {
+ const oauth = t.mock('../../../lib/auth/oauth.js', {
'../../../lib/auth/sso.js': (npm, opts) => {
t.equal(opts, oauthOpts, 'should forward opts')
},
diff --git a/test/lib/auth/saml.js b/test/lib/auth/saml.js
index b8c21f649..1558e0db8 100644
--- a/test/lib/auth/saml.js
+++ b/test/lib/auth/saml.js
@@ -1,7 +1,6 @@
-const requireInject = require('require-inject')
-const { test } = require('tap')
+const t = require('tap')
-test('saml login', (t) => {
+t.test('saml login', (t) => {
t.plan(3)
const samlOpts = {
creds: {},
@@ -17,7 +16,7 @@ test('saml login', (t) => {
},
},
}
- const saml = requireInject('../../../lib/auth/saml.js', {
+ const saml = t.mock('../../../lib/auth/saml.js', {
'../../../lib/auth/sso.js': (npm, opts) => {
t.equal(opts, samlOpts, 'should forward opts')
},
diff --git a/test/lib/auth/sso.js b/test/lib/auth/sso.js
index 6f3d981a6..11be002ae 100644
--- a/test/lib/auth/sso.js
+++ b/test/lib/auth/sso.js
@@ -1,5 +1,4 @@
-const requireInject = require('require-inject')
-const { test } = require('tap')
+const t = require('tap')
let log = ''
let warn = ''
@@ -11,7 +10,7 @@ const token = '24528a24f240'
const SSO_URL = 'https://registry.npmjs.org/{SSO_URL}'
const profile = {}
const npmFetch = {}
-const sso = requireInject('../../../lib/auth/sso.js', {
+const sso = t.mock('../../../lib/auth/sso.js', {
npmlog: {
info: (...msgs) => {
log += msgs.join(' ') + '\n'
@@ -46,7 +45,7 @@ const npm = {
flatOptions: _flatOptions,
}
-test('empty login', async (t) => {
+t.test('empty login', async (t) => {
_flatOptions.ssoType = false
await t.rejects(
@@ -66,13 +65,13 @@ test('empty login', async (t) => {
warn = ''
})
-test('simple login', async (t) => {
+t.test('simple login', async (t) => {
t.plan(6)
profile.loginCouch = (username, password, opts) => {
t.equal(username, 'npm_oauth_auth_dummy_user', 'should use dummy user')
t.equal(password, 'placeholder', 'should use dummy password')
- t.deepEqual(
+ t.same(
opts,
{
creds: {},
@@ -109,7 +108,7 @@ test('simple login', async (t) => {
'should have correct logged info msg'
)
- t.deepEqual(
+ t.same(
newCreds,
{ token },
'should return expected resulting credentials'
@@ -121,7 +120,7 @@ test('simple login', async (t) => {
delete npmFetch.json
})
-test('polling retry', async (t) => {
+t.test('polling retry', async (t) => {
t.plan(3)
profile.loginCouch = () => ({ token, sso: SSO_URL })
@@ -168,7 +167,7 @@ test('polling retry', async (t) => {
delete npmFetch.json
})
-test('polling error', async (t) => {
+t.test('polling error', async (t) => {
profile.loginCouch = () => ({ token, sso: SSO_URL })
npmFetch.json = () => Promise.reject(Object.assign(
new Error('unknown error'),
@@ -191,7 +190,7 @@ test('polling error', async (t) => {
delete npmFetch.json
})
-test('no token retrieved from loginCouch', async (t) => {
+t.test('no token retrieved from loginCouch', async (t) => {
profile.loginCouch = () => ({})
await t.rejects(
@@ -209,7 +208,7 @@ test('no token retrieved from loginCouch', async (t) => {
delete profile.loginCouch
})
-test('no sso url retrieved from loginCouch', async (t) => {
+t.test('no sso url retrieved from loginCouch', async (t) => {
profile.loginCouch = () => Promise.resolve({ token })
await t.rejects(
@@ -227,7 +226,7 @@ test('no sso url retrieved from loginCouch', async (t) => {
delete profile.loginCouch
})
-test('scoped login', async (t) => {
+t.test('scoped login', async (t) => {
profile.loginCouch = () => ({ token, sso: SSO_URL })
npmFetch.json = () => Promise.resolve({ username: 'foo' })
@@ -252,7 +251,7 @@ test('scoped login', async (t) => {
'should have correct logged info msg'
)
- t.deepEqual(
+ t.same(
newCreds,
{ token },
'should return expected resulting credentials'
diff --git a/test/lib/bin.js b/test/lib/bin.js
index 1d9341169..898e7ba43 100644
--- a/test/lib/bin.js
+++ b/test/lib/bin.js
@@ -1,8 +1,7 @@
-const { test } = require('tap')
-const requireInject = require('require-inject')
+const t = require('tap')
const mockNpm = require('../fixtures/mock-npm')
-test('bin', (t) => {
+t.test('bin', (t) => {
t.plan(4)
const dir = '/bin/dir'
@@ -19,15 +18,15 @@ test('bin', (t) => {
t.match(bin.usage, 'bin', 'usage has command name in it')
bin.exec([], (err) => {
- t.ifError(err, 'npm bin')
+ t.error(err, 'npm bin')
t.ok('should have printed directory')
})
})
-test('bin -g', (t) => {
+t.test('bin -g', (t) => {
t.plan(3)
const consoleError = console.error
- t.tearDown(() => {
+ t.teardown(() => {
console.error = consoleError
})
@@ -36,7 +35,7 @@ test('bin -g', (t) => {
}
const dir = '/bin/dir'
- const Bin = requireInject('../../lib/bin.js', {
+ const Bin = t.mock('../../lib/bin.js', {
'../../lib/utils/path.js': [dir],
})
@@ -50,15 +49,15 @@ test('bin -g', (t) => {
const bin = new Bin(npm)
bin.exec([], (err) => {
- t.ifError(err, 'npm bin')
+ t.error(err, 'npm bin')
t.ok('should have printed directory')
})
})
-test('bin -g (not in path)', (t) => {
+t.test('bin -g (not in path)', (t) => {
t.plan(4)
const consoleError = console.error
- t.tearDown(() => {
+ t.teardown(() => {
console.error = consoleError
})
@@ -67,7 +66,7 @@ test('bin -g (not in path)', (t) => {
}
const dir = '/bin/dir'
- const Bin = requireInject('../../lib/bin.js', {
+ const Bin = t.mock('../../lib/bin.js', {
'../../lib/utils/path.js': ['/not/my/dir'],
})
const npm = mockNpm({
@@ -80,7 +79,7 @@ test('bin -g (not in path)', (t) => {
const bin = new Bin(npm)
bin.exec([], (err) => {
- t.ifError(err, 'npm bin')
+ t.error(err, 'npm bin')
t.ok('should have printed directory')
})
})
diff --git a/test/lib/bugs.js b/test/lib/bugs.js
index 21b1a9841..1cc6e06ee 100644
--- a/test/lib/bugs.js
+++ b/test/lib/bugs.js
@@ -1,6 +1,5 @@
const t = require('tap')
-const requireInject = require('require-inject')
const pacote = {
manifest: async (spec, options) => {
return spec === 'nobugs' ? {
@@ -48,7 +47,7 @@ const openUrl = async (npm, url, errMsg) => {
opened[url]++
}
-const Bugs = requireInject('../../lib/bugs.js', {
+const Bugs = t.mock('../../lib/bugs.js', {
pacote,
'../../lib/utils/open-url.js': openUrl,
})
diff --git a/test/lib/cache.js b/test/lib/cache.js
index 0fdf76856..bbebae889 100644
--- a/test/lib/cache.js
+++ b/test/lib/cache.js
@@ -1,5 +1,4 @@
const t = require('tap')
-const requireInject = require('require-inject')
const mockNpm = require('../fixtures/mock-npm')
const path = require('path')
@@ -47,7 +46,7 @@ const cacache = {
},
}
-const Cache = requireInject('../../lib/cache.js', {
+const Cache = t.mock('../../lib/cache.js', {
cacache,
npmlog,
pacote,
@@ -89,7 +88,7 @@ t.test('cache clean (force)', t => {
})
cache.exec(['clear'], err => {
- t.ifError(err)
+ t.error(err)
t.equal(rimrafPath, path.join(npm.cache, '_cacache'))
t.end()
})
@@ -124,7 +123,7 @@ t.test('cache add pkg only', t => {
})
cache.exec(['add', 'mypkg'], err => {
- t.ifError(err)
+ t.error(err)
t.strictSame(logOutput, [
['silly', 'cache add', 'args', ['mypkg']],
['silly', 'cache add', 'spec', 'mypkg'],
@@ -143,7 +142,7 @@ t.test('cache add pkg w/ spec modifier', t => {
})
cache.exec(['add', 'mypkg', 'latest'], err => {
- t.ifError(err)
+ t.error(err)
t.strictSame(logOutput, [
['silly', 'cache add', 'args', ['mypkg', 'latest']],
['silly', 'cache add', 'spec', 'mypkg@latest'],
@@ -160,7 +159,7 @@ t.test('cache verify', t => {
})
cache.exec(['verify'], err => {
- t.ifError(err)
+ t.error(err)
t.match(outputOutput, [
`Cache verified and compressed (${path.join(npm.cache, '_cacache')})`,
'Content verified: 1 (100 bytes)',
@@ -187,7 +186,7 @@ t.test('cache verify w/ extra output', t => {
})
cache.exec(['check'], err => {
- t.ifError(err)
+ t.error(err)
t.match(outputOutput, [
`Cache verified and compressed (~${path.join('/fake/path', '_cacache')})`,
'Content verified: 1 (100 bytes)',
diff --git a/test/lib/ci.js b/test/lib/ci.js
index 7f06a6ceb..b60375c28 100644
--- a/test/lib/ci.js
+++ b/test/lib/ci.js
@@ -2,15 +2,14 @@ const fs = require('fs')
const util = require('util')
const readdir = util.promisify(fs.readdir)
-const { test } = require('tap')
+const t = require('tap')
-const requireInject = require('require-inject')
const mockNpm = require('../fixtures/mock-npm')
-test('should ignore scripts with --ignore-scripts', (t) => {
+t.test('should ignore scripts with --ignore-scripts', (t) => {
const SCRIPTS = []
let REIFY_CALLED = false
- const CI = requireInject('../../lib/ci.js', {
+ const CI = t.mock('../../lib/ci.js', {
'../../lib/utils/reify-finish.js': async () => {},
'@npmcli/run-script': ({ event }) => {
SCRIPTS.push(event)
@@ -42,7 +41,7 @@ test('should ignore scripts with --ignore-scripts', (t) => {
})
})
-test('should use Arborist and run-script', (t) => {
+t.test('should use Arborist and run-script', (t) => {
const scripts = [
'preinstall',
'install',
@@ -88,7 +87,7 @@ test('should use Arborist and run-script', (t) => {
const expectRimrafs = 3
let actualRimrafs = 0
- const CI = requireInject('../../lib/ci.js', {
+ const CI = t.mock('../../lib/ci.js', {
'../../lib/utils/reify-finish.js': async () => {},
'@npmcli/run-script': opts => {
t.match(opts, { event: scripts.shift() })
@@ -134,8 +133,8 @@ test('should use Arborist and run-script', (t) => {
})
})
-test('should pass flatOptions to Arborist.reify', (t) => {
- const CI = requireInject('../../lib/ci.js', {
+t.test('should pass flatOptions to Arborist.reify', (t) => {
+ const CI = t.mock('../../lib/ci.js', {
'../../lib/utils/reify-finish.js': async () => {},
'@npmcli/run-script': opts => {},
'@npmcli/arborist': function () {
@@ -159,13 +158,13 @@ test('should pass flatOptions to Arborist.reify', (t) => {
})
})
-test('should throw if package-lock.json or npm-shrinkwrap missing', (t) => {
+t.test('should throw if package-lock.json or npm-shrinkwrap missing', (t) => {
const testDir = t.testdir({
'index.js': 'some contents',
'package.json': 'some info',
})
- const CI = requireInject('../../lib/ci.js', {
+ const CI = t.mock('../../lib/ci.js', {
'@npmcli/run-script': opts => {},
'../../lib/utils/reify-finish.js': async () => {},
npmlog: {
@@ -188,8 +187,8 @@ test('should throw if package-lock.json or npm-shrinkwrap missing', (t) => {
})
})
-test('should throw ECIGLOBAL', (t) => {
- const CI = requireInject('../../lib/ci.js', {
+t.test('should throw ECIGLOBAL', (t) => {
+ const CI = t.mock('../../lib/ci.js', {
'@npmcli/run-script': opts => {},
'../../lib/utils/reify-finish.js': async () => {},
})
@@ -201,20 +200,20 @@ test('should throw ECIGLOBAL', (t) => {
})
const ci = new CI(npm)
ci.exec(null, (err, res) => {
- t.equals(err.code, 'ECIGLOBAL', 'throws error with global packages')
+ t.equal(err.code, 'ECIGLOBAL', 'throws error with global packages')
t.notOk(res)
t.end()
})
})
-test('should remove existing node_modules before installing', (t) => {
+t.test('should remove existing node_modules before installing', (t) => {
const testDir = t.testdir({
node_modules: {
'some-file': 'some contents',
},
})
- const CI = requireInject('../../lib/ci.js', {
+ const CI = t.mock('../../lib/ci.js', {
'@npmcli/run-script': opts => {},
'../../lib/utils/reify-finish.js': async () => {},
'@npmcli/arborist': function () {
diff --git a/test/lib/cli.js b/test/lib/cli.js
index 28e44394e..f491c6174 100644
--- a/test/lib/cli.js
+++ b/test/lib/cli.js
@@ -43,8 +43,7 @@ const npmlogMock = {
info: (...msg) => logs.push(['info', ...msg]),
}
-const requireInject = require('require-inject')
-const cli = requireInject.installGlobally('../../lib/cli.js', {
+const cli = t.mock('../../lib/cli.js', {
'../../lib/npm.js': npmock,
'../../lib/utils/did-you-mean.js': () => '\ntest did you mean',
'../../lib/utils/unsupported.js': unsupportedMock,
diff --git a/test/lib/completion.js b/test/lib/completion.js
index c6ef901a7..4f7d4a5fd 100644
--- a/test/lib/completion.js
+++ b/test/lib/completion.js
@@ -1,5 +1,4 @@
-const { test } = require('tap')
-const requireInject = require('require-inject')
+const t = require('tap')
const fs = require('fs')
const path = require('path')
@@ -81,7 +80,7 @@ const deref = (cmd) => {
return cmd
}
-const Completion = requireInject('../../lib/completion.js', {
+const Completion = t.mock('../../lib/completion.js', {
'../../lib/utils/cmd-list.js': cmdList,
'../../lib/utils/config/index.js': config,
'../../lib/utils/deref-command.js': deref,
@@ -89,7 +88,7 @@ const Completion = requireInject('../../lib/completion.js', {
})
const completion = new Completion(npm)
-test('completion completion', async t => {
+t.test('completion completion', async t => {
const home = process.env.HOME
t.teardown(() => {
process.env.HOME = home
@@ -108,7 +107,7 @@ test('completion completion', async t => {
t.end()
})
-test('completion completion no known shells', async t => {
+t.test('completion completion no known shells', async t => {
const home = process.env.HOME
t.teardown(() => {
process.env.HOME = home
@@ -121,14 +120,14 @@ test('completion completion no known shells', async t => {
t.end()
})
-test('completion completion wrong word count', async t => {
+t.test('completion completion wrong word count', async t => {
const res = await completion.completion({ w: 3 })
t.strictSame(res, undefined, 'no responses')
t.end()
})
-test('completion errors in windows without bash', t => {
- const Compl = requireInject('../../lib/completion.js', {
+t.test('completion errors in windows without bash', t => {
+ const Compl = t.mock('../../lib/completion.js', {
'../../lib/utils/is-windows-shell.js': true,
})
@@ -143,7 +142,7 @@ test('completion errors in windows without bash', t => {
})
})
-test('dump script when completion is not being attempted', t => {
+t.test('dump script when completion is not being attempted', t => {
const _write = process.stdout.write
const _on = process.stdout.on
t.teardown(() => {
@@ -176,7 +175,7 @@ test('dump script when completion is not being attempted', t => {
})
})
-test('dump script exits correctly when EPIPE is emitted on stdout', t => {
+t.test('dump script exits correctly when EPIPE is emitted on stdout', t => {
const _write = process.stdout.write
const _on = process.stdout.on
t.teardown(() => {
@@ -209,7 +208,7 @@ test('dump script exits correctly when EPIPE is emitted on stdout', t => {
})
})
-test('non EPIPE errors cause failures', t => {
+t.test('non EPIPE errors cause failures', t => {
const _write = process.stdout.write
const _on = process.stdout.on
t.teardown(() => {
@@ -240,7 +239,7 @@ test('non EPIPE errors cause failures', t => {
})
})
-test('completion completes single command name', t => {
+t.test('completion completes single command name', t => {
process.env.COMP_CWORD = 1
process.env.COMP_LINE = 'npm c'
process.env.COMP_POINT = process.env.COMP_LINE.length
@@ -262,7 +261,7 @@ test('completion completes single command name', t => {
})
})
-test('completion completes command names', t => {
+t.test('completion completes command names', t => {
process.env.COMP_CWORD = 1
process.env.COMP_LINE = 'npm a'
process.env.COMP_POINT = process.env.COMP_LINE.length
@@ -284,7 +283,7 @@ test('completion completes command names', t => {
})
})
-test('completion of invalid command name does nothing', t => {
+t.test('completion of invalid command name does nothing', t => {
process.env.COMP_CWORD = 1
process.env.COMP_LINE = 'npm compute'
process.env.COMP_POINT = process.env.COMP_LINE.length
@@ -306,7 +305,7 @@ test('completion of invalid command name does nothing', t => {
})
})
-test('handles async completion function', t => {
+t.test('handles async completion function', t => {
process.env.COMP_CWORD = 2
process.env.COMP_LINE = 'npm promise'
process.env.COMP_POINT = process.env.COMP_LINE.length
@@ -335,7 +334,7 @@ test('handles async completion function', t => {
})
})
-test('completion triggers command completions', t => {
+t.test('completion triggers command completions', t => {
process.env.COMP_CWORD = 2
process.env.COMP_LINE = 'npm access '
process.env.COMP_POINT = process.env.COMP_LINE.length
@@ -364,7 +363,7 @@ test('completion triggers command completions', t => {
})
})
-test('completion triggers filtered command completions', t => {
+t.test('completion triggers filtered command completions', t => {
process.env.COMP_CWORD = 2
process.env.COMP_LINE = 'npm access p'
process.env.COMP_POINT = process.env.COMP_LINE.length
@@ -393,7 +392,7 @@ test('completion triggers filtered command completions', t => {
})
})
-test('completions for commands that return nested arrays are joined', t => {
+t.test('completions for commands that return nested arrays are joined', t => {
process.env.COMP_CWORD = 2
process.env.COMP_LINE = 'npm completion '
process.env.COMP_POINT = process.env.COMP_LINE.length
@@ -422,7 +421,7 @@ test('completions for commands that return nested arrays are joined', t => {
})
})
-test('completions for commands that return nothing work correctly', t => {
+t.test('completions for commands that return nothing work correctly', t => {
process.env.COMP_CWORD = 2
process.env.COMP_LINE = 'npm donothing '
process.env.COMP_POINT = process.env.COMP_LINE.length
@@ -451,7 +450,7 @@ test('completions for commands that return nothing work correctly', t => {
})
})
-test('completions for commands that return a single item work correctly', t => {
+t.test('completions for commands that return a single item work correctly', t => {
process.env.COMP_CWORD = 2
process.env.COMP_LINE = 'npm driveaboat '
process.env.COMP_POINT = process.env.COMP_LINE.length
@@ -480,7 +479,7 @@ test('completions for commands that return a single item work correctly', t => {
})
})
-test('command completion for commands with no completion return no results', t => {
+t.test('command completion for commands with no completion return no results', t => {
process.env.COMP_CWORD = 2
process.env.COMP_LINE = 'npm adduser '
process.env.COMP_POINT = process.env.COMP_LINE.length
@@ -510,7 +509,7 @@ test('command completion for commands with no completion return no results', t =
})
})
-test('command completion errors propagate', t => {
+t.test('command completion errors propagate', t => {
process.env.COMP_CWORD = 2
process.env.COMP_LINE = 'npm access '
process.env.COMP_POINT = process.env.COMP_LINE.length
@@ -539,7 +538,7 @@ test('command completion errors propagate', t => {
})
})
-test('completion can complete flags', t => {
+t.test('completion can complete flags', t => {
process.env.COMP_CWORD = 2
process.env.COMP_LINE = 'npm install --'
process.env.COMP_POINT = process.env.COMP_LINE.length
@@ -562,7 +561,7 @@ test('completion can complete flags', t => {
})
})
-test('double dashes escape from flag completion', t => {
+t.test('double dashes escape from flag completion', t => {
process.env.COMP_CWORD = 2
process.env.COMP_LINE = 'npm -- install --'
process.env.COMP_POINT = process.env.COMP_LINE.length
@@ -585,7 +584,7 @@ test('double dashes escape from flag completion', t => {
})
})
-test('completion cannot complete options that take a value in mid-command', t => {
+t.test('completion cannot complete options that take a value in mid-command', t => {
process.env.COMP_CWORD = 2
process.env.COMP_LINE = 'npm --registry install'
process.env.COMP_POINT = process.env.COMP_LINE.length
diff --git a/test/lib/config.js b/test/lib/config.js
index 074db9765..155ad0bcf 100644
--- a/test/lib/config.js
+++ b/test/lib/config.js
@@ -1,6 +1,5 @@
const t = require('tap')
-const requireInject = require('require-inject')
const { EventEmitter } = require('events')
const redactCwd = (path) => {
@@ -84,7 +83,7 @@ const mocks = {
'../../lib/utils/usage.js': usageUtil,
}
-const Config = requireInject('../../lib/config.js', mocks)
+const Config = t.mock('../../lib/config.js', mocks)
const config = new Config(npm)
t.test('config no args', t => {
@@ -121,7 +120,7 @@ t.test('config list', t => {
})
config.exec(['list'], (err) => {
- t.ifError(err, 'npm config list')
+ t.error(err, 'npm config list')
t.matchSnapshot(result, 'should list configs')
})
})
@@ -147,7 +146,7 @@ t.test('config list overrides', t => {
})
config.exec(['list'], (err) => {
- t.ifError(err, 'npm config list')
+ t.error(err, 'npm config list')
t.matchSnapshot(result, 'should list overridden configs')
})
})
@@ -165,7 +164,7 @@ t.test('config list --long', t => {
})
config.exec(['list'], (err) => {
- t.ifError(err, 'npm config list --long')
+ t.error(err, 'npm config list --long')
t.matchSnapshot(result, 'should list all configs')
})
})
@@ -190,8 +189,8 @@ t.test('config list --json', t => {
})
config.exec(['list'], (err) => {
- t.ifError(err, 'npm config list --json')
- t.deepEqual(
+ t.error(err, 'npm config list --json')
+ t.same(
JSON.parse(result),
{
editor: 'vi',
@@ -224,7 +223,7 @@ t.test('config delete key', t => {
}
config.exec(['delete', 'foo'], (err) => {
- t.ifError(err, 'npm config delete key')
+ t.error(err, 'npm config delete key')
})
t.teardown(() => {
@@ -251,7 +250,7 @@ t.test('config delete multiple key', t => {
}
config.exec(['delete', 'foo', 'bar'], (err) => {
- t.ifError(err, 'npm config delete keys')
+ t.error(err, 'npm config delete keys')
})
t.teardown(() => {
@@ -274,7 +273,7 @@ t.test('config delete key --global', t => {
cliConfig.global = true
config.exec(['delete', 'foo'], (err) => {
- t.ifError(err, 'npm config delete key --global')
+ t.error(err, 'npm config delete key --global')
})
t.teardown(() => {
@@ -305,7 +304,7 @@ t.test('config set key', t => {
}
config.exec(['set', 'foo', 'bar'], (err) => {
- t.ifError(err, 'npm config set key')
+ t.error(err, 'npm config set key')
})
t.teardown(() => {
@@ -328,7 +327,7 @@ t.test('config set key=val', t => {
}
config.exec(['set', 'foo=bar'], (err) => {
- t.ifError(err, 'npm config set key')
+ t.error(err, 'npm config set key')
})
t.teardown(() => {
@@ -359,7 +358,7 @@ t.test('config set multiple keys', t => {
}
config.exec(['set', ...args], (err) => {
- t.ifError(err, 'npm config set key')
+ t.error(err, 'npm config set key')
})
t.teardown(() => {
@@ -382,7 +381,7 @@ t.test('config set key to empty value', t => {
}
config.exec(['set', 'foo'], (err) => {
- t.ifError(err, 'npm config set key to empty value')
+ t.error(err, 'npm config set key to empty value')
})
t.teardown(() => {
@@ -410,7 +409,7 @@ t.test('config set invalid key', t => {
})
config.exec(['set', 'foo', 'bar'], (err) => {
- t.ifError(err, 'npm config set invalid key')
+ t.error(err, 'npm config set invalid key')
})
})
@@ -429,7 +428,7 @@ t.test('config set key --global', t => {
cliConfig.global = true
config.exec(['set', 'foo', 'bar'], (err) => {
- t.ifError(err, 'npm config set key --global')
+ t.error(err, 'npm config set key --global')
})
t.teardown(() => {
@@ -450,7 +449,7 @@ t.test('config get no args', t => {
})
config.exec(['get'], (err) => {
- t.ifError(err, 'npm config get no args')
+ t.error(err, 'npm config get no args')
t.matchSnapshot(result, 'should list configs on config get no args')
})
})
@@ -469,7 +468,7 @@ t.test('config get key', t => {
}
config.exec(['get', 'foo'], (err) => {
- t.ifError(err, 'npm config get key')
+ t.error(err, 'npm config get key')
})
t.teardown(() => {
@@ -497,7 +496,7 @@ t.test('config get multiple keys', t => {
}
config.exec(['get', 'foo', 'bar'], (err) => {
- t.ifError(err, 'npm config get multiple keys')
+ t.error(err, 'npm config get multiple keys')
t.equal(result, 'foo=asdf\nbar=asdf')
})
@@ -555,20 +554,20 @@ sign-git-commit=true`
},
},
}
- const Config = requireInject('../../lib/config.js', editMocks)
+ const Config = t.mock('../../lib/config.js', editMocks)
const config = new Config(npm)
config.exec(['edit'], (err) => {
- t.ifError(err, 'npm config edit')
+ t.error(err, 'npm config edit')
// test no config file result
editMocks.fs.readFile = (p, e, cb) => {
cb(new Error('ERR'))
}
- const Config = requireInject('../../lib/config.js', editMocks)
+ const Config = t.mock('../../lib/config.js', editMocks)
const config = new Config(npm)
config.exec(['edit'], (err) => {
- t.ifError(err, 'npm config edit')
+ t.error(err, 'npm config edit')
})
})
@@ -614,7 +613,7 @@ t.test('config edit --global', t => {
},
},
}
- const Config = requireInject('../../lib/config.js', editMocks)
+ const Config = t.mock('../../lib/config.js', editMocks)
const config = new Config(npm)
config.exec(['edit'], (err) => {
t.match(err, /exited with code: 137/, 'propagated exit code from editor')
diff --git a/test/lib/dedupe.js b/test/lib/dedupe.js
index 851163f93..801e3c96d 100644
--- a/test/lib/dedupe.js
+++ b/test/lib/dedupe.js
@@ -1,9 +1,8 @@
-const { test } = require('tap')
-const requireInject = require('require-inject')
+const t = require('tap')
const mockNpm = require('../fixtures/mock-npm')
-test('should throw in global mode', (t) => {
- const Dedupe = requireInject('../../lib/dedupe.js')
+t.test('should throw in global mode', (t) => {
+ const Dedupe = t.mock('../../lib/dedupe.js')
const npm = mockNpm({
config: { 'dry-run': false, global: true },
})
@@ -15,8 +14,8 @@ test('should throw in global mode', (t) => {
})
})
-test('should remove dupes using Arborist', (t) => {
- const Dedupe = requireInject('../../lib/dedupe.js', {
+t.test('should remove dupes using Arborist', (t) => {
+ const Dedupe = t.mock('../../lib/dedupe.js', {
'@npmcli/arborist': function (args) {
t.ok(args, 'gets options object')
t.ok(args.path, 'gets path option')
@@ -44,8 +43,8 @@ test('should remove dupes using Arborist', (t) => {
})
})
-test('should remove dupes using Arborist - no arguments', (t) => {
- const Dedupe = requireInject('../../lib/dedupe.js', {
+t.test('should remove dupes using Arborist - no arguments', (t) => {
+ const Dedupe = t.mock('../../lib/dedupe.js', {
'@npmcli/arborist': function (args) {
t.ok(args.dryRun, 'gets dryRun from config')
this.dedupe = () => {}
diff --git a/test/lib/deprecate.js b/test/lib/deprecate.js
index e278a3e3c..c358fde24 100644
--- a/test/lib/deprecate.js
+++ b/test/lib/deprecate.js
@@ -1,5 +1,4 @@
-const { test } = require('tap')
-const requireInject = require('require-inject')
+const t = require('tap')
let getIdentityImpl = () => 'someperson'
let npmFetchBody = null
@@ -18,7 +17,7 @@ npmFetch.json = async (uri, opts) => {
}
}
-const Deprecate = requireInject('../../lib/deprecate.js', {
+const Deprecate = t.mock('../../lib/deprecate.js', {
'../../lib/utils/get-identity.js': async () => getIdentityImpl(),
'../../lib/utils/otplease.js': async (opts, fn) => fn(opts),
libnpmaccess: {
@@ -31,7 +30,7 @@ const deprecate = new Deprecate({
flatOptions: { registry: 'https://registry.npmjs.org' },
})
-test('completion', async t => {
+t.test('completion', async t => {
const defaultIdentityImpl = getIdentityImpl
t.teardown(() => {
getIdentityImpl = defaultIdentityImpl
@@ -58,28 +57,28 @@ test('completion', async t => {
t.rejects(testComp([], []), { message: 'deprecate test failure' })
})
-test('no args', t => {
+t.test('no args', t => {
deprecate.exec([], (err) => {
t.match(err, 'Usage:', 'logs usage')
t.end()
})
})
-test('only one arg', t => {
+t.test('only one arg', t => {
deprecate.exec(['foo'], (err) => {
t.match(err, 'Usage:', 'logs usage')
t.end()
})
})
-test('invalid semver range', t => {
+t.test('invalid semver range', t => {
deprecate.exec(['foo@notaversion', 'this will fail'], (err) => {
t.match(err, /invalid version range/, 'logs semver error')
t.end()
})
})
-test('deprecates given range', t => {
+t.test('deprecates given range', t => {
t.teardown(() => {
npmFetchBody = null
})
@@ -105,7 +104,7 @@ test('deprecates given range', t => {
})
})
-test('deprecates all versions when no range is specified', t => {
+t.test('deprecates all versions when no range is specified', t => {
t.teardown(() => {
npmFetchBody = null
})
diff --git a/test/lib/diff.js b/test/lib/diff.js
index 08761c64c..355095c95 100644
--- a/test/lib/diff.js
+++ b/test/lib/diff.js
@@ -1,6 +1,5 @@
const { resolve } = require('path')
const t = require('tap')
-const requireInject = require('require-inject')
const mockNpm = require('../fixtures/mock-npm')
const noop = () => null
@@ -38,7 +37,7 @@ const mocks = {
'../../lib/utils/usage.js': () => 'usage instructions',
}
-t.afterEach(cb => {
+t.afterEach(() => {
config.global = false
config.tag = 'latest'
config.diff = []
@@ -54,10 +53,9 @@ t.afterEach(cb => {
npm.prefix = '..'
libnpmdiff = noop
rlp = () => 'foo'
- cb()
})
-const Diff = requireInject('../../lib/diff.js', mocks)
+const Diff = t.mock('../../lib/diff.js', mocks)
const diff = new Diff(npm)
t.test('no args', t => {
@@ -314,7 +312,7 @@ t.test('single arg', t => {
config.diff = ['bar']
npm.prefix = path
- const Diff = requireInject('../../lib/diff.js', {
+ const Diff = t.mock('../../lib/diff.js', {
...mocks,
pacote: {
packument: (spec) => {
@@ -378,7 +376,7 @@ t.test('single arg', t => {
npm.prefix = resolve(path, 'project')
npm.globalDir = resolve(path, 'globalDir/lib/node_modules')
- const Diff = requireInject('../../lib/diff.js', {
+ const Diff = t.mock('../../lib/diff.js', {
...mocks,
pacote: {
packument: (spec) => {
@@ -465,7 +463,7 @@ t.test('single arg', t => {
}),
})
- const Diff = requireInject('../../lib/diff.js', {
+ const Diff = t.mock('../../lib/diff.js', {
...mocks,
'../../lib/utils/read-local-package.js': async () => 'my-project',
pacote: {
@@ -502,7 +500,7 @@ t.test('single arg', t => {
}),
})
- const Diff = requireInject('../../lib/diff.js', {
+ const Diff = t.mock('../../lib/diff.js', {
...mocks,
'../../lib/utils/read-local-package.js': async () => 'my-project',
'@npmcli/arborist': class {
@@ -940,7 +938,7 @@ t.test('first arg is a valid semver range', t => {
}),
})
- const Diff = requireInject('../../lib/diff.js', {
+ const Diff = t.mock('../../lib/diff.js', {
...mocks,
'../../lib/utils/read-local-package.js': async () => 'my-project',
'@npmcli/arborist': class {
diff --git a/test/lib/dist-tag.js b/test/lib/dist-tag.js
index 5e54c8f99..701bdc6e4 100644
--- a/test/lib/dist-tag.js
+++ b/test/lib/dist-tag.js
@@ -1,14 +1,12 @@
-const requireInject = require('require-inject')
const mockNpm = require('../fixtures/mock-npm')
-const { afterEach, test } = require('tap')
+const t = require('tap')
let result = ''
let log = ''
-afterEach((cb) => {
+t.afterEach(() => {
result = ''
log = ''
- cb()
})
const routeMap = {
@@ -58,7 +56,7 @@ const logger = (...msgs) => {
log += '\n'
}
-const DistTag = requireInject('../../lib/dist-tag.js', {
+const DistTag = t.mock('../../lib/dist-tag.js', {
npmlog: {
error: logger,
info: logger,
@@ -80,14 +78,14 @@ const npm = mockNpm({
})
const distTag = new DistTag(npm)
-test('ls in current package', (t) => {
+t.test('ls in current package', (t) => {
npm.prefix = t.testdir({
'package.json': JSON.stringify({
name: '@scoped/pkg',
}),
})
distTag.exec(['ls'], (err) => {
- t.ifError(err, 'npm dist-tags ls')
+ t.error(err, 'npm dist-tags ls')
t.matchSnapshot(
result,
'should list available tags for current package'
@@ -96,14 +94,14 @@ test('ls in current package', (t) => {
})
})
-test('no args in current package', (t) => {
+t.test('no args in current package', (t) => {
npm.prefix = t.testdir({
'package.json': JSON.stringify({
name: '@scoped/pkg',
}),
})
distTag.exec([], (err) => {
- t.ifError(err, 'npm dist-tags ls')
+ t.error(err, 'npm dist-tags ls')
t.matchSnapshot(
result,
'should default to listing available tags for current package'
@@ -112,7 +110,7 @@ test('no args in current package', (t) => {
})
})
-test('borked cmd usage', (t) => {
+t.test('borked cmd usage', (t) => {
npm.prefix = t.testdir({})
distTag.exec(['borked', '@scoped/pkg'], (err) => {
t.matchSnapshot(err, 'should show usage error')
@@ -120,10 +118,10 @@ test('borked cmd usage', (t) => {
})
})
-test('ls on named package', (t) => {
+t.test('ls on named package', (t) => {
npm.prefix = t.testdir({})
distTag.exec(['ls', '@scoped/another'], (err) => {
- t.ifError(err, 'npm dist-tags ls')
+ t.error(err, 'npm dist-tags ls')
t.matchSnapshot(
result,
'should list tags for the specified package'
@@ -132,7 +130,7 @@ test('ls on named package', (t) => {
})
})
-test('ls on missing package', (t) => {
+t.test('ls on missing package', (t) => {
npm.prefix = t.testdir({})
distTag.exec(['ls', 'foo'], (err) => {
t.matchSnapshot(
@@ -147,7 +145,7 @@ test('ls on missing package', (t) => {
})
})
-test('ls on missing name in current package', (t) => {
+t.test('ls on missing name in current package', (t) => {
npm.prefix = t.testdir({
'package.json': JSON.stringify({
version: '1.0.0',
@@ -162,10 +160,10 @@ test('ls on missing name in current package', (t) => {
})
})
-test('only named package arg', (t) => {
+t.test('only named package arg', (t) => {
npm.prefix = t.testdir({})
distTag.exec(['@scoped/another'], (err) => {
- t.ifError(err, 'npm dist-tags ls')
+ t.error(err, 'npm dist-tags ls')
t.matchSnapshot(
result,
'should default to listing tags for the specified package'
@@ -174,7 +172,7 @@ test('only named package arg', (t) => {
})
})
-test('workspaces', (t) => {
+t.test('workspaces', (t) => {
npm.localPrefix = t.testdir({
'package.json': JSON.stringify({
name: 'root',
@@ -203,7 +201,7 @@ test('workspaces', (t) => {
t.test('no args', t => {
distTag.execWorkspaces([], [], (err) => {
- t.ifError(err)
+ t.error(err)
t.matchSnapshot(result, 'printed the expected output')
t.end()
})
@@ -211,7 +209,7 @@ test('workspaces', (t) => {
t.test('no args, one workspace', t => {
distTag.execWorkspaces([], ['workspace-a'], (err) => {
- t.ifError(err)
+ t.error(err)
t.matchSnapshot(result, 'printed the expected output')
t.end()
})
@@ -219,7 +217,7 @@ test('workspaces', (t) => {
t.test('one arg -- .', t => {
distTag.execWorkspaces(['.'], [], (err) => {
- t.ifError(err)
+ t.error(err)
t.matchSnapshot(result, 'printed the expected output')
t.end()
})
@@ -227,7 +225,7 @@ test('workspaces', (t) => {
t.test('one arg -- .@1, ignores version spec', t => {
distTag.execWorkspaces(['.@'], [], (err) => {
- t.ifError(err)
+ t.error(err)
t.matchSnapshot(result, 'printed the expected output')
t.end()
})
@@ -235,7 +233,7 @@ test('workspaces', (t) => {
t.test('one arg -- list', t => {
distTag.execWorkspaces(['list'], [], (err) => {
- t.ifError(err)
+ t.error(err)
t.matchSnapshot(result, 'printed the expected output')
t.end()
})
@@ -243,7 +241,7 @@ test('workspaces', (t) => {
t.test('two args -- list, .', t => {
distTag.execWorkspaces(['list', '.'], [], (err) => {
- t.ifError(err)
+ t.error(err)
t.matchSnapshot(result, 'printed the expected output')
t.end()
})
@@ -251,7 +249,7 @@ test('workspaces', (t) => {
t.test('two args -- list, .@1, ignores version spec', t => {
distTag.execWorkspaces(['list', '.@'], [], (err) => {
- t.ifError(err)
+ t.error(err)
t.matchSnapshot(result, 'printed the expected output')
t.end()
})
@@ -259,7 +257,7 @@ test('workspaces', (t) => {
t.test('two args -- list, @scoped/pkg, logs a warning and ignores workspaces', t => {
distTag.execWorkspaces(['list', '@scoped/pkg'], [], (err) => {
- t.ifError(err)
+ t.error(err)
t.match(log, 'Ignoring workspaces for specified package', 'logs a warning')
t.matchSnapshot(result, 'printed the expected output')
t.end()
@@ -300,7 +298,7 @@ test('workspaces', (t) => {
})
distTag.execWorkspaces([], [], (err) => {
- t.ifError(err)
+ t.error(err)
t.equal(process.exitCode, 1, 'set the error status')
process.exitCode = 0
t.match(log, 'dist-tag ls Couldn\'t get dist-tag data for workspace-d@latest', 'logs the error')
@@ -312,7 +310,7 @@ test('workspaces', (t) => {
t.end()
})
-test('add new tag', (t) => {
+t.test('add new tag', (t) => {
const _nrf = npmRegistryFetchMock
t.teardown(() => {
npmRegistryFetchMock = _nrf
@@ -324,7 +322,7 @@ test('add new tag', (t) => {
}
npm.prefix = t.testdir({})
distTag.exec(['add', '@scoped/another@7.7.7', 'c'], (err) => {
- t.ifError(err, 'npm dist-tags add')
+ t.error(err, 'npm dist-tags add')
t.matchSnapshot(
result,
'should return success msg'
@@ -333,7 +331,7 @@ test('add new tag', (t) => {
})
})
-test('add using valid semver range as name', (t) => {
+t.test('add using valid semver range as name', (t) => {
npm.prefix = t.testdir({})
distTag.exec(['add', '@scoped/another@7.7.7', '1.0.0'], (err) => {
t.match(
@@ -349,7 +347,7 @@ test('add using valid semver range as name', (t) => {
})
})
-test('add missing args', (t) => {
+t.test('add missing args', (t) => {
npm.prefix = t.testdir({})
distTag.exec(['add', '@scoped/another@7.7.7'], (err) => {
t.matchSnapshot(err, 'should exit usage error message')
@@ -357,7 +355,7 @@ test('add missing args', (t) => {
})
})
-test('add missing pkg name', (t) => {
+t.test('add missing pkg name', (t) => {
npm.prefix = t.testdir({})
distTag.exec(['add', null], (err) => {
t.matchSnapshot(err, 'should exit usage error message')
@@ -365,10 +363,10 @@ test('add missing pkg name', (t) => {
})
})
-test('set existing version', (t) => {
+t.test('set existing version', (t) => {
npm.prefix = t.testdir({})
distTag.exec(['set', '@scoped/another@0.6.0', 'b'], (err) => {
- t.ifError(err, 'npm dist-tags set')
+ t.error(err, 'npm dist-tags set')
t.matchSnapshot(
log,
'should log warn msg'
@@ -377,7 +375,7 @@ test('set existing version', (t) => {
})
})
-test('remove existing tag', (t) => {
+t.test('remove existing tag', (t) => {
const _nrf = npmRegistryFetchMock
t.teardown(() => {
npmRegistryFetchMock = _nrf
@@ -388,14 +386,14 @@ test('remove existing tag', (t) => {
}
npm.prefix = t.testdir({})
distTag.exec(['rm', '@scoped/another', 'c'], (err) => {
- t.ifError(err, 'npm dist-tags rm')
+ t.error(err, 'npm dist-tags rm')
t.matchSnapshot(log, 'should log remove info')
t.matchSnapshot(result, 'should return success msg')
t.end()
})
})
-test('remove non-existing tag', (t) => {
+t.test('remove non-existing tag', (t) => {
npm.prefix = t.testdir({})
distTag.exec(['rm', '@scoped/another', 'nonexistent'], (err) => {
t.match(
@@ -408,7 +406,7 @@ test('remove non-existing tag', (t) => {
})
})
-test('remove missing pkg name', (t) => {
+t.test('remove missing pkg name', (t) => {
npm.prefix = t.testdir({})
distTag.exec(['rm', null], (err) => {
t.matchSnapshot(err, 'should exit usage error message')
@@ -416,7 +414,7 @@ test('remove missing pkg name', (t) => {
})
})
-test('completion', t => {
+t.test('completion', t => {
const { completion } = distTag
t.plan(2)
diff --git a/test/lib/docs.js b/test/lib/docs.js
index e8176eb47..0da070d9a 100644
--- a/test/lib/docs.js
+++ b/test/lib/docs.js
@@ -1,5 +1,4 @@
const t = require('tap')
-const requireInject = require('require-inject')
const mockNpm = require('../fixtures/mock-npm.js')
const { join, sep } = require('path')
@@ -72,16 +71,14 @@ const openUrl = async (npm, url, errMsg) => {
opened[url]++
}
-const Docs = requireInject('../../lib/docs.js', {
+const Docs = t.mock('../../lib/docs.js', {
'../../lib/utils/open-url.js': openUrl,
})
const flatOptions = {}
const npm = mockNpm({ flatOptions })
const docs = new Docs(npm)
-t.afterEach(async () => {
- opened = {}
-})
+t.afterEach(() => opened = {})
t.test('open docs urls', t => {
// XXX It is very odd that `where` is how pacote knows to look anywhere other
diff --git a/test/lib/doctor.js b/test/lib/doctor.js
index 56bbdf974..0ceb670c1 100644
--- a/test/lib/doctor.js
+++ b/test/lib/doctor.js
@@ -1,5 +1,4 @@
-const { test } = require('tap')
-const requireInject = require('require-inject')
+const t = require('tap')
const { join } = require('path')
const fs = require('fs')
@@ -123,7 +122,7 @@ const cacache = {
},
}
-const Doctor = requireInject('../../lib/doctor.js', {
+const Doctor = t.mock('../../lib/doctor.js', {
'../../lib/utils/is-windows.js': false,
'../../lib/utils/ping.js': ping,
cacache,
@@ -134,7 +133,7 @@ const Doctor = requireInject('../../lib/doctor.js', {
const doctor = new Doctor(npm)
const origVersion = process.version
-test('node versions', t => {
+t.test('node versions', t => {
t.plan(nodeVersions.length)
nodeVersions.forEach(({ version }) => {
@@ -276,13 +275,13 @@ test('node versions', t => {
st.match(output, /local bin folder.*ok/, 'local bin is ok')
st.match(output, /global bin folder.*ok/, 'global bin is ok')
st.match(output, /cache contents.*ok/, 'cache contents is ok')
- st.notEqual(output[0], ansiTrim(output[0]), 'output should contain color codes')
+ st.not(output[0], ansiTrim(output[0]), 'output should contain color codes')
st.end()
})
})
vt.test('npm doctor skips some tests in windows', st => {
- const WinDoctor = requireInject('../../lib/doctor.js', {
+ const WinDoctor = t.mock('../../lib/doctor.js', {
'../../lib/utils/is-windows.js': true,
'../../lib/utils/ping.js': ping,
cacache,
@@ -560,7 +559,7 @@ test('node versions', t => {
}
}
- const Doctor = requireInject('../../lib/doctor.js', {
+ const Doctor = t.mock('../../lib/doctor.js', {
'../../lib/utils/is-windows.js': false,
'../../lib/utils/ping.js': ping,
cacache,
@@ -903,7 +902,7 @@ test('node versions', t => {
})
})
-test('outdated node version', vt => {
+t.test('outdated node version', vt => {
vt.plan(1)
const version = 'v10.0.0'
diff --git a/test/lib/edit.js b/test/lib/edit.js
index acf03fa43..09908165d 100644
--- a/test/lib/edit.js
+++ b/test/lib/edit.js
@@ -1,6 +1,5 @@
-const { test } = require('tap')
+const t = require('tap')
const { resolve } = require('path')
-const requireInject = require('require-inject')
const { EventEmitter } = require('events')
let editorBin = null
@@ -39,13 +38,13 @@ const npm = {
}
const gracefulFs = require('graceful-fs')
-const Edit = requireInject('../../lib/edit.js', {
+const Edit = t.mock('../../lib/edit.js', {
child_process: childProcess,
'graceful-fs': gracefulFs,
})
const edit = new Edit(npm)
-test('npm edit', t => {
+t.test('npm edit', t => {
t.teardown(() => {
rebuildArgs = null
editorBin = null
@@ -66,7 +65,7 @@ test('npm edit', t => {
})
})
-test('rebuild fails', t => {
+t.test('rebuild fails', t => {
t.teardown(() => {
rebuildFail = null
rebuildArgs = null
@@ -87,7 +86,7 @@ test('rebuild fails', t => {
})
})
-test('npm edit editor has flags', t => {
+t.test('npm edit editor has flags', t => {
EDITOR = 'code -w'
t.teardown(() => {
rebuildArgs = null
@@ -110,14 +109,14 @@ test('npm edit editor has flags', t => {
})
})
-test('npm edit no args', t => {
+t.test('npm edit no args', t => {
return edit.exec([], (err) => {
t.match(err, /npm edit/, 'throws usage error')
t.end()
})
})
-test('npm edit lstat error propagates', t => {
+t.test('npm edit lstat error propagates', t => {
const _lstat = gracefulFs.lstat
gracefulFs.lstat = (dir, cb) => {
return cb(new Error('lstat failed'))
@@ -132,7 +131,7 @@ test('npm edit lstat error propagates', t => {
})
})
-test('npm edit editor exit code error propagates', t => {
+t.test('npm edit editor exit code error propagates', t => {
EDITOR_CODE = 137
t.teardown(() => {
EDITOR_CODE = 0
diff --git a/test/lib/exec.js b/test/lib/exec.js
index bcfe75577..0c577e42f 100644
--- a/test/lib/exec.js
+++ b/test/lib/exec.js
@@ -1,5 +1,4 @@
const t = require('tap')
-const requireInject = require('require-inject')
const mockNpm = require('../fixtures/mock-npm')
const { resolve, delimiter } = require('path')
const OUTPUT = []
@@ -94,10 +93,10 @@ const mocks = {
read,
'mkdirp-infer-owner': mkdirp,
}
-const Exec = requireInject('../../lib/exec.js', mocks)
+const Exec = t.mock('../../lib/exec.js', mocks)
const exec = new Exec(npm)
-t.afterEach(cb => {
+t.afterEach(() => {
MKDIRPS.length = 0
ARB_CTOR.length = 0
ARB_REIFY.length = 0
@@ -115,7 +114,6 @@ t.afterEach(cb => {
config.yes = true
npm.localBin = 'local-bin'
npm.globalBin = 'global-bin'
- cb()
})
t.test('npx foo, bin already exists locally', t => {
@@ -127,7 +125,7 @@ t.test('npx foo, bin already exists locally', t => {
npm.localBin = path
exec.exec(['foo', 'one arg', 'two arg'], er => {
- t.ifError(er, 'npm exec')
+ t.error(er, 'npm exec')
t.match(RUN_SCRIPTS, [{
pkg: { scripts: { npx: 'foo' }},
args: ['one arg', 'two arg'],
@@ -153,7 +151,7 @@ t.test('npx foo, bin already exists globally', t => {
npm.globalBin = path
exec.exec(['foo', 'one arg', 'two arg'], er => {
- t.ifError(er, 'npm exec')
+ t.error(er, 'npm exec')
t.match(RUN_SCRIPTS, [{
pkg: { scripts: { npx: 'foo' }},
args: ['one arg', 'two arg'],
@@ -1067,7 +1065,7 @@ t.test('abort if -n provided', t => {
t.equal(PROGRESS_ENABLED, true, 'progress re-enabled')
t.strictSame(RUN_SCRIPTS, [])
t.strictSame(READ, [])
- t.done()
+ t.end()
})
})
@@ -1095,7 +1093,7 @@ t.test('forward legacyPeerDeps opt', t => {
if (er)
throw er
t.match(ARB_REIFY, [{add: ['foo@'], legacyPeerDeps: true}], 'need to install foo@ using legacyPeerDeps opt')
- t.done()
+ t.end()
})
})
diff --git a/test/lib/explain.js b/test/lib/explain.js
index 2e82928d8..7e4ec8bd3 100644
--- a/test/lib/explain.js
+++ b/test/lib/explain.js
@@ -1,5 +1,4 @@
const t = require('tap')
-const requireInject = require('require-inject')
const npm = {
prefix: null,
color: true,
@@ -12,7 +11,7 @@ const { resolve } = require('path')
const OUTPUT = []
-const Explain = requireInject('../../lib/explain.js', {
+const Explain = t.mock('../../lib/explain.js', {
// keep the snapshots pared down a bit, since this has its own tests.
'../../lib/utils/explain-dep.js': {
@@ -27,7 +26,7 @@ t.test('no args throws usage', t => {
t.plan(1)
explain.exec([], er => {
t.equal(er, explain.usage)
- t.done()
+ t.end()
})
})
@@ -49,10 +48,9 @@ t.test('invalid package name throws not found', t => {
})
t.test('explain some nodes', t => {
- t.afterEach((cb) => {
+ t.afterEach(() => {
OUTPUT.length = 0
npm.flatOptions.json = false
- cb()
})
npm.prefix = t.testdir({
@@ -172,7 +170,7 @@ t.test('explain some nodes', t => {
t.plan(1)
explain.exec(['asdf/foo/bar', 'quux@1.x'], er => {
t.equal(er, 'No dependencies found matching asdf/foo/bar, quux@1.x')
- t.done()
+ t.end()
})
})
t.end()
diff --git a/test/lib/explore.js b/test/lib/explore.js
index a0655380e..b49c885cb 100644
--- a/test/lib/explore.js
+++ b/test/lib/explore.js
@@ -1,5 +1,4 @@
const t = require('tap')
-const requireInject = require('require-inject')
let RPJ_ERROR = null
let RPJ_CALLED = ''
@@ -47,7 +46,7 @@ const output = []
let ERROR_HANDLER_CALLED = null
const logs = []
const getExplore = (windows) => {
- const Explore = requireInject('../../lib/explore.js', {
+ const Explore = t.mock('../../lib/explore.js', {
'../../lib/utils/is-windows.js': windows,
path: require('path')[windows ? 'win32' : 'posix'],
'../../lib/utils/error-handler.js': er => {
@@ -77,10 +76,7 @@ const windowsExplore = getExplore(true)
const posixExplore = getExplore(false)
t.test('basic interactive', t => {
- t.afterEach((cb) => {
- output.length = 0
- cb()
- })
+ t.afterEach(() => output.length = 0)
t.test('windows', t => windowsExplore.exec(['pkg'], er => {
if (er)
@@ -125,16 +121,14 @@ t.test('basic interactive', t => {
t.test('interactive tracks exit code', t => {
const { exitCode } = process
- t.beforeEach((cb) => {
+ t.beforeEach(() => {
process.exitCode = exitCode
RUN_SCRIPT_EXIT_CODE = 99
- cb()
})
- t.afterEach((cb) => {
+ t.afterEach(() => {
RUN_SCRIPT_EXIT_CODE = 0
output.length = 0
process.exitCode = exitCode
- cb()
})
t.test('windows', t => windowsExplore.exec(['pkg'], er => {
@@ -223,10 +217,7 @@ t.test('interactive tracks exit code', t => {
})
t.test('basic non-interactive', t => {
- t.afterEach((cb) => {
- output.length = 0
- cb()
- })
+ t.afterEach(() => output.length = 0)
t.test('windows', t => windowsExplore.exec(['pkg', 'ls'], er => {
if (er)
@@ -267,22 +258,17 @@ t.test('basic non-interactive', t => {
t.test('signal fails non-interactive', t => {
const { exitCode } = process
- t.afterEach((cb) => {
+ t.afterEach(() => {
output.length = 0
logs.length = 0
- cb()
})
- t.beforeEach(cb => {
+ t.beforeEach(() => {
RUN_SCRIPT_SIGNAL = 'SIGPROBLEM'
RUN_SCRIPT_EXIT_CODE = null
process.exitCode = exitCode
- cb()
- })
- t.afterEach(cb => {
- process.exitCode = exitCode
- cb()
})
+ t.afterEach(() => process.exitCode = exitCode)
t.test('windows', t => windowsExplore.exec(['pkg', 'ls'], er => {
t.match(er, {
diff --git a/test/lib/fund.js b/test/lib/fund.js
index 8c1000784..41754d51f 100644
--- a/test/lib/fund.js
+++ b/test/lib/fund.js
@@ -1,5 +1,4 @@
-const { test } = require('tap')
-const requireInject = require('require-inject')
+const t = require('tap')
const mockNpm = require('../fixtures/mock-npm')
const version = '1.0.0'
@@ -200,7 +199,7 @@ const openUrl = async (npm, url, msg) => {
} else
printUrl = `${msg}:\n ${url}`
}
-const Fund = requireInject('../../lib/fund.js', {
+const Fund = t.mock('../../lib/fund.js', {
'../../lib/utils/open-url.js': openUrl,
pacote: {
manifest: (arg) => arg.name === 'ntl'
@@ -218,7 +217,7 @@ const npm = mockNpm({
})
const fund = new Fund(npm)
-test('fund with no package containing funding', t => {
+t.test('fund with no package containing funding', t => {
npm.prefix = t.testdir({
'package.json': JSON.stringify({
name: 'no-funding-package',
@@ -227,31 +226,31 @@ test('fund with no package containing funding', t => {
})
fund.exec([], (err) => {
- t.ifError(err, 'should not error out')
+ t.error(err, 'should not error out')
t.matchSnapshot(result, 'should print empty funding info')
result = ''
t.end()
})
})
-test('fund in which same maintainer owns all its deps', t => {
+t.test('fund in which same maintainer owns all its deps', t => {
npm.prefix = t.testdir(maintainerOwnsAllDeps)
fund.exec([], (err) => {
- t.ifError(err, 'should not error out')
+ t.error(err, 'should not error out')
t.matchSnapshot(result, 'should print stack packages together')
result = ''
t.end()
})
})
-test('fund in which same maintainer owns all its deps, using --json option', t => {
+t.test('fund in which same maintainer owns all its deps, using --json option', t => {
config.json = true
npm.prefix = t.testdir(maintainerOwnsAllDeps)
fund.exec([], (err) => {
- t.ifError(err, 'should not error out')
- t.deepEqual(
+ t.error(err, 'should not error out')
+ t.same(
JSON.parse(result),
{
length: 3,
@@ -284,11 +283,11 @@ test('fund in which same maintainer owns all its deps, using --json option', t =
})
})
-test('fund containing multi-level nested deps with no funding', t => {
+t.test('fund containing multi-level nested deps with no funding', t => {
npm.prefix = t.testdir(nestedNoFundingPackages)
fund.exec([], (err) => {
- t.ifError(err, 'should not error out')
+ t.error(err, 'should not error out')
t.matchSnapshot(
result,
'should omit dependencies with no funding declared'
@@ -299,13 +298,13 @@ test('fund containing multi-level nested deps with no funding', t => {
})
})
-test('fund containing multi-level nested deps with no funding, using --json option', t => {
+t.test('fund containing multi-level nested deps with no funding, using --json option', t => {
npm.prefix = t.testdir(nestedNoFundingPackages)
config.json = true
fund.exec([], (err) => {
- t.ifError(err, 'should not error out')
- t.deepEqual(
+ t.error(err, 'should not error out')
+ t.same(
JSON.parse(result),
{
length: 2,
@@ -331,13 +330,13 @@ test('fund containing multi-level nested deps with no funding, using --json opti
})
})
-test('fund containing multi-level nested deps with no funding, using --json option', t => {
+t.test('fund containing multi-level nested deps with no funding, using --json option', t => {
npm.prefix = t.testdir(nestedMultipleFundingPackages)
config.json = true
fund.exec([], (err) => {
- t.ifError(err, 'should not error out')
- t.deepEqual(
+ t.error(err, 'should not error out')
+ t.same(
JSON.parse(result),
{
length: 2,
@@ -388,7 +387,7 @@ test('fund containing multi-level nested deps with no funding, using --json opti
})
})
-test('fund does not support global', t => {
+t.test('fund does not support global', t => {
npm.prefix = t.testdir({})
config.global = true
@@ -401,11 +400,11 @@ test('fund does not support global', t => {
})
})
-test('fund using package argument', t => {
+t.test('fund using package argument', t => {
npm.prefix = t.testdir(maintainerOwnsAllDeps)
fund.exec(['.'], (err) => {
- t.ifError(err, 'should not error out')
+ t.error(err, 'should not error out')
t.matchSnapshot(printUrl, 'should open funding url')
printUrl = ''
@@ -413,7 +412,7 @@ test('fund using package argument', t => {
})
})
-test('fund does not support global, using --json option', t => {
+t.test('fund does not support global, using --json option', t => {
npm.prefix = t.testdir({})
config.global = true
config.json = true
@@ -432,7 +431,7 @@ test('fund does not support global, using --json option', t => {
})
})
-test('fund using string shorthand', t => {
+t.test('fund using string shorthand', t => {
npm.prefix = t.testdir({
'package.json': JSON.stringify({
name: 'funding-string-shorthand',
@@ -442,7 +441,7 @@ test('fund using string shorthand', t => {
})
fund.exec(['.'], (err) => {
- t.ifError(err, 'should not error out')
+ t.error(err, 'should not error out')
t.matchSnapshot(printUrl, 'should open string-only url')
printUrl = ''
@@ -450,11 +449,11 @@ test('fund using string shorthand', t => {
})
})
-test('fund using nested packages with multiple sources', t => {
+t.test('fund using nested packages with multiple sources', t => {
npm.prefix = t.testdir(nestedMultipleFundingPackages)
fund.exec(['.'], (err) => {
- t.ifError(err, 'should not error out')
+ t.error(err, 'should not error out')
t.matchSnapshot(result, 'should prompt with all available URLs')
result = ''
@@ -462,7 +461,7 @@ test('fund using nested packages with multiple sources', t => {
})
})
-test('fund using symlink ref', t => {
+t.test('fund using symlink ref', t => {
npm.prefix = t.testdir({
'package.json': JSON.stringify({
name: 'using-symlink-ref',
@@ -482,7 +481,7 @@ test('fund using symlink ref', t => {
// using symlinked ref
fund.exec(['./node_modules/a'], (err) => {
- t.ifError(err, 'should not error out')
+ t.error(err, 'should not error out')
t.match(
printUrl,
'http://example.com/a',
@@ -493,7 +492,7 @@ test('fund using symlink ref', t => {
// using target ref
fund.exec(['./a'], (err) => {
- t.ifError(err, 'should not error out')
+ t.error(err, 'should not error out')
t.match(
printUrl,
@@ -508,7 +507,7 @@ test('fund using symlink ref', t => {
})
})
-test('fund using data from actual tree', t => {
+t.test('fund using data from actual tree', t => {
npm.prefix = t.testdir({
'package.json': JSON.stringify({
name: 'using-actual-tree',
@@ -543,7 +542,7 @@ test('fund using data from actual tree', t => {
// using symlinked ref
fund.exec(['a'], (err) => {
- t.ifError(err, 'should not error out')
+ t.error(err, 'should not error out')
t.match(
printUrl,
'http://example.com/_AAA',
@@ -555,12 +554,12 @@ test('fund using data from actual tree', t => {
})
})
-test('fund using nested packages with multiple sources, with a source number', t => {
+t.test('fund using nested packages with multiple sources, with a source number', t => {
npm.prefix = t.testdir(nestedMultipleFundingPackages)
config.which = '1'
fund.exec(['.'], (err) => {
- t.ifError(err, 'should not error out')
+ t.error(err, 'should not error out')
t.matchSnapshot(printUrl, 'should open the numbered URL')
config.which = null
@@ -569,12 +568,12 @@ test('fund using nested packages with multiple sources, with a source number', t
})
})
-test('fund using pkg name while having conflicting versions', t => {
+t.test('fund using pkg name while having conflicting versions', t => {
npm.prefix = t.testdir(conflictingFundingPackages)
config.which = '1'
fund.exec(['foo'], (err) => {
- t.ifError(err, 'should not error out')
+ t.error(err, 'should not error out')
t.matchSnapshot(printUrl, 'should open greatest version')
printUrl = ''
@@ -582,13 +581,13 @@ test('fund using pkg name while having conflicting versions', t => {
})
})
-test('fund using package argument with no browser, using --json option', t => {
+t.test('fund using package argument with no browser, using --json option', t => {
npm.prefix = t.testdir(maintainerOwnsAllDeps)
config.json = true
fund.exec(['.'], (err) => {
- t.ifError(err, 'should not error out')
- t.deepEqual(
+ t.error(err, 'should not error out')
+ t.same(
JSON.parse(printUrl),
{
title: 'individual funding available at the following URL',
@@ -603,11 +602,11 @@ test('fund using package argument with no browser, using --json option', t => {
})
})
-test('fund using package info fetch from registry', t => {
+t.test('fund using package info fetch from registry', t => {
npm.prefix = t.testdir({})
fund.exec(['ntl'], (err) => {
- t.ifError(err, 'should not error out')
+ t.error(err, 'should not error out')
t.match(
printUrl,
/http:\/\/example.com\/pacote/,
@@ -619,7 +618,7 @@ test('fund using package info fetch from registry', t => {
})
})
-test('fund tries to use package info fetch from registry but registry has nothing', t => {
+t.test('fund tries to use package info fetch from registry but registry has nothing', t => {
npm.prefix = t.testdir({})
fund.exec(['foo'], (err) => {
@@ -635,7 +634,7 @@ test('fund tries to use package info fetch from registry but registry has nothin
})
})
-test('fund but target module has no funding info', t => {
+t.test('fund but target module has no funding info', t => {
npm.prefix = t.testdir(nestedNoFundingPackages)
fund.exec(['foo'], (err) => {
@@ -651,7 +650,7 @@ test('fund but target module has no funding info', t => {
})
})
-test('fund using bad which value', t => {
+t.test('fund using bad which value', t => {
npm.prefix = t.testdir(nestedMultipleFundingPackages)
config.which = 3
@@ -669,7 +668,7 @@ test('fund using bad which value', t => {
})
})
-test('fund pkg missing version number', t => {
+t.test('fund pkg missing version number', t => {
npm.prefix = t.testdir({
'package.json': JSON.stringify({
name: 'foo',
@@ -678,14 +677,14 @@ test('fund pkg missing version number', t => {
})
fund.exec([], (err) => {
- t.ifError(err, 'should not error out')
+ t.error(err, 'should not error out')
t.matchSnapshot(result, 'should print name only')
result = ''
t.end()
})
})
-test('fund a package throws on openUrl', t => {
+t.test('fund a package throws on openUrl', t => {
npm.prefix = t.testdir({
'package.json': JSON.stringify({
name: 'foo',
@@ -701,7 +700,7 @@ test('fund a package throws on openUrl', t => {
})
})
-test('fund a package with type and multiple sources', t => {
+t.test('fund a package with type and multiple sources', t => {
npm.prefix = t.testdir({
'package.json': JSON.stringify({
name: 'foo',
@@ -719,7 +718,7 @@ test('fund a package with type and multiple sources', t => {
})
fund.exec(['.'], (err) => {
- t.ifError(err, 'should not error out')
+ t.error(err, 'should not error out')
t.matchSnapshot(result, 'should print prompt select message')
result = ''
@@ -727,7 +726,7 @@ test('fund a package with type and multiple sources', t => {
})
})
-test('fund colors', t => {
+t.test('fund colors', t => {
npm.prefix = t.testdir({
'package.json': JSON.stringify({
name: 'test-fund-colors',
@@ -783,7 +782,7 @@ test('fund colors', t => {
npm.color = true
fund.exec([], (err) => {
- t.ifError(err, 'should not error out')
+ t.error(err, 'should not error out')
t.matchSnapshot(result, 'should print output with color info')
result = ''
@@ -792,7 +791,7 @@ test('fund colors', t => {
})
})
-test('sub dep with fund info and a parent with no funding info', t => {
+t.test('sub dep with fund info and a parent with no funding info', t => {
npm.prefix = t.testdir({
'package.json': JSON.stringify({
name: 'test-multiple-funding-sources',
@@ -833,7 +832,7 @@ test('sub dep with fund info and a parent with no funding info', t => {
})
fund.exec([], (err) => {
- t.ifError(err, 'should not error out')
+ t.error(err, 'should not error out')
t.matchSnapshot(result, 'should nest sub dep as child of root')
result = ''
diff --git a/test/lib/get.js b/test/lib/get.js
index a11597d26..9b77fbba3 100644
--- a/test/lib/get.js
+++ b/test/lib/get.js
@@ -1,8 +1,7 @@
-const { test } = require('tap')
-const requireInject = require('require-inject')
+const t = require('tap')
-test('should retrieve values from npm.commands.config', (t) => {
- const Get = requireInject('../../lib/get.js')
+t.test('should retrieve values from npm.commands.config', (t) => {
+ const Get = t.mock('../../lib/get.js')
const get = new Get({
commands: {
config: ([action, arg]) => {
diff --git a/test/lib/help-search.js b/test/lib/help-search.js
index 567097a2e..845b3873e 100644
--- a/test/lib/help-search.js
+++ b/test/lib/help-search.js
@@ -1,6 +1,5 @@
-const { test } = require('tap')
+const t = require('tap')
const { join } = require('path')
-const requireInject = require('require-inject')
const mockNpm = require('../fixtures/mock-npm')
const ansicolors = require('ansicolors')
@@ -43,12 +42,12 @@ const globDir = {
const glob = (p, cb) =>
cb(null, Object.keys(globDir).map((file) => join(globRoot, file)))
-const HelpSearch = requireInject('../../lib/help-search.js', {
+const HelpSearch = t.mock('../../lib/help-search.js', {
glob,
})
const helpSearch = new HelpSearch(npm)
-test('npm help-search', t => {
+t.test('npm help-search', t => {
globRoot = t.testdir(globDir)
t.teardown(() => {
OUTPUT.length = 0
@@ -64,7 +63,7 @@ test('npm help-search', t => {
})
})
-test('npm help-search multiple terms', t => {
+t.test('npm help-search multiple terms', t => {
globRoot = t.testdir(globDir)
t.teardown(() => {
OUTPUT.length = 0
@@ -81,7 +80,7 @@ test('npm help-search multiple terms', t => {
})
})
-test('npm help-search long output', t => {
+t.test('npm help-search long output', t => {
globRoot = t.testdir(globDir)
config.long = true
t.teardown(() => {
@@ -99,7 +98,7 @@ test('npm help-search long output', t => {
})
})
-test('npm help-search long output with color', t => {
+t.test('npm help-search long output with color', t => {
globRoot = t.testdir(globDir)
config.long = true
npm.color = true
@@ -120,7 +119,7 @@ test('npm help-search long output with color', t => {
})
})
-test('npm help-search no args', t => {
+t.test('npm help-search no args', t => {
return helpSearch.exec([], (err) => {
t.notOk(err)
t.match(OUTPUT, /npm help-search/, 'outputs usage')
@@ -128,7 +127,7 @@ test('npm help-search no args', t => {
})
})
-test('npm help-search no matches', t => {
+t.test('npm help-search no matches', t => {
globRoot = t.testdir(globDir)
t.teardown(() => {
OUTPUT.length = 0
diff --git a/test/lib/help.js b/test/lib/help.js
index b5fe297b5..44ba5b1ca 100644
--- a/test/lib/help.js
+++ b/test/lib/help.js
@@ -1,5 +1,4 @@
-const { test } = require('tap')
-const requireInject = require('require-inject')
+const t = require('tap')
const { EventEmitter } = require('events')
const npmConfig = {
@@ -68,7 +67,7 @@ const openUrl = async (npm, url, msg) => {
openUrlArg = url
}
-const Help = requireInject('../../lib/help.js', {
+const Help = t.mock('../../lib/help.js', {
'../../lib/utils/open-url.js': openUrl,
child_process: {
spawn,
@@ -77,7 +76,7 @@ const Help = requireInject('../../lib/help.js', {
})
const help = new Help(npm)
-test('npm help', t => {
+t.test('npm help', t => {
return help.exec([], (err) => {
if (err)
throw err
@@ -87,7 +86,7 @@ test('npm help', t => {
})
})
-test('npm help completion', async t => {
+t.test('npm help completion', async t => {
t.teardown(() => {
globErr = null
})
@@ -100,7 +99,7 @@ test('npm help completion', async t => {
t.rejects(help.completion({ conf: { argv: { remain: [] } } }), /glob failed/, 'glob errors propagate')
})
-test('npm help multiple args calls search', t => {
+t.test('npm help multiple args calls search', t => {
t.teardown(() => {
helpSearchArgs = null
})
@@ -114,7 +113,7 @@ test('npm help multiple args calls search', t => {
})
})
-test('npm help no matches calls search', t => {
+t.test('npm help no matches calls search', t => {
globResult = []
t.teardown(() => {
helpSearchArgs = null
@@ -130,7 +129,7 @@ test('npm help no matches calls search', t => {
})
})
-test('npm help glob errors propagate', t => {
+t.test('npm help glob errors propagate', t => {
globErr = new Error('glob failed')
t.teardown(() => {
globErr = null
@@ -144,7 +143,7 @@ test('npm help glob errors propagate', t => {
})
})
-test('npm help whoami', t => {
+t.test('npm help whoami', t => {
globResult = ['/root/man/man1/npm-whoami.1.xz']
t.teardown(() => {
globResult = globDefaults
@@ -162,7 +161,7 @@ test('npm help whoami', t => {
})
})
-test('npm help 1 install', t => {
+t.test('npm help 1 install', t => {
npmConfig.viewer = 'browser'
globResult = [
'/root/man/man5/install.5',
@@ -185,7 +184,7 @@ test('npm help 1 install', t => {
})
})
-test('npm help 5 install', t => {
+t.test('npm help 5 install', t => {
npmConfig.viewer = 'browser'
globResult = [
'/root/man/man5/install.5',
@@ -209,7 +208,7 @@ test('npm help 5 install', t => {
})
})
-test('npm help 7 config', t => {
+t.test('npm help 7 config', t => {
npmConfig.viewer = 'browser'
globResult = [
'/root/man/man7/config.7',
@@ -232,7 +231,7 @@ test('npm help 7 config', t => {
})
})
-test('npm help package.json redirects to package-json', t => {
+t.test('npm help package.json redirects to package-json', t => {
globResult = ['/root/man/man5/package-json.5']
t.teardown(() => {
globResult = globDefaults
@@ -251,7 +250,7 @@ test('npm help package.json redirects to package-json', t => {
})
})
-test('npm help ?(un)star', t => {
+t.test('npm help ?(un)star', t => {
npmConfig.viewer = 'woman'
globResult = [
'/root/man/man1/npm-star.1',
@@ -274,7 +273,7 @@ test('npm help ?(un)star', t => {
})
})
-test('npm help - woman viewer propagates errors', t => {
+t.test('npm help - woman viewer propagates errors', t => {
npmConfig.viewer = 'woman'
spawnCode = 1
globResult = [
@@ -297,7 +296,7 @@ test('npm help - woman viewer propagates errors', t => {
})
})
-test('npm help un*', t => {
+t.test('npm help un*', t => {
globResult = [
'/root/man/man1/npm-unstar.1',
'/root/man/man1/npm-uninstall.1',
@@ -319,7 +318,7 @@ test('npm help un*', t => {
})
})
-test('npm help - man viewer propagates errors', t => {
+t.test('npm help - man viewer propagates errors', t => {
spawnCode = 1
globResult = [
'/root/man/man1/npm-unstar.1',
@@ -341,7 +340,7 @@ test('npm help - man viewer propagates errors', t => {
})
})
-test('npm help with complex installation path finds proper help file', t => {
+t.test('npm help with complex installation path finds proper help file', t => {
npmConfig.viewer = 'browser'
globResult = [
'C:/Program Files/node-v14.15.5-win-x64/node_modules/npm/man/man1/npm-install.1',
diff --git a/test/lib/hook.js b/test/lib/hook.js
index 3e012d94e..2419f1604 100644
--- a/test/lib/hook.js
+++ b/test/lib/hook.js
@@ -1,5 +1,4 @@
-const { test } = require('tap')
-const requireInject = require('require-inject')
+const t = require('tap')
const output = []
const npm = {
@@ -55,20 +54,20 @@ const libnpmhook = {
},
}
-const Hook = requireInject('../../lib/hook.js', {
+const Hook = t.mock('../../lib/hook.js', {
'../../lib/utils/otplease.js': async (opts, fn) => fn(opts),
libnpmhook,
})
const hook = new Hook(npm)
-test('npm hook no args', t => {
+t.test('npm hook no args', t => {
return hook.exec([], (err) => {
t.match(err, /npm hook add/, 'throws usage with no arguments')
t.end()
})
})
-test('npm hook add', t => {
+t.test('npm hook add', t => {
t.teardown(() => {
hookArgs = null
output.length = 0
@@ -89,7 +88,7 @@ test('npm hook add', t => {
})
})
-test('npm hook add - unicode output', t => {
+t.test('npm hook add - unicode output', t => {
npm.flatOptions.unicode = true
t.teardown(() => {
npm.flatOptions.unicode = false
@@ -112,7 +111,7 @@ test('npm hook add - unicode output', t => {
})
})
-test('npm hook add - json output', t => {
+t.test('npm hook add - json output', t => {
npm.flatOptions.json = true
t.teardown(() => {
npm.flatOptions.json = false
@@ -140,7 +139,7 @@ test('npm hook add - json output', t => {
})
})
-test('npm hook add - parseable output', t => {
+t.test('npm hook add - parseable output', t => {
npm.flatOptions.parseable = true
t.teardown(() => {
npm.flatOptions.parseable = false
@@ -168,7 +167,7 @@ test('npm hook add - parseable output', t => {
})
})
-test('npm hook add - silent output', t => {
+t.test('npm hook add - silent output', t => {
npm.flatOptions.silent = true
t.teardown(() => {
npm.flatOptions.silent = false
@@ -191,7 +190,7 @@ test('npm hook add - silent output', t => {
})
})
-test('npm hook ls', t => {
+t.test('npm hook ls', t => {
t.teardown(() => {
hookArgs = null
output.length = 0
@@ -214,7 +213,7 @@ test('npm hook ls', t => {
})
})
-test('npm hook ls, no results', t => {
+t.test('npm hook ls, no results', t => {
hookResponse = []
t.teardown(() => {
hookResponse = null
@@ -235,7 +234,7 @@ test('npm hook ls, no results', t => {
})
})
-test('npm hook ls, single result', t => {
+t.test('npm hook ls, single result', t => {
hookResponse = [{
id: 1,
name: 'semver',
@@ -264,7 +263,7 @@ test('npm hook ls, single result', t => {
})
})
-test('npm hook ls - json output', t => {
+t.test('npm hook ls - json output', t => {
npm.flatOptions.json = true
t.teardown(() => {
npm.flatOptions.json = false
@@ -301,7 +300,7 @@ test('npm hook ls - json output', t => {
})
})
-test('npm hook ls - parseable output', t => {
+t.test('npm hook ls - parseable output', t => {
npm.flatOptions.parseable = true
t.teardown(() => {
npm.flatOptions.parseable = false
@@ -327,7 +326,7 @@ test('npm hook ls - parseable output', t => {
})
})
-test('npm hook ls - silent output', t => {
+t.test('npm hook ls - silent output', t => {
npm.flatOptions.silent = true
t.teardown(() => {
npm.flatOptions.silent = false
@@ -348,7 +347,7 @@ test('npm hook ls - silent output', t => {
})
})
-test('npm hook rm', t => {
+t.test('npm hook rm', t => {
t.teardown(() => {
hookArgs = null
output.length = 0
@@ -369,7 +368,7 @@ test('npm hook rm', t => {
})
})
-test('npm hook rm - unicode output', t => {
+t.test('npm hook rm - unicode output', t => {
npm.flatOptions.unicode = true
t.teardown(() => {
npm.flatOptions.unicode = false
@@ -392,7 +391,7 @@ test('npm hook rm - unicode output', t => {
})
})
-test('npm hook rm - silent output', t => {
+t.test('npm hook rm - silent output', t => {
npm.flatOptions.silent = true
t.teardown(() => {
npm.flatOptions.silent = false
@@ -413,7 +412,7 @@ test('npm hook rm - silent output', t => {
})
})
-test('npm hook rm - json output', t => {
+t.test('npm hook rm - json output', t => {
npm.flatOptions.json = true
t.teardown(() => {
npm.flatOptions.json = false
@@ -439,7 +438,7 @@ test('npm hook rm - json output', t => {
})
})
-test('npm hook rm - parseable output', t => {
+t.test('npm hook rm - parseable output', t => {
npm.flatOptions.parseable = true
t.teardown(() => {
npm.flatOptions.parseable = false
@@ -463,7 +462,7 @@ test('npm hook rm - parseable output', t => {
})
})
-test('npm hook update', t => {
+t.test('npm hook update', t => {
t.teardown(() => {
hookArgs = null
output.length = 0
@@ -486,7 +485,7 @@ test('npm hook update', t => {
})
})
-test('npm hook update - unicode', t => {
+t.test('npm hook update - unicode', t => {
npm.flatOptions.unicode = true
t.teardown(() => {
npm.flatOptions.unicode = false
@@ -511,7 +510,7 @@ test('npm hook update - unicode', t => {
})
})
-test('npm hook update - json output', t => {
+t.test('npm hook update - json output', t => {
npm.flatOptions.json = true
t.teardown(() => {
npm.flatOptions.json = false
@@ -539,7 +538,7 @@ test('npm hook update - json output', t => {
})
})
-test('npm hook update - parseable output', t => {
+t.test('npm hook update - parseable output', t => {
npm.flatOptions.parseable = true
t.teardown(() => {
npm.flatOptions.parseable = false
@@ -565,7 +564,7 @@ test('npm hook update - parseable output', t => {
})
})
-test('npm hook update - silent output', t => {
+t.test('npm hook update - silent output', t => {
npm.flatOptions.silent = true
t.teardown(() => {
npm.flatOptions.silent = false
diff --git a/test/lib/init.js b/test/lib/init.js
index 2b212f4a1..11273e4c3 100644
--- a/test/lib/init.js
+++ b/test/lib/init.js
@@ -1,5 +1,4 @@
const t = require('tap')
-const requireInject = require('require-inject')
const mockNpm = require('../fixtures/mock-npm')
let result = ''
@@ -26,20 +25,19 @@ const mocks = {
'init-package-json': (dir, initFile, config, cb) => cb(null, 'data'),
'../../lib/utils/usage.js': () => 'usage instructions',
}
-const Init = requireInject('../../lib/init.js', mocks)
+const Init = t.mock('../../lib/init.js', mocks)
const init = new Init(npm)
-t.afterEach(cb => {
+t.afterEach(() => {
result = ''
config.package = undefined
npm.commands = {}
npm.log = npmLog
- cb()
})
t.test('classic npm init no args', t => {
init.exec([], err => {
- t.ifError(err, 'npm init no args')
+ t.error(err, 'npm init no args')
t.matchSnapshot(result, 'should print helper info')
t.end()
})
@@ -62,7 +60,7 @@ t.test('classic npm init -y', t => {
t.equal(msg, 'written successfully', 'should print done info')
}
init.exec([], err => {
- t.ifError(err, 'npm init -y')
+ t.error(err, 'npm init -y')
t.equal(result, '')
})
})
@@ -70,8 +68,8 @@ t.test('classic npm init -y', t => {
t.test('npm init <arg>', t => {
t.plan(3)
npm.commands.exec = (arr, cb) => {
- t.deepEqual(config.package, [], 'should set empty array value')
- t.deepEqual(
+ t.same(config.package, [], 'should set empty array value')
+ t.same(
arr,
['create-react-app'],
'should npx with listed packages'
@@ -79,14 +77,14 @@ t.test('npm init <arg>', t => {
cb()
}
init.exec(['react-app'], err => {
- t.ifError(err, 'npm init react-app')
+ t.error(err, 'npm init react-app')
})
})
t.test('npm init @scope/name', t => {
t.plan(2)
npm.commands.exec = (arr, cb) => {
- t.deepEqual(
+ t.same(
arr,
['@npmcli/create-something'],
'should npx with scoped packages'
@@ -94,14 +92,14 @@ t.test('npm init @scope/name', t => {
cb()
}
init.exec(['@npmcli/something'], err => {
- t.ifError(err, 'npm init init @scope/name')
+ t.error(err, 'npm init init @scope/name')
})
})
t.test('npm init git spec', t => {
t.plan(2)
npm.commands.exec = (arr, cb) => {
- t.deepEqual(
+ t.same(
arr,
['npm/create-something'],
'should npx with git-spec packages'
@@ -109,14 +107,14 @@ t.test('npm init git spec', t => {
cb()
}
init.exec(['npm/something'], err => {
- t.ifError(err, 'npm init init @scope/name')
+ t.error(err, 'npm init init @scope/name')
})
})
t.test('npm init @scope', t => {
t.plan(2)
npm.commands.exec = (arr, cb) => {
- t.deepEqual(
+ t.same(
arr,
['@npmcli/create'],
'should npx with @scope/create pkgs'
@@ -124,7 +122,7 @@ t.test('npm init @scope', t => {
cb()
}
init.exec(['@npmcli'], err => {
- t.ifError(err, 'npm init init @scope/create')
+ t.error(err, 'npm init init @scope/create')
})
})
@@ -142,7 +140,7 @@ t.test('npm init tgz', t => {
t.test('npm init <arg>@next', t => {
t.plan(2)
npm.commands.exec = (arr, cb) => {
- t.deepEqual(
+ t.same(
arr,
['create-something@next'],
'should npx with something@next'
@@ -150,7 +148,7 @@ t.test('npm init <arg>@next', t => {
cb()
}
init.exec(['something@next'], err => {
- t.ifError(err, 'npm init init something@next')
+ t.error(err, 'npm init init something@next')
})
})
@@ -171,8 +169,8 @@ t.test('npm init exec error', t => {
t.test('should not rewrite flatOptions', t => {
t.plan(3)
npm.commands.exec = (arr, cb) => {
- t.deepEqual(config.package, [], 'should set empty array value')
- t.deepEqual(
+ t.same(config.package, [], 'should set empty array value')
+ t.same(
arr,
['create-react-app', 'my-app'],
'should npx with extra args'
@@ -180,13 +178,13 @@ t.test('should not rewrite flatOptions', t => {
cb()
}
init.exec(['react-app', 'my-app'], err => {
- t.ifError(err, 'npm init react-app')
+ t.error(err, 'npm init react-app')
})
})
t.test('npm init cancel', t => {
t.plan(3)
- const Init = requireInject('../../lib/init.js', {
+ const Init = t.mock('../../lib/init.js', {
...mocks,
'init-package-json': (dir, initFile, config, cb) => cb(
new Error('canceled')
@@ -199,12 +197,12 @@ t.test('npm init cancel', t => {
t.equal(msg, 'canceled', 'should log canceled')
}
init.exec([], err => {
- t.ifError(err, 'npm init cancel')
+ t.error(err, 'npm init cancel')
})
})
t.test('npm init error', t => {
- const Init = requireInject('../../lib/init.js', {
+ const Init = t.mock('../../lib/init.js', {
...mocks,
'init-package-json': (dir, initFile, config, cb) => cb(
new Error('Unknown Error')
diff --git a/test/lib/install-ci-test.js b/test/lib/install-ci-test.js
index 5f30efcab..2695e0f13 100644
--- a/test/lib/install-ci-test.js
+++ b/test/lib/install-ci-test.js
@@ -24,13 +24,12 @@ const installCITest = new InstallCITest({
})
t.test('the install-ci-test command', t => {
- t.afterEach(cb => {
+ t.afterEach(() => {
ciArgs = null
ciCalled = false
testArgs = null
testCalled = false
ciError = null
- cb()
})
t.test('ci and test', t => {
diff --git a/test/lib/install-test.js b/test/lib/install-test.js
index 0c52bd5e3..adec91b61 100644
--- a/test/lib/install-test.js
+++ b/test/lib/install-test.js
@@ -24,13 +24,12 @@ const installTest = new InstallTest({
})
t.test('the install-test command', t => {
- t.afterEach(cb => {
+ t.afterEach(() => {
installArgs = null
installCalled = false
testArgs = null
testCalled = false
installError = null
- cb()
})
t.test('install and test', t => {
diff --git a/test/lib/install.js b/test/lib/install.js
index 619f0bb34..b7929bdda 100644
--- a/test/lib/install.js
+++ b/test/lib/install.js
@@ -1,16 +1,15 @@
-const { test } = require('tap')
+const t = require('tap')
const Install = require('../../lib/install.js')
-const requireInject = require('require-inject')
const mockNpm = require('../fixtures/mock-npm')
-test('should install using Arborist', (t) => {
+t.test('should install using Arborist', (t) => {
const SCRIPTS = []
let ARB_ARGS = null
let REIFY_CALLED = false
let ARB_OBJ = null
- const Install = requireInject('../../lib/install.js', {
+ const Install = t.mock('../../lib/install.js', {
'@npmcli/run-script': ({ event }) => {
SCRIPTS.push(event)
},
@@ -73,10 +72,10 @@ test('should install using Arborist', (t) => {
t.end()
})
-test('should ignore scripts with --ignore-scripts', (t) => {
+t.test('should ignore scripts with --ignore-scripts', (t) => {
const SCRIPTS = []
let REIFY_CALLED = false
- const Install = requireInject('../../lib/install.js', {
+ const Install = t.mock('../../lib/install.js', {
'../../lib/utils/reify-finish.js': async () => {},
'@npmcli/run-script': ({ event }) => {
SCRIPTS.push(event)
@@ -106,8 +105,8 @@ test('should ignore scripts with --ignore-scripts', (t) => {
})
})
-test('should install globally using Arborist', (t) => {
- const Install = requireInject('../../lib/install.js', {
+t.test('should install globally using Arborist', (t) => {
+ const Install = t.mock('../../lib/install.js', {
'../../lib/utils/reify-finish.js': async () => {},
'@npmcli/arborist': function () {
this.reify = () => {}
@@ -127,8 +126,8 @@ test('should install globally using Arborist', (t) => {
})
})
-test('completion to folder', async t => {
- const Install = requireInject('../../lib/install.js', {
+t.test('completion to folder', async t => {
+ const Install = t.mock('../../lib/install.js', {
'../../lib/utils/reify-finish.js': async () => {},
util: {
promisify: (fn) => fn,
@@ -149,8 +148,8 @@ test('completion to folder', async t => {
t.end()
})
-test('completion to folder - invalid dir', async t => {
- const Install = requireInject('../../lib/install.js', {
+t.test('completion to folder - invalid dir', async t => {
+ const Install = t.mock('../../lib/install.js', {
'../../lib/utils/reify-finish.js': async () => {},
util: {
promisify: (fn) => fn,
@@ -167,8 +166,8 @@ test('completion to folder - invalid dir', async t => {
t.end()
})
-test('completion to folder - no matches', async t => {
- const Install = requireInject('../../lib/install.js', {
+t.test('completion to folder - no matches', async t => {
+ const Install = t.mock('../../lib/install.js', {
'../../lib/utils/reify-finish.js': async () => {},
util: {
promisify: (fn) => fn,
@@ -185,8 +184,8 @@ test('completion to folder - no matches', async t => {
t.end()
})
-test('completion to folder - match is not a package', async t => {
- const Install = requireInject('../../lib/install.js', {
+t.test('completion to folder - match is not a package', async t => {
+ const Install = t.mock('../../lib/install.js', {
'../../lib/utils/reify-finish.js': async () => {},
util: {
promisify: (fn) => fn,
@@ -206,14 +205,14 @@ test('completion to folder - match is not a package', async t => {
t.end()
})
-test('completion to url', async t => {
+t.test('completion to url', async t => {
const install = new Install({})
const res = await install.completion({ partialWord: 'http://path/to/url' })
t.strictSame(res, [])
t.end()
})
-test('completion', async t => {
+t.test('completion', async t => {
const install = new Install({})
const res = await install.completion({ partialWord: 'toto' })
t.notOk(res)
diff --git a/test/lib/link.js b/test/lib/link.js
index 0d96ba0bc..34c533fb7 100644
--- a/test/lib/link.js
+++ b/test/lib/link.js
@@ -2,7 +2,6 @@ const { resolve } = require('path')
const Arborist = require('@npmcli/arborist')
const t = require('tap')
-const requireInject = require('require-inject')
const mockNpm = require('../fixtures/mock-npm')
const redactCwd = (path) => {
@@ -40,7 +39,7 @@ const mocks = {
'../../lib/utils/reify-output.js': () => reifyOutput(),
}
-const Link = requireInject('../../lib/link.js', mocks)
+const Link = t.mock('../../lib/link.js', mocks)
const link = new Link(npm)
t.test('link to globalDir when in current working dir of pkg and no args', (t) => {
@@ -81,7 +80,7 @@ t.test('link to globalDir when in current working dir of pkg and no args', (t) =
}
link.exec([], (err) => {
- t.ifError(err, 'should not error out')
+ t.error(err, 'should not error out')
})
})
@@ -189,7 +188,7 @@ t.test('link global linked pkg to local nm when using args', (t) => {
'a',
'file:../link-me-too',
], (err) => {
- t.ifError(err, 'should not error out')
+ t.error(err, 'should not error out')
})
})
@@ -252,7 +251,7 @@ t.test('link pkg already in global space', (t) => {
// - a: prev installed package available in globalDir
// - file:./link-me-too: pkg that needs to be reified in globalDir first
link.exec(['@myscope/linked'], (err) => {
- t.ifError(err, 'should not error out')
+ t.error(err, 'should not error out')
})
})
@@ -310,7 +309,7 @@ t.test('link pkg already in global space when prefix is a symlink', (t) => {
}
link.exec(['@myscope/linked'], (err) => {
- t.ifError(err, 'should not error out')
+ t.error(err, 'should not error out')
})
})
@@ -330,7 +329,7 @@ t.test('completion', async t => {
npm.globalDir = resolve(testdir, 'global-prefix', 'lib', 'node_modules')
const words = await link.completion({})
- t.deepEqual(
+ t.same(
words,
['bar', 'foo', 'ipsum', 'lorem'],
'should list all package names available in globalDir'
diff --git a/test/lib/ll.js b/test/lib/ll.js
index 45eb4ec95..28a3ab12c 100644
--- a/test/lib/ll.js
+++ b/test/lib/ll.js
@@ -1,4 +1,3 @@
-const requireInject = require('require-inject')
const t = require('tap')
t.test('ll', t => {
@@ -10,12 +9,12 @@ t.test('ll', t => {
}
exec (args, cb) {
- t.deepEqual(args, ['pkg'], 'should forward args')
+ t.same(args, ['pkg'], 'should forward args')
cb()
}
}
- const LL = requireInject('../../lib/ll.js', {
+ const LL = t.mock('../../lib/ll.js', {
'../../lib/ls.js': LS,
})
const ll = new LL({
diff --git a/test/lib/load-all-commands.js b/test/lib/load-all-commands.js
index cb3aefb1f..8267cd543 100644
--- a/test/lib/load-all-commands.js
+++ b/test/lib/load-all-commands.js
@@ -2,9 +2,8 @@
// It does ensure that every command has a usage that renders, contains its
// name, a description, and if it has completion it is a function. That it
// renders also ensures that any params we've defined in our commands work.
-const requireInject = require('require-inject')
-const npm = requireInject('../../lib/npm.js')
const t = require('tap')
+const npm = t.mock('../../lib/npm.js')
const { cmdList } = require('../../lib/utils/cmd-list.js')
let npmOutput = []
@@ -20,8 +19,8 @@ t.test('load each command', t => {
t.test(cmd, t => {
const impl = npm.commands[cmd]
if (impl.completion)
- t.isa(impl.completion, 'function', 'completion, if present, is a function')
- t.isa(impl, 'function', 'implementation is a function')
+ t.type(impl.completion, 'function', 'completion, if present, is a function')
+ t.type(impl, 'function', 'implementation is a function')
t.ok(impl.description, 'implementation has a description')
t.ok(impl.name, 'implementation has a name')
t.match(impl.usage, cmd, 'usage contains the command')
diff --git a/test/lib/logout.js b/test/lib/logout.js
index bae797f96..fb1e281b7 100644
--- a/test/lib/logout.js
+++ b/test/lib/logout.js
@@ -1,6 +1,5 @@
-const requireInject = require('require-inject')
const mockNpm = require('../fixtures/mock-npm')
-const { test } = require('tap')
+const t = require('tap')
const config = {
registry: 'https://registry.npmjs.org/',
@@ -24,10 +23,10 @@ const mocks = {
'npm-registry-fetch': npmFetch,
}
-const Logout = requireInject('../../lib/logout.js', mocks)
+const Logout = t.mock('../../lib/logout.js', mocks)
const logout = new Logout(npm)
-test('token logout', async (t) => {
+t.test('token logout', async (t) => {
t.plan(6)
flatOptions.token = '@foo/'
@@ -55,9 +54,9 @@ test('token logout', async (t) => {
await new Promise((res, rej) => {
logout.exec([], (err) => {
- t.ifError(err, 'should not error out')
+ t.error(err, 'should not error out')
- t.deepEqual(
+ t.same(
result,
{
url: '/-/user/token/%40foo%2F',
@@ -85,7 +84,7 @@ test('token logout', async (t) => {
})
})
-test('token scoped logout', async (t) => {
+t.test('token scoped logout', async (t) => {
t.plan(8)
flatOptions.token = '@foo/'
@@ -126,9 +125,9 @@ test('token scoped logout', async (t) => {
await new Promise((res, rej) => {
logout.exec([], (err) => {
- t.ifError(err, 'should not error out')
+ t.error(err, 'should not error out')
- t.deepEqual(
+ t.same(
result,
{
url: '/-/user/token/%40foo%2F',
@@ -159,7 +158,7 @@ test('token scoped logout', async (t) => {
})
})
-test('user/pass logout', async (t) => {
+t.test('user/pass logout', async (t) => {
t.plan(3)
flatOptions.username = 'foo'
@@ -179,7 +178,7 @@ test('user/pass logout', async (t) => {
await new Promise((res, rej) => {
logout.exec([], (err) => {
- t.ifError(err, 'should not error out')
+ t.error(err, 'should not error out')
delete flatOptions.username
delete flatOptions.password
@@ -192,7 +191,7 @@ test('user/pass logout', async (t) => {
})
})
-test('missing credentials', (t) => {
+t.test('missing credentials', (t) => {
logout.exec([], (err) => {
t.match(
err.message,
@@ -204,7 +203,7 @@ test('missing credentials', (t) => {
})
})
-test('ignore invalid scoped registry config', async (t) => {
+t.test('ignore invalid scoped registry config', async (t) => {
t.plan(5)
flatOptions.token = '@foo/'
@@ -233,9 +232,9 @@ test('ignore invalid scoped registry config', async (t) => {
await new Promise((res, rej) => {
logout.exec([], (err) => {
- t.ifError(err, 'should not error out')
+ t.error(err, 'should not error out')
- t.deepEqual(
+ t.same(
result,
{
url: '/-/user/token/%40foo%2F',
diff --git a/test/lib/ls.js b/test/lib/ls.js
index 5367dec68..6eab0b05b 100644
--- a/test/lib/ls.js
+++ b/test/lib/ls.js
@@ -1,3 +1,7 @@
+// TODO(isaacs): This test has a lot of very large objects pasted inline.
+// Consider using t.matchSnapshot on these instead, especially since many
+// of them contain the tap testdir folders, which are auto-generated and
+// may change when node-tap is updated.
const t = require('tap')
const mockNpm = require('../fixtures/mock-npm')
@@ -115,10 +119,7 @@ const redactCwd = res =>
const jsonParse = res => JSON.parse(redactCwd(res))
-const cleanUpResult = (done, t) => {
- result = ''
- done()
-}
+const cleanUpResult = () => result = ''
t.test('ls', (t) => {
t.beforeEach(cleanUpResult)
@@ -137,7 +138,7 @@ t.test('ls', (t) => {
...simpleNmFixture,
})
ls.exec([], (err) => {
- t.ifError(err, 'npm ls')
+ t.error(err, 'npm ls')
t.matchSnapshot(redactCwd(result), 'should output tree representation of dependencies structure')
t.end()
})
@@ -173,7 +174,7 @@ t.test('ls', (t) => {
t.equal(err.code, 'ELSPROBLEMS', 'should have error code')
t.equal(
redactCwd(err.message),
- 'extraneous: lorem@1.0.0 {CWD}/ls-ls-extraneous-deps/node_modules/lorem',
+ 'extraneous: lorem@1.0.0 {CWD}/tap-testdir-ls-ls-extraneous-deps/node_modules/lorem',
'should log extraneous dep as error'
)
t.matchSnapshot(redactCwd(result), 'should output containing problems info')
@@ -195,7 +196,7 @@ t.test('ls', (t) => {
...simpleNmFixture,
})
ls.exec(['lorem'], (err) => {
- t.ifError(err, 'npm ls')
+ t.error(err, 'npm ls')
t.matchSnapshot(redactCwd(result), 'should output tree contaning only occurrences of filtered by package and colored output')
npm.color = false
t.end()
@@ -217,7 +218,7 @@ t.test('ls', (t) => {
...simpleNmFixture,
})
ls.exec(['.'], (err) => {
- t.ifError(err, 'should not throw on missing dep above current level')
+ t.error(err, 'should not throw on missing dep above current level')
t.matchSnapshot(redactCwd(result), 'should output tree contaning only occurrences of filtered by package and colored output')
config.all = true
config.depth = Infinity
@@ -238,7 +239,7 @@ t.test('ls', (t) => {
...simpleNmFixture,
})
ls.exec(['bar'], (err) => {
- t.ifError(err, 'npm ls')
+ t.error(err, 'npm ls')
t.matchSnapshot(redactCwd(result), 'should output tree contaning only occurrences of filtered package and its ancestors')
t.end()
})
@@ -266,7 +267,7 @@ t.test('ls', (t) => {
},
})
ls.exec(['bar@*', 'lorem@1.0.0'], (err) => {
- t.ifError(err, 'npm ls')
+ t.error(err, 'npm ls')
t.matchSnapshot(redactCwd(result), 'should output tree contaning only occurrences of multiple filtered packages and their ancestors')
t.end()
})
@@ -285,7 +286,7 @@ t.test('ls', (t) => {
...simpleNmFixture,
})
ls.exec(['notadep'], (err) => {
- t.ifError(err, 'npm ls')
+ t.error(err, 'npm ls')
t.matchSnapshot(redactCwd(result), 'should output tree containing no dependencies info')
t.equal(
process.exitCode,
@@ -312,7 +313,7 @@ t.test('ls', (t) => {
...simpleNmFixture,
})
ls.exec([], (err) => {
- t.ifError(err, 'npm ls')
+ t.error(err, 'npm ls')
t.matchSnapshot(redactCwd(result), 'should output tree containing only top-level dependencies')
config.all = true
config.depth = Infinity
@@ -335,7 +336,7 @@ t.test('ls', (t) => {
...simpleNmFixture,
})
ls.exec([], (err) => {
- t.ifError(err, 'npm ls')
+ t.error(err, 'npm ls')
t.matchSnapshot(redactCwd(result), 'should output tree containing only top-level dependencies')
config.all = true
config.depth = Infinity
@@ -396,7 +397,7 @@ t.test('ls', (t) => {
},
})
ls.exec([], (err) => {
- t.ifError(err, 'npm ls')
+ t.error(err, 'npm ls')
t.matchSnapshot(redactCwd(result), 'should output tree containing top-level deps and their deps only')
config.all = true
config.depth = Infinity
@@ -420,9 +421,9 @@ t.test('ls', (t) => {
t.equal(err.code, 'ELSPROBLEMS', 'should have error code')
t.equal(
redactCwd(err.message).replace(/\r\n/g, '\n'),
- 'invalid: foo@1.0.0 {CWD}/ls-ls-missing-invalid-extraneous/node_modules/foo\n' +
+ 'invalid: foo@1.0.0 {CWD}/tap-testdir-ls-ls-missing-invalid-extraneous/node_modules/foo\n' +
'missing: ipsum@^1.0.0, required by test-npm-ls@1.0.0\n' +
- 'extraneous: lorem@1.0.0 {CWD}/ls-ls-missing-invalid-extraneous/node_modules/lorem',
+ 'extraneous: lorem@1.0.0 {CWD}/tap-testdir-ls-ls-missing-invalid-extraneous/node_modules/lorem',
'should log missing/invalid/extraneous errors'
)
t.matchSnapshot(redactCwd(result), 'should output tree containing missing, invalid, extraneous labels')
@@ -718,7 +719,7 @@ t.test('ls', (t) => {
t.test('empty location', (t) => {
npm.prefix = t.testdir({})
ls.exec([], (err) => {
- t.ifError(err, 'should not error out on empty locations')
+ t.error(err, 'should not error out on empty locations')
t.matchSnapshot(redactCwd(result), 'should print empty result')
t.end()
})
@@ -898,7 +899,7 @@ t.test('ls', (t) => {
},
})
ls.exec([], (err) => {
- t.ifError(err, 'npm ls')
+ t.error(err, 'npm ls')
t.matchSnapshot(redactCwd(result), 'should print tree output containing deduped ref')
t.end()
})
@@ -936,7 +937,7 @@ t.test('ls', (t) => {
},
})
ls.exec(['a'], (err) => {
- t.ifError(err, 'npm ls')
+ t.error(err, 'npm ls')
t.matchSnapshot(redactCwd(result), 'should print tree output containing deduped ref')
npm.color = false
t.end()
@@ -984,7 +985,7 @@ t.test('ls', (t) => {
},
})
ls.exec([], (err) => {
- t.ifError(err, 'npm ls')
+ t.error(err, 'npm ls')
t.matchSnapshot(redactCwd(result), 'should print tree output containing deduped ref')
t.end()
})
@@ -1033,7 +1034,7 @@ t.test('ls', (t) => {
},
})
ls.exec([], (err) => {
- t.ifError(err, 'npm ls')
+ t.error(err, 'npm ls')
t.matchSnapshot(redactCwd(result), 'should print tree output containing deduped ref')
config.all = true
config.depth = Infinity
@@ -1083,7 +1084,7 @@ t.test('ls', (t) => {
},
})
ls.exec(['@npmcli/b'], (err) => {
- t.ifError(err, 'npm ls')
+ t.error(err, 'npm ls')
t.matchSnapshot(redactCwd(result), 'should print tree output containing deduped ref')
npm.color = false
t.end()
@@ -1131,7 +1132,7 @@ t.test('ls', (t) => {
},
})
ls.exec(['@npmcli/c'], (err) => {
- t.ifError(err, 'npm ls')
+ t.error(err, 'npm ls')
t.matchSnapshot(redactCwd(result), 'should print tree output containing deduped ref')
t.end()
})
@@ -1221,7 +1222,7 @@ t.test('ls', (t) => {
})
touchHiddenPackageLock(npm.prefix)
ls.exec([], (err) => {
- t.ifError(err, 'npm ls')
+ t.error(err, 'npm ls')
t.matchSnapshot(redactCwd(result), 'should output tree containing git refs')
t.end()
})
@@ -1265,7 +1266,7 @@ t.test('ls', (t) => {
}),
})
ls.exec([], (err) => {
- t.ifError(err, 'npm ls')
+ t.error(err, 'npm ls')
t.matchSnapshot(redactCwd(result), 'should NOT print git refs in output tree')
t.end()
})
@@ -1453,12 +1454,12 @@ t.test('ls', (t) => {
})
ls.exec([], (err) => {
- t.ifError(err, 'should NOT have ELSPROBLEMS error code')
+ t.error(err, 'should NOT have ELSPROBLEMS error code')
t.matchSnapshot(redactCwd(result), 'should list workspaces properly')
// should also be able to filter out one of the workspaces
ls.exec(['a'], (err) => {
- t.ifError(err, 'should NOT have ELSPROBLEMS error code when filter')
+ t.error(err, 'should NOT have ELSPROBLEMS error code when filter')
t.matchSnapshot(redactCwd(result), 'should filter single workspace')
t.end()
@@ -1516,17 +1517,17 @@ t.test('ls', (t) => {
t.plan(6)
ls.exec(['a'], (err) => {
- t.ifError(err, 'should NOT have ELSPROBLEMS error code')
+ t.error(err, 'should NOT have ELSPROBLEMS error code')
t.matchSnapshot(redactCwd(result), 'should list a in top-level only')
ls.exec(['d'], (err) => {
- t.ifError(err, 'should NOT have ELSPROBLEMS error code when filter')
+ t.error(err, 'should NOT have ELSPROBLEMS error code when filter')
t.matchSnapshot(redactCwd(result), 'should print empty results msg')
// if no --depth config is defined, should print path to dep
config.depth = null // default config value
ls.exec(['d'], (err) => {
- t.ifError(err, 'should NOT have ELSPROBLEMS error code when filter')
+ t.error(err, 'should NOT have ELSPROBLEMS error code when filter')
t.matchSnapshot(redactCwd(result), 'should print expected result')
})
})
@@ -1558,7 +1559,7 @@ t.test('ls --parseable', (t) => {
...simpleNmFixture,
})
ls.exec([], (err) => {
- t.ifError(err, 'npm ls')
+ t.error(err, 'npm ls')
t.matchSnapshot(redactCwd(result), 'should output parseable representation of dependencies structure')
t.end()
})
@@ -1610,7 +1611,7 @@ t.test('ls --parseable', (t) => {
...simpleNmFixture,
})
ls.exec(['lorem'], (err) => {
- t.ifError(err, 'npm ls')
+ t.error(err, 'npm ls')
t.matchSnapshot(redactCwd(result), 'should output parseable contaning only occurrences of filtered by package')
t.end()
})
@@ -1629,7 +1630,7 @@ t.test('ls --parseable', (t) => {
...simpleNmFixture,
})
ls.exec(['bar'], (err) => {
- t.ifError(err, 'npm ls')
+ t.error(err, 'npm ls')
t.matchSnapshot(redactCwd(result), 'should output parseable contaning only occurrences of filtered package')
t.end()
})
@@ -1657,7 +1658,7 @@ t.test('ls --parseable', (t) => {
},
})
ls.exec(['bar@*', 'lorem@1.0.0'], (err) => {
- t.ifError(err, 'npm ls')
+ t.error(err, 'npm ls')
t.matchSnapshot(redactCwd(result), 'should output parseable contaning only occurrences of multiple filtered packages and their ancestors')
t.end()
})
@@ -1676,7 +1677,7 @@ t.test('ls --parseable', (t) => {
...simpleNmFixture,
})
ls.exec(['notadep'], (err) => {
- t.ifError(err, 'npm ls')
+ t.error(err, 'npm ls')
t.matchSnapshot(redactCwd(result), 'should output parseable output containing no dependencies info')
t.equal(
process.exitCode,
@@ -1703,7 +1704,7 @@ t.test('ls --parseable', (t) => {
...simpleNmFixture,
})
ls.exec([], (err) => {
- t.ifError(err, 'npm ls')
+ t.error(err, 'npm ls')
t.matchSnapshot(redactCwd(result), 'should output parseable output containing only top-level dependencies')
config.all = true
config.depth = Infinity
@@ -1726,7 +1727,7 @@ t.test('ls --parseable', (t) => {
...simpleNmFixture,
})
ls.exec([], (err) => {
- t.ifError(err, 'npm ls')
+ t.error(err, 'npm ls')
t.matchSnapshot(redactCwd(result), 'should output tree containing only top-level dependencies')
config.all = true
config.depth = Infinity
@@ -1749,7 +1750,7 @@ t.test('ls --parseable', (t) => {
...simpleNmFixture,
})
ls.exec([], (err) => {
- t.ifError(err, 'npm ls')
+ t.error(err, 'npm ls')
t.matchSnapshot(redactCwd(result), 'should output parseable containing top-level deps and their deps only')
config.all = true
config.depth = Infinity
@@ -1973,7 +1974,7 @@ t.test('ls --parseable', (t) => {
})
ls.exec([], (err) => {
t.equal(err.code, 'ELSPROBLEMS', 'should have error code')
- t.match(redactCwd(err.message), 'extraneous: lorem@1.0.0 {CWD}/ls-ls-parseable--long-with-extraneous-deps/node_modules/lorem', 'should have error code')
+ t.match(redactCwd(err.message), 'extraneous: lorem@1.0.0 {CWD}/tap-testdir-ls-ls---parseable---long-with-extraneous-deps/node_modules/lorem', 'should have error code')
t.matchSnapshot(redactCwd(result), 'should output long parseable output with extraneous info')
t.end()
})
@@ -2033,7 +2034,7 @@ t.test('ls --parseable', (t) => {
},
})
ls.exec([], (err) => {
- t.ifError(err, 'npm ls')
+ t.error(err, 'npm ls')
t.matchSnapshot(redactCwd(result), 'should output parseable results with symlink targets')
config.long = false
t.end()
@@ -2087,7 +2088,7 @@ t.test('ls --parseable', (t) => {
t.test('empty location', (t) => {
npm.prefix = t.testdir({})
ls.exec([], (err) => {
- t.ifError(err, 'should not error out on empty locations')
+ t.error(err, 'should not error out on empty locations')
t.matchSnapshot(redactCwd(result), 'should print empty result')
t.end()
})
@@ -2382,8 +2383,8 @@ t.test('ls --json', (t) => {
...simpleNmFixture,
})
ls.exec([], (err) => {
- t.ifError(err, 'npm ls')
- t.deepEqual(
+ t.error(err, 'npm ls')
+ t.same(
jsonParse(result),
{
name: 'test-npm-ls',
@@ -2414,27 +2415,27 @@ t.test('ls --json', (t) => {
})
ls.exec([], (err) => {
t.match(err, { code: 'ELSPROBLEMS' }, 'should list dep problems')
- t.deepEqual(
+ t.same(
jsonParse(result),
{
problems: [
- 'extraneous: bar@1.0.0 {CWD}/ls-ls-json-missing-package-json/node_modules/bar',
- 'extraneous: foo@1.0.0 {CWD}/ls-ls-json-missing-package-json/node_modules/foo',
- 'extraneous: lorem@1.0.0 {CWD}/ls-ls-json-missing-package-json/node_modules/lorem',
+ 'extraneous: bar@1.0.0 {CWD}/tap-testdir-ls-ls---json-missing-package.json/node_modules/bar',
+ 'extraneous: foo@1.0.0 {CWD}/tap-testdir-ls-ls---json-missing-package.json/node_modules/foo',
+ 'extraneous: lorem@1.0.0 {CWD}/tap-testdir-ls-ls---json-missing-package.json/node_modules/lorem',
],
dependencies: {
bar: {
version: '1.0.0',
extraneous: true,
problems: [
- 'extraneous: bar@1.0.0 {CWD}/ls-ls-json-missing-package-json/node_modules/bar',
+ 'extraneous: bar@1.0.0 {CWD}/tap-testdir-ls-ls---json-missing-package.json/node_modules/bar',
],
},
foo: {
version: '1.0.0',
extraneous: true,
problems: [
- 'extraneous: foo@1.0.0 {CWD}/ls-ls-json-missing-package-json/node_modules/foo',
+ 'extraneous: foo@1.0.0 {CWD}/tap-testdir-ls-ls---json-missing-package.json/node_modules/foo',
],
dependencies: {
bar: {
@@ -2446,7 +2447,7 @@ t.test('ls --json', (t) => {
version: '1.0.0',
extraneous: true,
problems: [
- 'extraneous: lorem@1.0.0 {CWD}/ls-ls-json-missing-package-json/node_modules/lorem',
+ 'extraneous: lorem@1.0.0 {CWD}/tap-testdir-ls-ls---json-missing-package.json/node_modules/lorem',
],
},
},
@@ -2471,7 +2472,7 @@ t.test('ls --json', (t) => {
ls.exec([], (err) => {
t.equal(
redactCwd(err.message),
- 'extraneous: lorem@1.0.0 {CWD}/ls-ls-json-extraneous-deps/node_modules/lorem',
+ 'extraneous: lorem@1.0.0 {CWD}/tap-testdir-ls-ls---json-extraneous-deps/node_modules/lorem',
'should log extraneous dep as error'
)
t.equal(
@@ -2479,13 +2480,13 @@ t.test('ls --json', (t) => {
'ELSPROBLEMS',
'should have ELSPROBLEMS error code'
)
- t.deepEqual(
+ t.same(
jsonParse(result),
{
name: 'test-npm-ls',
version: '1.0.0',
problems: [
- 'extraneous: lorem@1.0.0 {CWD}/ls-ls-json-extraneous-deps/node_modules/lorem',
+ 'extraneous: lorem@1.0.0 {CWD}/tap-testdir-ls-ls---json-extraneous-deps/node_modules/lorem',
],
dependencies: {
foo: {
@@ -2500,7 +2501,7 @@ t.test('ls --json', (t) => {
version: '1.0.0',
extraneous: true,
problems: [
- 'extraneous: lorem@1.0.0 {CWD}/ls-ls-json-extraneous-deps/node_modules/lorem',
+ 'extraneous: lorem@1.0.0 {CWD}/tap-testdir-ls-ls---json-extraneous-deps/node_modules/lorem',
],
},
},
@@ -2524,8 +2525,8 @@ t.test('ls --json', (t) => {
...simpleNmFixture,
})
ls.exec(['lorem'], (err) => {
- t.ifError(err, 'npm ls')
- t.deepEqual(
+ t.error(err, 'npm ls')
+ t.same(
jsonParse(result),
{
name: 'test-npm-ls',
@@ -2560,8 +2561,8 @@ t.test('ls --json', (t) => {
...simpleNmFixture,
})
ls.exec(['bar'], (err) => {
- t.ifError(err, 'npm ls')
- t.deepEqual(
+ t.error(err, 'npm ls')
+ t.same(
jsonParse(result),
{
name: 'test-npm-ls',
@@ -2605,8 +2606,8 @@ t.test('ls --json', (t) => {
},
})
ls.exec(['bar@*', 'lorem@1.0.0'], (err) => {
- t.ifError(err, 'npm ls')
- t.deepEqual(
+ t.error(err, 'npm ls')
+ t.same(
jsonParse(result),
{
version: '1.0.0',
@@ -2644,8 +2645,8 @@ t.test('ls --json', (t) => {
...simpleNmFixture,
})
ls.exec(['notadep'], (err) => {
- t.ifError(err, 'npm ls')
- t.deepEqual(
+ t.error(err, 'npm ls')
+ t.same(
jsonParse(result),
{
name: 'test-npm-ls',
@@ -2678,8 +2679,8 @@ t.test('ls --json', (t) => {
...simpleNmFixture,
})
ls.exec([], (err) => {
- t.ifError(err, 'npm ls')
- t.deepEqual(
+ t.error(err, 'npm ls')
+ t.same(
jsonParse(result),
{
name: 'test-npm-ls',
@@ -2716,8 +2717,8 @@ t.test('ls --json', (t) => {
...simpleNmFixture,
})
ls.exec([], (err) => {
- t.ifError(err, 'npm ls')
- t.deepEqual(
+ t.error(err, 'npm ls')
+ t.same(
jsonParse(result),
{
name: 'test-npm-ls',
@@ -2754,8 +2755,8 @@ t.test('ls --json', (t) => {
...simpleNmFixture,
})
ls.exec([], (err) => {
- t.ifError(err, 'npm ls')
- t.deepEqual(
+ t.error(err, 'npm ls')
+ t.same(
jsonParse(result),
{
name: 'test-npm-ls',
@@ -2796,22 +2797,22 @@ t.test('ls --json', (t) => {
})
ls.exec([], (err) => {
t.match(err, { code: 'ELSPROBLEMS' }, 'should list dep problems')
- t.deepEqual(
+ t.same(
jsonParse(result),
{
name: 'test-npm-ls',
version: '1.0.0',
problems: [
- 'invalid: foo@1.0.0 {CWD}/ls-ls-json-missing-invalid-extraneous/node_modules/foo',
+ 'invalid: foo@1.0.0 {CWD}/tap-testdir-ls-ls---json-missing-invalid-extraneous/node_modules/foo',
'missing: ipsum@^1.0.0, required by test-npm-ls@1.0.0',
- 'extraneous: lorem@1.0.0 {CWD}/ls-ls-json-missing-invalid-extraneous/node_modules/lorem',
+ 'extraneous: lorem@1.0.0 {CWD}/tap-testdir-ls-ls---json-missing-invalid-extraneous/node_modules/lorem',
],
dependencies: {
foo: {
version: '1.0.0',
invalid: true,
problems: [
- 'invalid: foo@1.0.0 {CWD}/ls-ls-json-missing-invalid-extraneous/node_modules/foo',
+ 'invalid: foo@1.0.0 {CWD}/tap-testdir-ls-ls---json-missing-invalid-extraneous/node_modules/foo',
],
dependencies: {
bar: {
@@ -2823,7 +2824,7 @@ t.test('ls --json', (t) => {
version: '1.0.0',
extraneous: true,
problems: [
- 'extraneous: lorem@1.0.0 {CWD}/ls-ls-json-missing-invalid-extraneous/node_modules/lorem',
+ 'extraneous: lorem@1.0.0 {CWD}/tap-testdir-ls-ls---json-missing-invalid-extraneous/node_modules/lorem',
],
},
ipsum: {
@@ -2864,7 +2865,7 @@ t.test('ls --json', (t) => {
...diffDepTypesNmFixture,
})
ls.exec([], () => {
- t.deepEqual(
+ t.same(
jsonParse(result),
{
name: 'test-npm-ls',
@@ -2911,7 +2912,7 @@ t.test('ls --json', (t) => {
...diffDepTypesNmFixture,
})
ls.exec([], () => {
- t.deepEqual(
+ t.same(
jsonParse(result),
{
name: 'test-npm-ls',
@@ -2968,7 +2969,7 @@ t.test('ls --json', (t) => {
},
})
ls.exec([], () => {
- t.deepEqual(
+ t.same(
jsonParse(result),
{
name: 'test-npm-ls',
@@ -3010,7 +3011,7 @@ t.test('ls --json', (t) => {
...diffDepTypesNmFixture,
})
ls.exec([], () => {
- t.deepEqual(
+ t.same(
jsonParse(result),
{
name: 'test-npm-ls',
@@ -3051,7 +3052,7 @@ t.test('ls --json', (t) => {
...diffDepTypesNmFixture,
})
ls.exec([], () => {
- t.deepEqual(
+ t.same(
jsonParse(result),
{
name: 'test-npm-ls',
@@ -3164,7 +3165,7 @@ t.test('ls --json', (t) => {
}),
})
ls.exec([], () => {
- t.deepEqual(
+ t.same(
jsonParse(result),
{
version: '1.0.0',
@@ -3178,7 +3179,7 @@ t.test('ls --json', (t) => {
resolved: 'https://registry.npmjs.org/@isaacs/dedupe-tests-b/-/dedupe-tests-b-1.0.0.tgz',
extraneous: true,
problems: [
- 'extraneous: @isaacs/dedupe-tests-b@ {CWD}/ls-ls-json-from-lockfile/node_modules/@isaacs/dedupe-tests-a/node_modules/@isaacs/dedupe-tests-b',
+ 'extraneous: @isaacs/dedupe-tests-b@ {CWD}/tap-testdir-ls-ls---json-from-lockfile/node_modules/@isaacs/dedupe-tests-a/node_modules/@isaacs/dedupe-tests-b',
],
},
},
@@ -3189,7 +3190,7 @@ t.test('ls --json', (t) => {
},
},
problems: [
- 'extraneous: @isaacs/dedupe-tests-b@ {CWD}/ls-ls-json-from-lockfile/node_modules/@isaacs/dedupe-tests-a/node_modules/@isaacs/dedupe-tests-b',
+ 'extraneous: @isaacs/dedupe-tests-b@ {CWD}/tap-testdir-ls-ls---json-from-lockfile/node_modules/@isaacs/dedupe-tests-a/node_modules/@isaacs/dedupe-tests-b',
],
},
'should output json containing only prod deps'
@@ -3221,7 +3222,7 @@ t.test('ls --json', (t) => {
...diffDepTypesNmFixture,
})
ls.exec([], () => {
- t.deepEqual(
+ t.same(
jsonParse(result),
{
name: 'test-npm-ls',
@@ -3235,7 +3236,7 @@ t.test('ls --json', (t) => {
devDependencies: {},
peerDependencies: {},
_dependencies: {},
- path: '{CWD}/ls-ls-json--long/node_modules/peer-dep',
+ path: '{CWD}/tap-testdir-ls-ls---json---long/node_modules/peer-dep',
extraneous: false,
},
'dev-dep': {
@@ -3254,7 +3255,7 @@ t.test('ls --json', (t) => {
devDependencies: {},
peerDependencies: {},
_dependencies: {},
- path: '{CWD}/ls-ls-json--long/node_modules/bar',
+ path: '{CWD}/tap-testdir-ls-ls---json---long/node_modules/bar',
extraneous: false,
},
},
@@ -3262,7 +3263,7 @@ t.test('ls --json', (t) => {
devDependencies: {},
peerDependencies: {},
_dependencies: { bar: '^1.0.0' },
- path: '{CWD}/ls-ls-json--long/node_modules/foo',
+ path: '{CWD}/tap-testdir-ls-ls---json---long/node_modules/foo',
extraneous: false,
},
},
@@ -3270,7 +3271,7 @@ t.test('ls --json', (t) => {
devDependencies: {},
peerDependencies: {},
_dependencies: { foo: '^1.0.0' },
- path: '{CWD}/ls-ls-json--long/node_modules/dev-dep',
+ path: '{CWD}/tap-testdir-ls-ls---json---long/node_modules/dev-dep',
extraneous: false,
},
lorem: {
@@ -3280,7 +3281,7 @@ t.test('ls --json', (t) => {
devDependencies: {},
peerDependencies: {},
_dependencies: {},
- path: '{CWD}/ls-ls-json--long/node_modules/lorem',
+ path: '{CWD}/tap-testdir-ls-ls---json---long/node_modules/lorem',
extraneous: false,
},
'optional-dep': {
@@ -3291,7 +3292,7 @@ t.test('ls --json', (t) => {
devDependencies: {},
peerDependencies: {},
_dependencies: {},
- path: '{CWD}/ls-ls-json--long/node_modules/optional-dep',
+ path: '{CWD}/tap-testdir-ls-ls---json---long/node_modules/optional-dep',
extraneous: false,
},
'prod-dep': {
@@ -3307,7 +3308,7 @@ t.test('ls --json', (t) => {
devDependencies: {},
peerDependencies: {},
_dependencies: {},
- path: '{CWD}/ls-ls-json--long/node_modules/prod-dep/node_modules/bar',
+ path: '{CWD}/tap-testdir-ls-ls---json---long/node_modules/prod-dep/node_modules/bar',
extraneous: false,
},
},
@@ -3315,7 +3316,7 @@ t.test('ls --json', (t) => {
devDependencies: {},
peerDependencies: {},
_dependencies: { bar: '^2.0.0' },
- path: '{CWD}/ls-ls-json--long/node_modules/prod-dep',
+ path: '{CWD}/tap-testdir-ls-ls---json---long/node_modules/prod-dep',
extraneous: false,
},
},
@@ -3324,7 +3325,7 @@ t.test('ls --json', (t) => {
peerDependencies: { 'peer-dep': '^1.0.0' },
_id: 'test-npm-ls@1.0.0',
_dependencies: { 'prod-dep': '^1.0.0', lorem: '^1.0.0', 'optional-dep': '^1.0.0' },
- path: '{CWD}/ls-ls-json--long',
+ path: '{CWD}/tap-testdir-ls-ls---json---long',
extraneous: false,
},
'should output long json info'
@@ -3359,7 +3360,7 @@ t.test('ls --json', (t) => {
...diffDepTypesNmFixture,
})
ls.exec([], () => {
- t.deepEqual(
+ t.same(
jsonParse(result),
{
name: 'test-npm-ls',
@@ -3373,7 +3374,7 @@ t.test('ls --json', (t) => {
devDependencies: {},
peerDependencies: {},
_dependencies: {},
- path: '{CWD}/ls-ls-json--long-depth-0/node_modules/peer-dep',
+ path: '{CWD}/tap-testdir-ls-ls---json---long---depth-0/node_modules/peer-dep',
extraneous: false,
},
'dev-dep': {
@@ -3384,7 +3385,7 @@ t.test('ls --json', (t) => {
devDependencies: {},
peerDependencies: {},
_dependencies: { foo: '^1.0.0' },
- path: '{CWD}/ls-ls-json--long-depth-0/node_modules/dev-dep',
+ path: '{CWD}/tap-testdir-ls-ls---json---long---depth-0/node_modules/dev-dep',
extraneous: false,
},
lorem: {
@@ -3394,7 +3395,7 @@ t.test('ls --json', (t) => {
devDependencies: {},
peerDependencies: {},
_dependencies: {},
- path: '{CWD}/ls-ls-json--long-depth-0/node_modules/lorem',
+ path: '{CWD}/tap-testdir-ls-ls---json---long---depth-0/node_modules/lorem',
extraneous: false,
},
'optional-dep': {
@@ -3405,7 +3406,7 @@ t.test('ls --json', (t) => {
devDependencies: {},
peerDependencies: {},
_dependencies: {},
- path: '{CWD}/ls-ls-json--long-depth-0/node_modules/optional-dep',
+ path: '{CWD}/tap-testdir-ls-ls---json---long---depth-0/node_modules/optional-dep',
extraneous: false,
},
'prod-dep': {
@@ -3416,7 +3417,7 @@ t.test('ls --json', (t) => {
devDependencies: {},
peerDependencies: {},
_dependencies: { bar: '^2.0.0' },
- path: '{CWD}/ls-ls-json--long-depth-0/node_modules/prod-dep',
+ path: '{CWD}/tap-testdir-ls-ls---json---long---depth-0/node_modules/prod-dep',
extraneous: false,
},
},
@@ -3425,7 +3426,7 @@ t.test('ls --json', (t) => {
peerDependencies: { 'peer-dep': '^1.0.0' },
_id: 'test-npm-ls@1.0.0',
_dependencies: { 'prod-dep': '^1.0.0', lorem: '^1.0.0', 'optional-dep': '^1.0.0' },
- path: '{CWD}/ls-ls-json--long-depth-0',
+ path: '{CWD}/tap-testdir-ls-ls---json---long---depth-0',
extraneous: false,
},
'should output json containing top-level deps in long format'
@@ -3444,12 +3445,12 @@ t.test('ls --json', (t) => {
ls.exec([], (err) => {
t.match(err.message, 'Failed to parse root package.json', 'should have missin root package.json msg')
t.match(err.code, 'EJSONPARSE', 'should have EJSONPARSE error code')
- t.deepEqual(
+ t.same(
jsonParse(result),
{
invalid: true,
problems: [
- 'error in {CWD}/ls-ls-json-json-read-problems: Failed to parse root package.json',
+ 'error in {CWD}/tap-testdir-ls-ls---json-json-read-problems: Failed to parse root package.json',
],
},
'should print empty json result'
@@ -3461,8 +3462,8 @@ t.test('ls --json', (t) => {
t.test('empty location', (t) => {
npm.prefix = t.testdir({})
ls.exec([], (err) => {
- t.ifError(err, 'should not error out on empty locations')
- t.deepEqual(
+ t.error(err, 'should not error out on empty locations')
+ t.same(
jsonParse(result),
{},
'should print empty json result'
@@ -3494,20 +3495,20 @@ t.test('ls --json', (t) => {
})
ls.exec([], (err) => {
t.match(err.code, 'ELSPROBLEMS', 'Should have ELSPROBLEMS error code')
- t.deepEqual(
+ t.same(
jsonParse(result),
{
name: 'test-npm-ls',
version: '1.0.0',
problems: [
- 'invalid: peer-dep@1.0.0 {CWD}/ls-ls-json-unmet-peer-dep/node_modules/peer-dep',
+ 'invalid: peer-dep@1.0.0 {CWD}/tap-testdir-ls-ls---json-unmet-peer-dep/node_modules/peer-dep',
],
dependencies: {
'peer-dep': {
version: '1.0.0',
invalid: true,
problems: [
- 'invalid: peer-dep@1.0.0 {CWD}/ls-ls-json-unmet-peer-dep/node_modules/peer-dep',
+ 'invalid: peer-dep@1.0.0 {CWD}/tap-testdir-ls-ls---json-unmet-peer-dep/node_modules/peer-dep',
],
},
'dev-dep': {
@@ -3555,20 +3556,20 @@ t.test('ls --json', (t) => {
ls.exec([], (err) => {
t.match(err.code, 'ELSPROBLEMS', 'should have ELSPROBLEMS error code')
t.match(err.message, /invalid: optional-dep@1.0.0/, 'should have invalid dep error msg')
- t.deepEqual(
+ t.same(
jsonParse(result),
{
name: 'test-npm-ls',
version: '1.0.0',
problems: [
- 'invalid: optional-dep@1.0.0 {CWD}/ls-ls-json-unmet-optional-dep/node_modules/optional-dep', // mismatching optional deps get flagged in problems
+ 'invalid: optional-dep@1.0.0 {CWD}/tap-testdir-ls-ls---json-unmet-optional-dep/node_modules/optional-dep', // mismatching optional deps get flagged in problems
],
dependencies: {
'optional-dep': {
version: '1.0.0',
invalid: true,
problems: [
- 'invalid: optional-dep@1.0.0 {CWD}/ls-ls-json-unmet-optional-dep/node_modules/optional-dep',
+ 'invalid: optional-dep@1.0.0 {CWD}/tap-testdir-ls-ls---json-unmet-optional-dep/node_modules/optional-dep',
],
},
'peer-dep': {
@@ -3625,7 +3626,7 @@ t.test('ls --json', (t) => {
},
})
ls.exec([], () => {
- t.deepEqual(
+ t.same(
jsonParse(result),
{
name: 'test-npm-ls',
@@ -3683,7 +3684,7 @@ t.test('ls --json', (t) => {
})
touchHiddenPackageLock(npm.prefix)
ls.exec([], () => {
- t.deepEqual(
+ t.same(
jsonParse(result),
{
name: 'test-npm-ls',
@@ -3743,7 +3744,7 @@ t.test('ls --json', (t) => {
})
touchHiddenPackageLock(npm.prefix)
ls.exec([], () => {
- t.deepEqual(
+ t.same(
jsonParse(result),
{
name: 'test-npm-ls',
@@ -3827,7 +3828,7 @@ t.test('ls --json', (t) => {
})
touchHiddenPackageLock(npm.prefix)
ls.exec([], () => {
- t.deepEqual(
+ t.same(
jsonParse(result),
{
name: 'test-npm-ls',
@@ -3852,11 +3853,11 @@ t.test('ls --json', (t) => {
}),
})
ls.exec([], () => {
- t.deepEqual(
+ t.same(
jsonParse(result),
{
version: '1.0.0',
- name: 'ls-ls-json-node-name-fallback-if-missing-root-package-name',
+ name: 'tap-testdir-ls-ls---json-node.name-fallback-if-missing-root-package-name',
},
'should use node.name as key in json result obj'
)
@@ -3895,10 +3896,10 @@ t.test('ls --json', (t) => {
npm.globalDir = resolve(fixtures, 'node_modules')
ls.exec([], () => {
- t.deepEqual(
+ t.same(
jsonParse(result),
{
- name: 'ls-ls-json-global',
+ name: 'tap-testdir-ls-ls---json-global',
dependencies: {
a: {
version: '1.0.0',
diff --git a/test/lib/npm.js b/test/lib/npm.js
index 4d40792af..6f8f8936d 100644
--- a/test/lib/npm.js
+++ b/test/lib/npm.js
@@ -174,34 +174,34 @@ t.test('npm.load', t => {
t.equal(npm.log, npmlog, 'npmlog getter')
t.equal(npm.lockfileVersion, 2, 'lockfileVersion getter')
t.equal(npm.prefix, npm.localPrefix, 'prefix is local prefix')
- t.notEqual(npm.prefix, npm.globalPrefix, 'prefix is not global prefix')
+ t.not(npm.prefix, npm.globalPrefix, 'prefix is not global prefix')
npm.globalPrefix = npm.prefix
t.equal(npm.prefix, npm.globalPrefix, 'globalPrefix setter')
npm.localPrefix = dir + '/extra/prefix'
t.equal(npm.prefix, npm.localPrefix, 'prefix is local prefix after localPrefix setter')
- t.notEqual(npm.prefix, npm.globalPrefix, 'prefix is not global prefix after localPrefix setter')
+ t.not(npm.prefix, npm.globalPrefix, 'prefix is not global prefix after localPrefix setter')
npm.prefix = dir + '/some/prefix'
t.equal(npm.prefix, npm.localPrefix, 'prefix is local prefix after prefix setter')
- t.notEqual(npm.prefix, npm.globalPrefix, 'prefix is not global prefix after prefix setter')
+ t.not(npm.prefix, npm.globalPrefix, 'prefix is not global prefix after prefix setter')
t.equal(npm.bin, npm.localBin, 'bin is local bin after prefix setter')
- t.notEqual(npm.bin, npm.globalBin, 'bin is not global bin after prefix setter')
+ t.not(npm.bin, npm.globalBin, 'bin is not global bin after prefix setter')
t.equal(npm.dir, npm.localDir, 'dir is local dir after prefix setter')
- t.notEqual(npm.dir, npm.globalDir, 'dir is not global dir after prefix setter')
+ t.not(npm.dir, npm.globalDir, 'dir is not global dir after prefix setter')
npm.config.set('global', true)
t.equal(npm.prefix, npm.globalPrefix, 'prefix is global prefix after setting global')
- t.notEqual(npm.prefix, npm.localPrefix, 'prefix is not local prefix after setting global')
+ t.not(npm.prefix, npm.localPrefix, 'prefix is not local prefix after setting global')
t.equal(npm.bin, npm.globalBin, 'bin is global bin after setting global')
- t.notEqual(npm.bin, npm.localBin, 'bin is not local bin after setting global')
+ t.not(npm.bin, npm.localBin, 'bin is not local bin after setting global')
t.equal(npm.dir, npm.globalDir, 'dir is global dir after setting global')
- t.notEqual(npm.dir, npm.localDir, 'dir is not local dir after setting global')
+ t.not(npm.dir, npm.localDir, 'dir is not local dir after setting global')
npm.prefix = dir + '/new/global/prefix'
t.equal(npm.prefix, npm.globalPrefix, 'prefix is global prefix after prefix setter')
- t.notEqual(npm.prefix, npm.localPrefix, 'prefix is not local prefix after prefix setter')
+ t.not(npm.prefix, npm.localPrefix, 'prefix is not local prefix after prefix setter')
t.equal(npm.bin, npm.globalBin, 'bin is global bin after prefix setter')
- t.notEqual(npm.bin, npm.localBin, 'bin is not local bin after prefix setter')
+ t.not(npm.bin, npm.localBin, 'bin is not local bin after prefix setter')
beWindows()
t.equal(npm.bin, npm.globalBin, 'bin is global bin in windows mode')
@@ -215,7 +215,7 @@ t.test('npm.load', t => {
t.equal(npm.loaded, false, 'not loaded yet')
t.equal(npm.loading, true, 'working on it tho')
- t.isa(p, Promise, 'npm.load() returned a Promise first time')
+ t.type(p, Promise, 'npm.load() returned a Promise first time')
t.equal(npm.load(second), undefined,
'npm.load() returns nothing second time')
@@ -477,10 +477,7 @@ t.test('set process.title', t => {
freshConfig()
})
- t.afterEach(cb => {
- consoleLogs.length = 0
- cb()
- })
+ t.afterEach(() => consoleLogs.length = 0)
t.test('basic title setting', async t => {
freshConfig({
diff --git a/test/lib/org.js b/test/lib/org.js
index 4ffbf0af4..156232ac2 100644
--- a/test/lib/org.js
+++ b/test/lib/org.js
@@ -1,5 +1,4 @@
-const { test } = require('tap')
-const requireInject = require('require-inject')
+const t = require('tap')
const ansiTrim = require('../../lib/utils/ansi-trim.js')
const output = []
@@ -41,13 +40,13 @@ const libnpmorg = {
},
}
-const Org = requireInject('../../lib/org.js', {
+const Org = t.mock('../../lib/org.js', {
'../../lib/utils/otplease.js': async (opts, fn) => fn(opts),
libnpmorg,
})
const org = new Org(npm)
-test('completion', async t => {
+t.test('completion', async t => {
const completion = (argv) =>
org.completion({ conf: { argv: { remain: argv } } })
@@ -65,14 +64,14 @@ test('completion', async t => {
t.rejects(completion(['npm', 'org', 'flurb']), /flurb not recognized/, 'errors for unknown subcommand')
})
-test('npm org - invalid subcommand', t => {
+t.test('npm org - invalid subcommand', t => {
org.exec(['foo'], (err) => {
t.match(err, /npm org set/, 'prints usage information')
t.end()
})
})
-test('npm org add', t => {
+t.test('npm org add', t => {
t.teardown(() => {
orgSetArgs = null
output.length = 0
@@ -93,7 +92,7 @@ test('npm org add', t => {
})
})
-test('npm org add - no org', t => {
+t.test('npm org add - no org', t => {
t.teardown(() => {
orgSetArgs = null
output.length = 0
@@ -105,7 +104,7 @@ test('npm org add - no org', t => {
})
})
-test('npm org add - no user', t => {
+t.test('npm org add - no user', t => {
t.teardown(() => {
orgSetArgs = null
output.length = 0
@@ -117,7 +116,7 @@ test('npm org add - no user', t => {
})
})
-test('npm org add - invalid role', t => {
+t.test('npm org add - invalid role', t => {
t.teardown(() => {
orgSetArgs = null
output.length = 0
@@ -129,7 +128,7 @@ test('npm org add - invalid role', t => {
})
})
-test('npm org add - more users', t => {
+t.test('npm org add - more users', t => {
orgSize = 5
t.teardown(() => {
orgSize = 1
@@ -152,7 +151,7 @@ test('npm org add - more users', t => {
})
})
-test('npm org add - json output', t => {
+t.test('npm org add - json output', t => {
npm.flatOptions.json = true
t.teardown(() => {
npm.flatOptions.json = false
@@ -182,7 +181,7 @@ test('npm org add - json output', t => {
})
})
-test('npm org add - parseable output', t => {
+t.test('npm org add - parseable output', t => {
npm.flatOptions.parseable = true
t.teardown(() => {
npm.flatOptions.parseable = false
@@ -208,7 +207,7 @@ test('npm org add - parseable output', t => {
})
})
-test('npm org add - silent output', t => {
+t.test('npm org add - silent output', t => {
npm.flatOptions.silent = true
t.teardown(() => {
npm.flatOptions.silent = false
@@ -231,7 +230,7 @@ test('npm org add - silent output', t => {
})
})
-test('npm org rm', t => {
+t.test('npm org rm', t => {
t.teardown(() => {
orgRmArgs = null
orgLsArgs = null
@@ -256,7 +255,7 @@ test('npm org rm', t => {
})
})
-test('npm org rm - no org', t => {
+t.test('npm org rm - no org', t => {
t.teardown(() => {
orgRmArgs = null
orgLsArgs = null
@@ -269,7 +268,7 @@ test('npm org rm - no org', t => {
})
})
-test('npm org rm - no user', t => {
+t.test('npm org rm - no user', t => {
t.teardown(() => {
orgRmArgs = null
orgLsArgs = null
@@ -282,7 +281,7 @@ test('npm org rm - no user', t => {
})
})
-test('npm org rm - one user left', t => {
+t.test('npm org rm - one user left', t => {
orgList = {
one: 'developer',
}
@@ -312,7 +311,7 @@ test('npm org rm - one user left', t => {
})
})
-test('npm org rm - json output', t => {
+t.test('npm org rm - json output', t => {
npm.flatOptions.json = true
t.teardown(() => {
npm.flatOptions.json = false
@@ -344,7 +343,7 @@ test('npm org rm - json output', t => {
})
})
-test('npm org rm - parseable output', t => {
+t.test('npm org rm - parseable output', t => {
npm.flatOptions.parseable = true
t.teardown(() => {
npm.flatOptions.parseable = false
@@ -374,7 +373,7 @@ test('npm org rm - parseable output', t => {
})
})
-test('npm org rm - silent output', t => {
+t.test('npm org rm - silent output', t => {
npm.flatOptions.silent = true
t.teardown(() => {
npm.flatOptions.silent = false
@@ -401,7 +400,7 @@ test('npm org rm - silent output', t => {
})
})
-test('npm org ls', t => {
+t.test('npm org ls', t => {
orgList = {
one: 'developer',
two: 'admin',
@@ -429,7 +428,7 @@ test('npm org ls', t => {
})
})
-test('npm org ls - user filter', t => {
+t.test('npm org ls - user filter', t => {
orgList = {
username: 'admin',
missing: 'admin',
@@ -455,7 +454,7 @@ test('npm org ls - user filter', t => {
})
})
-test('npm org ls - user filter, missing user', t => {
+t.test('npm org ls - user filter, missing user', t => {
orgList = {
missing: 'admin',
}
@@ -480,7 +479,7 @@ test('npm org ls - user filter, missing user', t => {
})
})
-test('npm org ls - no org', t => {
+t.test('npm org ls - no org', t => {
t.teardown(() => {
orgLsArgs = null
output.length = 0
@@ -492,7 +491,7 @@ test('npm org ls - no org', t => {
})
})
-test('npm org ls - json output', t => {
+t.test('npm org ls - json output', t => {
npm.flatOptions.json = true
orgList = {
one: 'developer',
@@ -519,7 +518,7 @@ test('npm org ls - json output', t => {
})
})
-test('npm org ls - parseable output', t => {
+t.test('npm org ls - parseable output', t => {
npm.flatOptions.parseable = true
orgList = {
one: 'developer',
@@ -551,7 +550,7 @@ test('npm org ls - parseable output', t => {
})
})
-test('npm org ls - silent output', t => {
+t.test('npm org ls - silent output', t => {
npm.flatOptions.silent = true
orgList = {
one: 'developer',
diff --git a/test/lib/outdated.js b/test/lib/outdated.js
index 5aff7c37a..605853056 100644
--- a/test/lib/outdated.js
+++ b/test/lib/outdated.js
@@ -1,5 +1,4 @@
const t = require('tap')
-const requireInject = require('require-inject')
const mockNpm = require('../fixtures/mock-npm')
const packument = spec => {
@@ -85,7 +84,7 @@ const globalDir = t.testdir({
})
const outdated = (dir, opts) => {
- const Outdated = requireInject('../../lib/outdated.js', {
+ const Outdated = t.mock('../../lib/outdated.js', {
pacote: {
packument,
},
@@ -99,10 +98,7 @@ const outdated = (dir, opts) => {
return new Outdated(npm)
}
-t.beforeEach((done) => {
- logs = ''
- done()
-})
+t.beforeEach(() => logs = '')
const redactCwd = (path) => {
const normalizePath = p => p
@@ -342,7 +338,7 @@ t.test('should return if no outdated deps', t => {
outdated(testDir, {
global: false,
}).exec([], () => {
- t.equals(logs.length, 0, 'no logs')
+ t.equal(logs.length, 0, 'no logs')
t.end()
})
})
@@ -369,7 +365,7 @@ t.test('throws if error with a dep', t => {
outdated(testDir, {
global: false,
}).exec([], (err) => {
- t.equals(err.message, 'There is an error with this package.')
+ t.equal(err.message, 'There is an error with this package.')
t.end()
})
})
@@ -389,7 +385,7 @@ t.test('should skip missing non-prod deps', t => {
outdated(testDir, {
global: false,
}).exec([], () => {
- t.equals(logs.length, 0, 'no logs')
+ t.equal(logs.length, 0, 'no logs')
t.end()
})
})
@@ -414,7 +410,7 @@ t.test('should skip invalid pkg ranges', t => {
})
outdated(testDir, {}).exec([], () => {
- t.equals(logs.length, 0, 'no logs')
+ t.equal(logs.length, 0, 'no logs')
t.end()
})
})
@@ -439,7 +435,7 @@ t.test('should skip git specs', t => {
})
outdated(testDir, {}).exec([], () => {
- t.equals(logs.length, 0, 'no logs')
+ t.equal(logs.length, 0, 'no logs')
t.end()
})
})
diff --git a/test/lib/owner.js b/test/lib/owner.js
index 11aeacb7b..4af8d1ebb 100644
--- a/test/lib/owner.js
+++ b/test/lib/owner.js
@@ -1,4 +1,3 @@
-const requireInject = require('require-inject')
const t = require('tap')
let result = ''
@@ -32,7 +31,7 @@ const npmcliMaintainers = [
{ email: 'i@izs.me', name: 'isaacs' },
]
-const Owner = requireInject('../../lib/owner.js', mocks)
+const Owner = t.mock('../../lib/owner.js', mocks)
const owner = new Owner(npm)
t.test('owner no args', t => {
@@ -72,7 +71,7 @@ t.test('owner ls no args', t => {
})
owner.exec(['ls'], err => {
- t.ifError(err, 'npm owner ls no args')
+ t.error(err, 'npm owner ls no args')
t.matchSnapshot(result, 'should output owners of cwd package')
})
})
@@ -140,7 +139,7 @@ t.test('owner ls <pkg>', t => {
})
owner.exec(['ls', '@npmcli/map-workspaces'], err => {
- t.ifError(err, 'npm owner ls <pkg>')
+ t.error(err, 'npm owner ls <pkg>')
t.matchSnapshot(result, 'should output owners of <pkg>')
})
})
@@ -156,7 +155,7 @@ t.test('owner ls <pkg> no maintainers', t => {
})
owner.exec(['ls', '@npmcli/map-workspaces'], err => {
- t.ifError(err, 'npm owner ls <pkg> no maintainers')
+ t.error(err, 'npm owner ls <pkg> no maintainers')
t.equal(result, 'no admin found', 'should output no admint found msg')
t.end()
})
@@ -190,7 +189,7 @@ t.test('owner add <user> <pkg>', t => {
name: '@npmcli/map-workspaces',
},
}, 'should use expected opts')
- t.deepEqual(
+ t.same(
opts.body.maintainers,
[
...npmcliMaintainers,
@@ -227,7 +226,7 @@ t.test('owner add <user> <pkg>', t => {
})
owner.exec(['add', 'foo', '@npmcli/map-workspaces'], err => {
- t.ifError(err, 'npm owner add <user> <pkg>')
+ t.error(err, 'npm owner add <user> <pkg>')
t.equal(result, '+ foo (@npmcli/map-workspaces)', 'should output add result')
})
})
@@ -260,7 +259,7 @@ t.test('owner add <user> cwd package', t => {
})
owner.exec(['add', 'foo'], err => {
- t.ifError(err, 'npm owner add <user> cwd package')
+ t.error(err, 'npm owner add <user> cwd package')
t.equal(result, '+ foo (@npmcli/map-workspaces)', 'should output add result')
t.end()
})
@@ -303,7 +302,7 @@ t.test('owner add <user> <pkg> already an owner', t => {
})
owner.exec(['add', 'ruyadorno', '@npmcli/map-workspaces'], err => {
- t.ifError(err, 'npm owner add <user> <pkg> already an owner')
+ t.error(err, 'npm owner add <user> <pkg> already an owner')
})
})
@@ -448,7 +447,7 @@ t.test('owner add <user> <pkg> no previous maintainers property from server', t
})
owner.exec(['add', 'foo', '@npmcli/no-owners-pkg'], err => {
- t.ifError(err, 'npm owner add <user> <pkg>')
+ t.error(err, 'npm owner add <user> <pkg>')
t.equal(result, '+ foo (@npmcli/no-owners-pkg)', 'should output add result')
t.end()
})
@@ -505,7 +504,7 @@ t.test('owner rm <user> <pkg>', t => {
name: '@npmcli/map-workspaces',
},
}, 'should use expected opts')
- t.deepEqual(
+ t.same(
opts.body.maintainers,
npmcliMaintainers.filter(m => m.name !== 'ruyadorno'),
'should contain expected new owners, removing requested user'
@@ -536,7 +535,7 @@ t.test('owner rm <user> <pkg>', t => {
})
owner.exec(['rm', 'ruyadorno', '@npmcli/map-workspaces'], err => {
- t.ifError(err, 'npm owner rm <user> <pkg>')
+ t.error(err, 'npm owner rm <user> <pkg>')
t.equal(result, '- ruyadorno (@npmcli/map-workspaces)', 'should output rm result')
})
})
@@ -576,7 +575,7 @@ t.test('owner rm <user> <pkg> not a current owner', t => {
})
owner.exec(['rm', 'foo', '@npmcli/map-workspaces'], err => {
- t.ifError(err, 'npm owner rm <user> <pkg> not a current owner')
+ t.error(err, 'npm owner rm <user> <pkg> not a current owner')
})
})
@@ -608,7 +607,7 @@ t.test('owner rm <user> cwd package', t => {
})
owner.exec(['rm', 'ruyadorno'], err => {
- t.ifError(err, 'npm owner rm <user> cwd package')
+ t.error(err, 'npm owner rm <user> cwd package')
t.equal(result, '- ruyadorno (@npmcli/map-workspaces)', 'should output rm result')
t.end()
})
diff --git a/test/lib/pack.js b/test/lib/pack.js
index 4bcfe8ae3..64f4d1258 100644
--- a/test/lib/pack.js
+++ b/test/lib/pack.js
@@ -1,5 +1,4 @@
const t = require('tap')
-const requireInject = require('require-inject')
const mockNpm = require('../fixtures/mock-npm')
const pacote = require('pacote')
@@ -23,13 +22,10 @@ const mockPacote = {
},
}
-t.afterEach(cb => {
- OUTPUT.length = 0
- cb()
-})
+t.afterEach(() => OUTPUT.length = 0)
t.test('should pack current directory with no arguments', (t) => {
- const Pack = requireInject('../../lib/pack.js', {
+ const Pack = t.mock('../../lib/pack.js', {
libnpmpack,
npmlog: {
notice: () => {},
@@ -65,7 +61,7 @@ t.test('should pack given directory', (t) => {
}, null, 2),
})
- const Pack = requireInject('../../lib/pack.js', {
+ const Pack = t.mock('../../lib/pack.js', {
libnpmpack,
npmlog: {
notice: () => {},
@@ -101,7 +97,7 @@ t.test('should pack given directory for scoped package', (t) => {
}, null, 2),
})
- const Pack = requireInject('../../lib/pack.js', {
+ const Pack = t.mock('../../lib/pack.js', {
libnpmpack,
npmlog: {
notice: () => {},
@@ -130,7 +126,7 @@ t.test('should pack given directory for scoped package', (t) => {
})
t.test('should log pack contents', (t) => {
- const Pack = requireInject('../../lib/pack.js', {
+ const Pack = t.mock('../../lib/pack.js', {
'../../lib/utils/tar.js': {
...require('../../lib/utils/tar.js'),
logTar: () => {
@@ -184,7 +180,7 @@ t.test('workspaces', (t) => {
}),
},
})
- const Pack = requireInject('../../lib/pack.js', {
+ const Pack = t.mock('../../lib/pack.js', {
libnpmpack,
pacote: mockPacote,
npmlog: {
diff --git a/test/lib/ping.js b/test/lib/ping.js
index 95361035a..c2d53efef 100644
--- a/test/lib/ping.js
+++ b/test/lib/ping.js
@@ -1,13 +1,12 @@
-const { test } = require('tap')
-const requireInject = require('require-inject')
+const t = require('tap')
const mockNpm = require('../fixtures/mock-npm')
-test('pings', (t) => {
+t.test('pings', (t) => {
t.plan(8)
const registry = 'https://registry.npmjs.org'
let noticeCalls = 0
- const Ping = requireInject('../../lib/ping.js', {
+ const Ping = t.mock('../../lib/ping.js', {
'../../lib/utils/ping.js': function (spec) {
t.equal(spec.registry, registry, 'passes flatOptions')
return {}
@@ -33,18 +32,18 @@ test('pings', (t) => {
ping.exec([], (err) => {
t.equal(noticeCalls, 2, 'should have logged 2 lines')
- t.ifError(err, 'npm ping')
+ t.error(err, 'npm ping')
t.ok('should be able to ping')
})
})
-test('pings and logs details', (t) => {
+t.test('pings and logs details', (t) => {
t.plan(10)
const registry = 'https://registry.npmjs.org'
const details = { extra: 'data' }
let noticeCalls = 0
- const Ping = requireInject('../../lib/ping.js', {
+ const Ping = t.mock('../../lib/ping.js', {
'../../lib/utils/ping.js': function (spec) {
t.equal(spec.registry, registry, 'passes flatOptions')
return details
@@ -74,18 +73,18 @@ test('pings and logs details', (t) => {
ping.exec([], (err) => {
t.equal(noticeCalls, 3, 'should have logged 3 lines')
- t.ifError(err, 'npm ping')
+ t.error(err, 'npm ping')
t.ok('should be able to ping')
})
})
-test('pings and returns json', (t) => {
+t.test('pings and returns json', (t) => {
t.plan(11)
const registry = 'https://registry.npmjs.org'
const details = { extra: 'data' }
let noticeCalls = 0
- const Ping = requireInject('../../lib/ping.js', {
+ const Ping = t.mock('../../lib/ping.js', {
'../../lib/utils/ping.js': function (spec) {
t.equal(spec.registry, registry, 'passes flatOptions')
return details
@@ -117,7 +116,7 @@ test('pings and returns json', (t) => {
ping.exec([], (err) => {
t.equal(noticeCalls, 2, 'should have logged 2 lines')
- t.ifError(err, 'npm ping')
+ t.error(err, 'npm ping')
t.ok('should be able to ping')
})
})
diff --git a/test/lib/prefix.js b/test/lib/prefix.js
index 5eb7ddb93..526631388 100644
--- a/test/lib/prefix.js
+++ b/test/lib/prefix.js
@@ -13,7 +13,7 @@ t.test('prefix', (t) => {
})
prefix.exec([], (err) => {
- t.ifError(err, 'npm prefix')
+ t.error(err, 'npm prefix')
t.ok('should have printed directory')
})
})
diff --git a/test/lib/profile.js b/test/lib/profile.js
index 5b1210615..17bcf99b9 100644
--- a/test/lib/profile.js
+++ b/test/lib/profile.js
@@ -1,5 +1,4 @@
const t = require('tap')
-const requireInject = require('require-inject')
const mockNpm = require('../fixtures/mock-npm')
let result = ''
@@ -67,16 +66,15 @@ const userProfile = {
github: 'https://github.com/npm',
}
-t.afterEach(cb => {
+t.afterEach(() => {
result = ''
flatOptions.otp = ''
config.json = false
config.parseable = false
config.registry = 'https://registry.npmjs.org/'
- cb()
})
-const Profile = requireInject('../../lib/profile.js', mocks)
+const Profile = t.mock('../../lib/profile.js', mocks)
const profile = new Profile(npm)
t.test('no args', t => {
@@ -97,7 +95,7 @@ t.test('profile get no args', t => {
},
}
- const Profile = requireInject('../../lib/profile.js', {
+ const Profile = t.mock('../../lib/profile.js', {
...mocks,
'npm-profile': npmProfile,
})
@@ -123,7 +121,7 @@ t.test('profile get no args', t => {
if (err)
throw err
- t.deepEqual(
+ t.same(
JSON.parse(result),
userProfile,
'should output json profile result'
@@ -157,7 +155,7 @@ t.test('profile get no args', t => {
},
}
- const Profile = requireInject('../../lib/profile.js', {
+ const Profile = t.mock('../../lib/profile.js', {
...mocks,
'npm-profile': npmProfile,
})
@@ -185,7 +183,7 @@ t.test('profile get no args', t => {
},
}
- const Profile = requireInject('../../lib/profile.js', {
+ const Profile = t.mock('../../lib/profile.js', {
...mocks,
'npm-profile': npmProfile,
})
@@ -213,7 +211,7 @@ t.test('profile get no args', t => {
},
}
- const Profile = requireInject('../../lib/profile.js', {
+ const Profile = t.mock('../../lib/profile.js', {
...mocks,
'npm-profile': npmProfile,
})
@@ -241,7 +239,7 @@ t.test('profile get <key>', t => {
},
}
- const Profile = requireInject('../../lib/profile.js', {
+ const Profile = t.mock('../../lib/profile.js', {
...mocks,
'npm-profile': npmProfile,
})
@@ -268,7 +266,7 @@ t.test('profile get <key>', t => {
if (err)
throw err
- t.deepEqual(
+ t.same(
JSON.parse(result),
userProfile,
'should output json profile result ignoring args filter'
@@ -302,7 +300,7 @@ t.test('profile get multiple args', t => {
},
}
- const Profile = requireInject('../../lib/profile.js', {
+ const Profile = t.mock('../../lib/profile.js', {
...mocks,
'npm-profile': npmProfile,
})
@@ -328,7 +326,7 @@ t.test('profile get multiple args', t => {
if (err)
throw err
- t.deepEqual(
+ t.same(
JSON.parse(result),
userProfile,
'should output json profile result and ignore args'
@@ -436,7 +434,7 @@ t.test('profile set <key> <value>', t => {
t.test('default output', t => {
t.plan(2)
- const Profile = requireInject('../../lib/profile.js', {
+ const Profile = t.mock('../../lib/profile.js', {
...mocks,
'npm-profile': npmProfile(t),
})
@@ -459,7 +457,7 @@ t.test('profile set <key> <value>', t => {
config.json = true
- const Profile = requireInject('../../lib/profile.js', {
+ const Profile = t.mock('../../lib/profile.js', {
...mocks,
'npm-profile': npmProfile(t),
})
@@ -469,7 +467,7 @@ t.test('profile set <key> <value>', t => {
if (err)
throw err
- t.deepEqual(
+ t.same(
JSON.parse(result),
{
fullname: 'Lorem Ipsum',
@@ -484,7 +482,7 @@ t.test('profile set <key> <value>', t => {
config.parseable = true
- const Profile = requireInject('../../lib/profile.js', {
+ const Profile = t.mock('../../lib/profile.js', {
...mocks,
'npm-profile': npmProfile(t),
})
@@ -531,7 +529,7 @@ t.test('profile set <key> <value>', t => {
},
}
- const Profile = requireInject('../../lib/profile.js', {
+ const Profile = t.mock('../../lib/profile.js', {
...mocks,
'npm-profile': npmProfile,
})
@@ -595,7 +593,7 @@ t.test('profile set <key> <value>', t => {
},
}
- const Profile = requireInject('../../lib/profile.js', {
+ const Profile = t.mock('../../lib/profile.js', {
...mocks,
'npm-profile': npmProfile,
'../../lib/utils/read-user-info.js': readUserInfo,
@@ -663,7 +661,7 @@ t.test('profile set <key> <value>', t => {
},
}
- const Profile = requireInject('../../lib/profile.js', {
+ const Profile = t.mock('../../lib/profile.js', {
...mocks,
npmlog,
'npm-profile': npmProfile,
@@ -754,7 +752,7 @@ t.test('enable-2fa', t => {
},
}
- const Profile = requireInject('../../lib/profile.js', {
+ const Profile = t.mock('../../lib/profile.js', {
...mocks,
'npm-profile': npmProfile,
})
@@ -783,7 +781,7 @@ t.test('enable-2fa', t => {
},
}
- const Profile = requireInject('../../lib/profile.js', {
+ const Profile = t.mock('../../lib/profile.js', {
...mocks,
'npm-profile': npmProfile,
})
@@ -804,7 +802,7 @@ t.test('enable-2fa', t => {
t.test('no auth found', t => {
npm.config.getCredentialsByURI = () => ({})
- const Profile = requireInject('../../lib/profile.js', {
+ const Profile = t.mock('../../lib/profile.js', {
...mocks,
})
const profile = new Profile(npm)
@@ -883,7 +881,7 @@ t.test('enable-2fa', t => {
},
}
- const Profile = requireInject('../../lib/profile.js', {
+ const Profile = t.mock('../../lib/profile.js', {
...mocks,
'npm-profile': npmProfile,
'../../lib/utils/read-user-info.js': readUserInfo,
@@ -985,7 +983,7 @@ t.test('enable-2fa', t => {
generate: (url, cb) => cb('qrcode'),
}
- const Profile = requireInject('../../lib/profile.js', {
+ const Profile = t.mock('../../lib/profile.js', {
...mocks,
'npm-profile': npmProfile,
'qrcode-terminal': qrcode,
@@ -1037,7 +1035,7 @@ t.test('enable-2fa', t => {
},
}
- const Profile = requireInject('../../lib/profile.js', {
+ const Profile = t.mock('../../lib/profile.js', {
...mocks,
'npm-profile': npmProfile,
'../../lib/utils/read-user-info.js': readUserInfo,
@@ -1083,7 +1081,7 @@ t.test('enable-2fa', t => {
},
}
- const Profile = requireInject('../../lib/profile.js', {
+ const Profile = t.mock('../../lib/profile.js', {
...mocks,
'npm-profile': npmProfile,
'../../lib/utils/read-user-info.js': readUserInfo,
@@ -1132,7 +1130,7 @@ t.test('enable-2fa', t => {
},
}
- const Profile = requireInject('../../lib/profile.js', {
+ const Profile = t.mock('../../lib/profile.js', {
...mocks,
'npm-profile': npmProfile,
'../../lib/utils/read-user-info.js': readUserInfo,
@@ -1181,7 +1179,7 @@ t.test('enable-2fa', t => {
},
}
- const Profile = requireInject('../../lib/profile.js', {
+ const Profile = t.mock('../../lib/profile.js', {
...mocks,
'npm-profile': npmProfile,
'../../lib/utils/read-user-info.js': readUserInfo,
@@ -1215,7 +1213,7 @@ t.test('disable-2fa', t => {
},
}
- const Profile = requireInject('../../lib/profile.js', {
+ const Profile = t.mock('../../lib/profile.js', {
...mocks,
'npm-profile': npmProfile,
})
@@ -1240,7 +1238,7 @@ t.test('disable-2fa', t => {
return userProfile
},
async set (newProfile, conf) {
- t.deepEqual(
+ t.same(
newProfile,
{
tfa: {
@@ -1277,7 +1275,7 @@ t.test('disable-2fa', t => {
})
t.test('default output', t => {
- const Profile = requireInject('../../lib/profile.js', {
+ const Profile = t.mock('../../lib/profile.js', {
...mocks,
'npm-profile': npmProfile(t),
'../../lib/utils/read-user-info.js': readUserInfo(t),
@@ -1300,7 +1298,7 @@ t.test('disable-2fa', t => {
t.test('--json', t => {
config.json = true
- const Profile = requireInject('../../lib/profile.js', {
+ const Profile = t.mock('../../lib/profile.js', {
...mocks,
'npm-profile': npmProfile(t),
'../../lib/utils/read-user-info.js': readUserInfo(t),
@@ -1311,7 +1309,7 @@ t.test('disable-2fa', t => {
if (err)
throw err
- t.deepEqual(
+ t.same(
JSON.parse(result),
{ tfa: false },
'should output json already disabled msg'
@@ -1323,7 +1321,7 @@ t.test('disable-2fa', t => {
t.test('--parseable', t => {
config.parseable = true
- const Profile = requireInject('../../lib/profile.js', {
+ const Profile = t.mock('../../lib/profile.js', {
...mocks,
'npm-profile': npmProfile(t),
'../../lib/utils/read-user-info.js': readUserInfo(t),
@@ -1356,7 +1354,7 @@ t.test('disable-2fa', t => {
return userProfile
},
async set (newProfile, conf) {
- t.deepEqual(
+ t.same(
newProfile,
{
tfa: {
@@ -1386,7 +1384,7 @@ t.test('disable-2fa', t => {
},
}
- const Profile = requireInject('../../lib/profile.js', {
+ const Profile = t.mock('../../lib/profile.js', {
...mocks,
'npm-profile': npmProfile,
'../../lib/utils/read-user-info.js': readUserInfo,
diff --git a/test/lib/prune.js b/test/lib/prune.js
index 8cd148806..87bb1370f 100644
--- a/test/lib/prune.js
+++ b/test/lib/prune.js
@@ -1,8 +1,7 @@
-const { test } = require('tap')
-const requireInject = require('require-inject')
+const t = require('tap')
-test('should prune using Arborist', (t) => {
- const Prune = requireInject('../../lib/prune.js', {
+t.test('should prune using Arborist', (t) => {
+ const Prune = t.mock('../../lib/prune.js', {
'@npmcli/arborist': function (args) {
t.ok(args, 'gets options object')
t.ok(args.path, 'gets path option')
diff --git a/test/lib/publish.js b/test/lib/publish.js
index f61377b54..57574b22a 100644
--- a/test/lib/publish.js
+++ b/test/lib/publish.js
@@ -1,5 +1,4 @@
const t = require('tap')
-const requireInject = require('require-inject')
const mockNpm = require('../fixtures/mock-npm')
const fs = require('fs')
@@ -19,10 +18,7 @@ const defaults = Object.entries(definitions).reduce((defaults, [key, def]) => {
const config = defaults
-t.afterEach(cb => {
- log.level = 'silent'
- cb()
-})
+t.afterEach(() => log.level = 'silent')
t.test('should publish with libnpmpublish, passing through flatOptions and respecting publishConfig.registry', (t) => {
t.plan(7)
@@ -37,7 +33,7 @@ t.test('should publish with libnpmpublish, passing through flatOptions and respe
}, null, 2),
})
- const Publish = requireInject('../../lib/publish.js', {
+ const Publish = t.mock('../../lib/publish.js', {
// verify that we do NOT remove publishConfig if it was there originally
// and then removed during the script/pack process
libnpmpack: async () => {
@@ -50,7 +46,7 @@ t.test('should publish with libnpmpublish, passing through flatOptions and respe
libnpmpublish: {
publish: (manifest, tarData, opts) => {
t.match(manifest, { name: 'my-cool-pkg', version: '1.0.0' }, 'gets manifest')
- t.isa(tarData, Buffer, 'tarData is a buffer')
+ t.type(tarData, Buffer, 'tarData is a buffer')
t.ok(opts, 'gets opts object')
t.same(opts.customValue, true, 'flatOptions values are passed through')
t.same(opts.registry, registry, 'publishConfig.registry is passed through')
@@ -88,7 +84,7 @@ t.test('re-loads publishConfig.registry if added during script process', (t) =>
}, null, 2),
})
- const Publish = requireInject('../../lib/publish.js', {
+ const Publish = t.mock('../../lib/publish.js', {
libnpmpack: async () => {
fs.writeFileSync(`${testDir}/package.json`, JSON.stringify({
name: 'my-cool-pkg',
@@ -100,7 +96,7 @@ t.test('re-loads publishConfig.registry if added during script process', (t) =>
libnpmpublish: {
publish: (manifest, tarData, opts) => {
t.match(manifest, { name: 'my-cool-pkg', version: '1.0.0' }, 'gets manifest')
- t.isa(tarData, Buffer, 'tarData is a buffer')
+ t.type(tarData, Buffer, 'tarData is a buffer')
t.ok(opts, 'gets opts object')
t.same(opts.registry, registry, 'publishConfig.registry is passed through')
},
@@ -132,7 +128,7 @@ t.test('if loglevel=info and json, should not output package contents', (t) => {
})
log.level = 'info'
- const Publish = requireInject('../../lib/publish.js', {
+ const Publish = t.mock('../../lib/publish.js', {
'../../lib/utils/tar.js': {
getContents: () => ({
id: 'someid',
@@ -178,7 +174,7 @@ t.test('if loglevel=silent and dry-run, should not output package contents or pu
})
log.level = 'silent'
- const Publish = requireInject('../../lib/publish.js', {
+ const Publish = t.mock('../../lib/publish.js', {
'../../lib/utils/tar.js': {
getContents: () => ({
id: 'someid',
@@ -224,7 +220,7 @@ t.test('if loglevel=info and dry-run, should not publish, should log package con
})
log.level = 'info'
- const Publish = requireInject('../../lib/publish.js', {
+ const Publish = t.mock('../../lib/publish.js', {
'../../lib/utils/tar.js': {
getContents: () => ({
id: 'someid',
@@ -260,7 +256,7 @@ t.test('if loglevel=info and dry-run, should not publish, should log package con
t.test('shows usage with wrong set of arguments', (t) => {
t.plan(1)
- const Publish = requireInject('../../lib/publish.js')
+ const Publish = t.mock('../../lib/publish.js')
const publish = new Publish({})
publish.exec(['a', 'b', 'c'], (er) => {
@@ -272,7 +268,7 @@ t.test('shows usage with wrong set of arguments', (t) => {
t.test('throws when invalid tag', (t) => {
t.plan(1)
- const Publish = requireInject('../../lib/publish.js')
+ const Publish = t.mock('../../lib/publish.js')
const npm = mockNpm({
config: { ...config, tag: '0.0.13' },
})
@@ -306,7 +302,7 @@ t.test('can publish a tarball', t => {
}, ['package'])
const tarFile = fs.readFileSync(`${testDir}/tarball/package.tgz`)
- const Publish = requireInject('../../lib/publish.js', {
+ const Publish = t.mock('../../lib/publish.js', {
libnpmpublish: {
publish: (manifest, tarData, opts) => {
t.match(manifest, {
@@ -334,7 +330,7 @@ t.test('can publish a tarball', t => {
t.test('should check auth for default registry', t => {
t.plan(2)
- const Publish = requireInject('../../lib/publish.js')
+ const Publish = t.mock('../../lib/publish.js')
const npm = mockNpm({ config })
npm.config.getCredentialsByURI = (uri) => {
t.same(uri, defaults.registry, 'gets credentials for expected registry')
@@ -354,7 +350,7 @@ t.test('should check auth for default registry', t => {
t.test('should check auth for configured registry', t => {
t.plan(2)
const registry = 'https://some.registry'
- const Publish = requireInject('../../lib/publish.js')
+ const Publish = t.mock('../../lib/publish.js')
const npm = mockNpm({
config,
flatOptions: { registry },
@@ -384,7 +380,7 @@ t.test('should check auth for scope specific registry', t => {
}, null, 2),
})
- const Publish = requireInject('../../lib/publish.js')
+ const Publish = t.mock('../../lib/publish.js')
const npm = mockNpm({
config,
flatOptions: { '@npm:registry': registry },
@@ -414,7 +410,7 @@ t.test('should use auth for scope specific registry', t => {
}, null, 2),
})
- const Publish = requireInject('../../lib/publish.js', {
+ const Publish = t.mock('../../lib/publish.js', {
libnpmpublish: {
publish: (manifest, tarData, opts) => {
t.ok(opts, 'gets opts object')
@@ -453,7 +449,7 @@ t.test('read registry only from publishConfig', t => {
}, null, 2),
})
- const Publish = requireInject('../../lib/publish.js', {
+ const Publish = t.mock('../../lib/publish.js', {
libnpmpublish: {
publish: (manifest, tarData, opts) => {
t.match(manifest, { name: 'my-cool-pkg', version: '1.0.0' }, 'gets manifest')
@@ -499,7 +495,7 @@ t.test('able to publish after if encountered multiple configs', t => {
}))
configList.unshift(Object.assign(Object.create(configList[0]), { tag }))
- const Publish = requireInject('../../lib/publish.js', {
+ const Publish = t.mock('../../lib/publish.js', {
libnpmpublish: {
publish: (manifest, tarData, opts) => {
t.same(opts.defaultTag, tag, 'gets option for expected tag')
diff --git a/test/lib/rebuild.js b/test/lib/rebuild.js
index 6e144b7e1..e686b6a32 100644
--- a/test/lib/rebuild.js
+++ b/test/lib/rebuild.js
@@ -19,12 +19,11 @@ const npm = mockNpm({
const Rebuild = require('../../lib/rebuild.js')
const rebuild = new Rebuild(npm)
-t.afterEach(cb => {
+t.afterEach(() => {
npm.prefix = ''
config.global = false
npm.globalDir = ''
result = ''
- cb()
})
t.test('no args', t => {
diff --git a/test/lib/repo.js b/test/lib/repo.js
index c05c02d80..0701750b5 100644
--- a/test/lib/repo.js
+++ b/test/lib/repo.js
@@ -1,5 +1,4 @@
const t = require('tap')
-const requireInject = require('require-inject')
const mockNpm = require('../fixtures/mock-npm.js')
const { join, sep } = require('path')
@@ -186,16 +185,14 @@ const openUrl = async (npm, url, errMsg) => {
opened[url]++
}
-const Repo = requireInject('../../lib/repo.js', {
+const Repo = t.mock('../../lib/repo.js', {
'../../lib/utils/open-url.js': openUrl,
})
const flatOptions = {}
const npm = mockNpm({ flatOptions })
const repo = new Repo(npm)
-t.afterEach(async () => {
- opened = {}
-})
+t.afterEach(() => opened = {})
t.test('open repo urls', t => {
// XXX It is very odd that `where` is how pacote knows to look anywhere other
diff --git a/test/lib/root.js b/test/lib/root.js
index 4a1aefa02..5460f3d49 100644
--- a/test/lib/root.js
+++ b/test/lib/root.js
@@ -13,7 +13,7 @@ t.test('root', (t) => {
})
root.exec([], (err) => {
- t.ifError(err, 'npm root')
+ t.error(err, 'npm root')
t.ok('should have printed directory')
})
})
diff --git a/test/lib/run-script.js b/test/lib/run-script.js
index f7eb46fed..897c80817 100644
--- a/test/lib/run-script.js
+++ b/test/lib/run-script.js
@@ -1,6 +1,5 @@
const { resolve } = require('path')
const t = require('tap')
-const requireInject = require('require-inject')
const mockNpm = require('../fixtures/mock-npm')
const normalizePath = p => p
@@ -43,7 +42,7 @@ const npmlog = {
error: () => null,
}
-t.afterEach(cb => {
+t.afterEach(() => {
npm.color = false
npmlog.level = 'warn'
npmlog.error = () => null
@@ -52,11 +51,10 @@ t.afterEach(cb => {
config['if-present'] = false
config.json = false
config.parseable = false
- cb()
})
const getRS = windows => {
- const RunScript = requireInject('../../lib/run-script.js', {
+ const RunScript = t.mock('../../lib/run-script.js', {
'@npmcli/run-script': Object.assign(async opts => {
RUN_SCRIPTS.push(opts)
}, {
@@ -386,7 +384,7 @@ t.test('skip pre/post hooks when using ignoreScripts', t => {
if (er)
throw er
- t.deepEqual(RUN_SCRIPTS, [
+ t.same(RUN_SCRIPTS, [
{
path: npm.localPrefix,
args: [],
@@ -898,27 +896,27 @@ t.test('workspaces', t => {
'Lifecycle script `missing-script` failed with error:',
'Error: Missing script: "missing-script"\n\nTo see a list of scripts, run:\n npm run',
' in workspace: a@1.0.0',
- ' at location: {CWD}/test/lib/run-script-workspaces/packages/a',
+ ' at location: {CWD}/test/lib/tap-testdir-run-script-workspaces/packages/a',
'Lifecycle script `missing-script` failed with error:',
'Error: Missing script: "missing-script"\n\nTo see a list of scripts, run:\n npm run',
' in workspace: b@2.0.0',
- ' at location: {CWD}/test/lib/run-script-workspaces/packages/b',
+ ' at location: {CWD}/test/lib/tap-testdir-run-script-workspaces/packages/b',
'Lifecycle script `missing-script` failed with error:',
'Error: Missing script: "missing-script"\n\nTo see a list of scripts, run:\n npm run',
' in workspace: c@1.0.0',
- ' at location: {CWD}/test/lib/run-script-workspaces/packages/c',
+ ' at location: {CWD}/test/lib/tap-testdir-run-script-workspaces/packages/c',
'Lifecycle script `missing-script` failed with error:',
'Error: Missing script: "missing-script"\n\nTo see a list of scripts, run:\n npm run',
' in workspace: d@1.0.0',
- ' at location: {CWD}/test/lib/run-script-workspaces/packages/d',
+ ' at location: {CWD}/test/lib/tap-testdir-run-script-workspaces/packages/d',
'Lifecycle script `missing-script` failed with error:',
'Error: Missing script: "missing-script"\n\nTo see a list of scripts, run:\n npm run',
' in workspace: e',
- ' at location: {CWD}/test/lib/run-script-workspaces/packages/e',
+ ' at location: {CWD}/test/lib/tap-testdir-run-script-workspaces/packages/e',
'Lifecycle script `missing-script` failed with error:',
'Error: Missing script: "missing-script"\n\nTo see a list of scripts, run:\n npm run',
' in workspace: noscripts@1.0.0',
- ' at location: {CWD}/test/lib/run-script-workspaces/packages/noscripts',
+ ' at location: {CWD}/test/lib/tap-testdir-run-script-workspaces/packages/noscripts',
], 'should log error msgs for each workspace script')
t.end()
@@ -939,11 +937,11 @@ t.test('workspaces', t => {
'Lifecycle script `test` failed with error:',
'Error: Missing script: "test"\n\nTo see a list of scripts, run:\n npm run',
' in workspace: a@1.0.0',
- ' at location: {CWD}/test/lib/run-script-workspaces/packages/a',
+ ' at location: {CWD}/test/lib/tap-testdir-run-script-workspaces/packages/a',
'Lifecycle script `test` failed with error:',
'Error: Missing script: "test"\n\nTo see a list of scripts, run:\n npm run',
' in workspace: b@2.0.0',
- ' at location: {CWD}/test/lib/run-script-workspaces/packages/b',
+ ' at location: {CWD}/test/lib/tap-testdir-run-script-workspaces/packages/b',
], 'should log error msgs for each workspace script')
t.end()
})
@@ -977,7 +975,7 @@ t.test('workspaces', t => {
})
t.test('single failed workspace run', t => {
- const RunScript = requireInject('../../lib/run-script.js', {
+ const RunScript = t.mock('../../lib/run-script.js', {
'@npmcli/run-script': () => {
throw new Error('err')
},
@@ -994,7 +992,7 @@ t.test('workspaces', t => {
})
t.test('failed workspace run with succeeded runs', t => {
- const RunScript = requireInject('../../lib/run-script.js', {
+ const RunScript = t.mock('../../lib/run-script.js', {
'@npmcli/run-script': async opts => {
if (opts.pkg.name === 'a')
throw new Error('ERR')
diff --git a/test/lib/search.js b/test/lib/search.js
index b7b408442..ac894a9e3 100644
--- a/test/lib/search.js
+++ b/test/lib/search.js
@@ -1,6 +1,5 @@
const Minipass = require('minipass')
const t = require('tap')
-const requireInject = require('require-inject')
const mockNpm = require('../fixtures/mock-npm')
const libnpmsearchResultFixture =
require('../fixtures/libnpmsearch-stream-result.js')
@@ -37,15 +36,14 @@ const mocks = {
'../../lib/utils/usage.js': () => 'usage instructions',
}
-t.afterEach(cb => {
+t.afterEach(() => {
result = ''
config.json = false
config.parseable = false
npm.flatOptions = { ...flatOptions }
- cb()
})
-const Search = requireInject('../../lib/search.js', mocks)
+const Search = t.mock('../../lib/search.js', mocks)
const search = new Search(npm)
t.test('no args', t => {
@@ -68,7 +66,7 @@ t.test('search <name>', t => {
},
}
- const Search = requireInject('../../lib/search.js', {
+ const Search = t.mock('../../lib/search.js', {
...mocks,
libnpmsearch,
})
@@ -101,7 +99,7 @@ t.test('search <name> --json', (t) => {
},
}
- const Search = requireInject('../../lib/search.js', {
+ const Search = t.mock('../../lib/search.js', {
...mocks,
libnpmsearch,
})
@@ -146,7 +144,7 @@ t.test('search <name> --searchexclude --searchopts', t => {
},
}
- const Search = requireInject('../../lib/search.js', {
+ const Search = t.mock('../../lib/search.js', {
...mocks,
libnpmsearch,
})
@@ -200,7 +198,7 @@ t.test('empty search results', t => {
},
}
- const Search = requireInject('../../lib/search.js', {
+ const Search = t.mock('../../lib/search.js', {
...mocks,
libnpmsearch,
})
@@ -227,7 +225,7 @@ t.test('search api response error', t => {
},
}
- const Search = requireInject('../../lib/search.js', {
+ const Search = t.mock('../../lib/search.js', {
...mocks,
libnpmsearch,
})
diff --git a/test/lib/set-script.js b/test/lib/set-script.js
index 0071fa20f..96b455785 100644
--- a/test/lib/set-script.js
+++ b/test/lib/set-script.js
@@ -1,5 +1,4 @@
-const test = require('tap')
-const requireInject = require('require-inject')
+const t = require('tap')
const fs = require('fs')
const parseJSON = require('json-parse-even-better-errors')
const mockNpm = require('../fixtures/mock-npm.js')
@@ -10,7 +9,7 @@ const npm = mockNpm(flatOptions)
const ERROR_OUTPUT = []
const WARN_OUTPUT = []
-const SetScript = requireInject('../../lib/set-script.js', {
+const SetScript = t.mock('../../lib/set-script.js', {
npmlog: {
error: (...args) => {
ERROR_OUTPUT.push(args)
@@ -22,7 +21,7 @@ const SetScript = requireInject('../../lib/set-script.js', {
})
const setScript = new SetScript(npm)
-test.test('completion', t => {
+t.test('completion', t => {
t.test('already have a script name', async t => {
npm.localPrefix = t.testdir({})
const res = await setScript.completion({conf: {argv: {remain: ['npm', 'run', 'x']}}})
@@ -60,14 +59,14 @@ test.test('completion', t => {
t.end()
})
-test.test('fails on invalid arguments', (t) => {
+t.test('fails on invalid arguments', (t) => {
t.plan(3)
setScript.exec(['arg1'], (fail) => t.match(fail, /Expected 2 arguments: got 1/))
setScript.exec(['arg1', 'arg2', 'arg3'], (fail) => t.match(fail, /Expected 2 arguments: got 3/))
setScript.exec(['arg1', 'arg2', 'arg3', 'arg4'], (fail) => t.match(fail, /Expected 2 arguments: got 4/))
})
-test.test('fails if run in postinstall script', (t) => {
+t.test('fails if run in postinstall script', (t) => {
const lifecycleEvent = process.env.npm_lifecycle_event
t.teardown(() => {
process.env.npm_lifecycle_event = lifecycleEvent
@@ -78,12 +77,12 @@ test.test('fails if run in postinstall script', (t) => {
setScript.exec(['arg1', 'arg2'], (fail) => t.equal(fail.toString(), 'Error: Scripts can’t set from the postinstall script'))
})
-test.test('fails when package.json not found', (t) => {
+t.test('fails when package.json not found', (t) => {
t.plan(1)
setScript.exec(['arg1', 'arg2'], (fail) => t.match(fail, /package.json not found/))
})
-test.test('fails on invalid JSON', (t) => {
+t.test('fails on invalid JSON', (t) => {
npm.localPrefix = t.testdir({
'package.json': 'iamnotjson',
})
@@ -92,7 +91,7 @@ test.test('fails on invalid JSON', (t) => {
setScript.exec(['arg1', 'arg2'], (fail) => t.match(fail, /Invalid package.json: JSONParseError/))
})
-test.test('creates scripts object', (t) => {
+t.test('creates scripts object', (t) => {
npm.localPrefix = t.testdir({
'package.json': '{}',
})
@@ -101,11 +100,11 @@ test.test('creates scripts object', (t) => {
setScript.exec(['arg1', 'arg2'], (error) => {
t.equal(error, undefined)
const contents = fs.readFileSync(resolve(npm.localPrefix, 'package.json'))
- t.assert(parseJSON(contents), {scripts: {arg1: 'arg2'}})
+ t.ok(parseJSON(contents), {scripts: {arg1: 'arg2'}})
})
})
-test.test('warns when overwriting', (t) => {
+t.test('warns when overwriting', (t) => {
WARN_OUTPUT.length = 0
npm.localPrefix = t.testdir({
'package.json': JSON.stringify({
@@ -122,7 +121,7 @@ test.test('warns when overwriting', (t) => {
})
})
-test.test('provided indentation and eol is used', (t) => {
+t.test('provided indentation and eol is used', (t) => {
npm.localPrefix = t.testdir({
'package.json': JSON.stringify({
name: 'foo',
@@ -141,7 +140,7 @@ test.test('provided indentation and eol is used', (t) => {
})
})
-test.test('workspaces', (t) => {
+t.test('workspaces', (t) => {
ERROR_OUTPUT.length = 0
WARN_OUTPUT.length = 0
npm.localPrefix = t.testdir({
diff --git a/test/lib/set.js b/test/lib/set.js
index 3b38fdc27..f51065a4b 100644
--- a/test/lib/set.js
+++ b/test/lib/set.js
@@ -1,5 +1,4 @@
const t = require('tap')
-const requireInject = require('require-inject')
let configArgs = null
const npm = {
@@ -11,7 +10,7 @@ const npm = {
},
}
-const Set = requireInject('../../lib/set.js')
+const Set = t.mock('../../lib/set.js')
const set = new Set(npm)
t.test('npm set - no args', t => {
diff --git a/test/lib/shrinkwrap.js b/test/lib/shrinkwrap.js
index faf452ea7..8bd18f7fb 100644
--- a/test/lib/shrinkwrap.js
+++ b/test/lib/shrinkwrap.js
@@ -1,6 +1,5 @@
const t = require('tap')
const fs = require('fs')
-const requireInject = require('require-inject')
const mockNpm = require('../fixtures/mock-npm')
const config = {
@@ -40,11 +39,10 @@ const mocks = {
'../../lib/utils/config/definitions.js': {},
}
-t.afterEach(cb => {
+t.afterEach(() => {
npm.prefix = ''
config.global = false
npm.globalDir = ''
- cb()
})
t.test('no args', t => {
@@ -54,7 +52,7 @@ t.test('no args', t => {
class Arborist {
constructor (args) {
- t.deepEqual(
+ t.same(
args,
{ ...flatOptions, path: npm.prefix },
'should call arborist constructor with expected args'
@@ -85,7 +83,7 @@ t.test('no args', t => {
},
}
- const Shrinkwrap = requireInject('../../lib/shrinkwrap.js', {
+ const Shrinkwrap = t.mock('../../lib/shrinkwrap.js', {
...mocks,
npmlog,
'@npmcli/arborist': Arborist,
@@ -105,7 +103,7 @@ t.test('no virtual tree', t => {
class Arborist {
constructor (args) {
- t.deepEqual(
+ t.same(
args,
{ ...flatOptions, path: npm.prefix },
'should call arborist constructor with expected args'
@@ -140,7 +138,7 @@ t.test('no virtual tree', t => {
},
}
- const Shrinkwrap = requireInject('../../lib/shrinkwrap.js', {
+ const Shrinkwrap = t.mock('../../lib/shrinkwrap.js', {
...mocks,
npmlog,
'@npmcli/arborist': Arborist,
@@ -160,7 +158,7 @@ t.test('existing package-json file', t => {
class Arborist {
constructor (args) {
- t.deepEqual(
+ t.same(
args,
{ ...flatOptions, path: npm.prefix },
'should call arborist constructor with expected args'
@@ -201,7 +199,7 @@ t.test('existing package-json file', t => {
},
}
- const Shrinkwrap = requireInject('../../lib/shrinkwrap.js', {
+ const Shrinkwrap = t.mock('../../lib/shrinkwrap.js', {
...mocks,
fs,
npmlog,
@@ -222,7 +220,7 @@ t.test('update shrinkwrap file version', t => {
class Arborist {
constructor (args) {
- t.deepEqual(
+ t.same(
args,
{ ...flatOptions, path: npm.prefix },
'should call arborist constructor with expected args'
@@ -256,7 +254,7 @@ t.test('update shrinkwrap file version', t => {
},
}
- const Shrinkwrap = requireInject('../../lib/shrinkwrap.js', {
+ const Shrinkwrap = t.mock('../../lib/shrinkwrap.js', {
...mocks,
npmlog,
'@npmcli/arborist': Arborist,
@@ -276,7 +274,7 @@ t.test('update to date shrinkwrap file', t => {
class Arborist {
constructor (args) {
- t.deepEqual(
+ t.same(
args,
{ ...flatOptions, path: npm.prefix },
'should call arborist constructor with expected args'
@@ -310,7 +308,7 @@ t.test('update to date shrinkwrap file', t => {
},
}
- const Shrinkwrap = requireInject('../../lib/shrinkwrap.js', {
+ const Shrinkwrap = t.mock('../../lib/shrinkwrap.js', {
...mocks,
npmlog,
'@npmcli/arborist': Arborist,
@@ -324,7 +322,7 @@ t.test('update to date shrinkwrap file', t => {
})
t.test('shrinkwrap --global', t => {
- const Shrinkwrap = requireInject('../../lib/shrinkwrap.js', mocks)
+ const Shrinkwrap = t.mock('../../lib/shrinkwrap.js', mocks)
config.global = true
const shrinkwrap = new Shrinkwrap(npm)
@@ -342,7 +340,7 @@ t.test('shrinkwrap --global', t => {
t.test('works without fs.promises', async t => {
t.doesNotThrow(() => {
- const Shrinkwrap = requireInject('../../lib/shrinkwrap.js', {
+ const Shrinkwrap = t.mock('../../lib/shrinkwrap.js', {
...mocks,
fs: { ...fs, promises: null },
})
diff --git a/test/lib/star.js b/test/lib/star.js
index fa75d2105..0c584e4a3 100644
--- a/test/lib/star.js
+++ b/test/lib/star.js
@@ -1,4 +1,3 @@
-const requireInject = require('require-inject')
const mockNpm = require('../fixtures/mock-npm')
const t = require('tap')
@@ -24,15 +23,14 @@ const mocks = {
'../../lib/utils/usage.js': () => 'usage instructions',
}
-const Star = requireInject('../../lib/star.js', mocks)
+const Star = t.mock('../../lib/star.js', mocks)
const star = new Star(npm)
-t.afterEach(cb => {
+t.afterEach(() => {
config.unicode = false
config['star.unstar'] = false
npmlog.info = noop
result = ''
- cb()
})
t.test('no args', t => {
@@ -136,7 +134,7 @@ t.test('unicode', async t => {
})
t.test('logged out user', t => {
- const Star = requireInject('../../lib/star.js', {
+ const Star = t.mock('../../lib/star.js', {
...mocks,
'../../lib/utils/get-identity.js': async () => undefined,
})
diff --git a/test/lib/stars.js b/test/lib/stars.js
index b242a883a..bf345aeb4 100644
--- a/test/lib/stars.js
+++ b/test/lib/stars.js
@@ -1,4 +1,3 @@
-const requireInject = require('require-inject')
const t = require('tap')
let result = ''
@@ -20,14 +19,13 @@ const mocks = {
'../../lib/utils/usage.js': () => 'usage instructions',
}
-const Stars = requireInject('../../lib/stars.js', mocks)
+const Stars = t.mock('../../lib/stars.js', mocks)
const stars = new Stars(npm)
-t.afterEach(cb => {
+t.afterEach(() => {
npm.config = { get () {} }
npmlog.warn = noop
result = ''
- cb()
})
t.test('no args', t => {
diff --git a/test/lib/team.js b/test/lib/team.js
index 458f8ee67..68ac28fff 100644
--- a/test/lib/team.js
+++ b/test/lib/team.js
@@ -1,5 +1,4 @@
const t = require('tap')
-const requireInject = require('require-inject')
let result = ''
const libnpmteam = {
@@ -23,13 +22,12 @@ const mocks = {
'../../lib/utils/usage.js': () => 'usage instructions',
}
-t.afterEach(cb => {
+t.afterEach(() => {
result = ''
npm.flatOptions = {}
- cb()
})
-const Team = requireInject('../../lib/team.js', mocks)
+const Team = t.mock('../../lib/team.js', mocks)
const team = new Team(npm)
t.test('no args', t => {
@@ -76,7 +74,7 @@ t.test('team add <scope:team> <user>', t => {
if (err)
throw err
- t.deepEqual(
+ t.same(
JSON.parse(result),
{
added: true,
@@ -96,7 +94,7 @@ t.test('team add <scope:team> <user>', t => {
if (err)
throw err
- t.deepEqual(result, '', 'should not output success if silent')
+ t.same(result, '', 'should not output success if silent')
t.end()
})
})
@@ -137,7 +135,7 @@ t.test('team create <scope:team>', t => {
if (err)
throw err
- t.deepEqual(
+ t.same(
JSON.parse(result),
{
created: true,
@@ -156,7 +154,7 @@ t.test('team create <scope:team>', t => {
if (err)
throw err
- t.deepEqual(result, '', 'should not output create success if silent')
+ t.same(result, '', 'should not output create success if silent')
t.end()
})
})
@@ -194,7 +192,7 @@ t.test('team destroy <scope:team>', t => {
if (err)
throw err
- t.deepEqual(
+ t.same(
JSON.parse(result),
{
deleted: true,
@@ -213,7 +211,7 @@ t.test('team destroy <scope:team>', t => {
if (err)
throw err
- t.deepEqual(result, '', 'should not output destroy if silent')
+ t.same(result, '', 'should not output destroy if silent')
t.end()
})
})
@@ -232,7 +230,7 @@ t.test('team ls <scope>', t => {
},
}
- const Team = requireInject('../../lib/team.js', {
+ const Team = t.mock('../../lib/team.js', {
...mocks,
libnpmteam,
})
@@ -267,7 +265,7 @@ t.test('team ls <scope>', t => {
if (err)
throw err
- t.deepEqual(
+ t.same(
JSON.parse(result),
[
'npmcli:designers',
@@ -287,7 +285,7 @@ t.test('team ls <scope>', t => {
if (err)
throw err
- t.deepEqual(result, '', 'should not list teams if silent')
+ t.same(result, '', 'should not list teams if silent')
t.end()
})
})
@@ -299,7 +297,7 @@ t.test('team ls <scope>', t => {
},
}
- const Team = requireInject('../../lib/team.js', {
+ const Team = t.mock('../../lib/team.js', {
...mocks,
libnpmteam,
})
@@ -321,7 +319,7 @@ t.test('team ls <scope>', t => {
},
}
- const Team = requireInject('../../lib/team.js', {
+ const Team = t.mock('../../lib/team.js', {
...mocks,
libnpmteam,
})
@@ -345,7 +343,7 @@ t.test('team ls <scope:team>', t => {
return ['nlf', 'ruyadorno', 'darcyclarke', 'isaacs']
},
}
- const Team = requireInject('../../lib/team.js', {
+ const Team = t.mock('../../lib/team.js', {
...mocks,
libnpmteam,
})
@@ -380,7 +378,7 @@ t.test('team ls <scope:team>', t => {
if (err)
throw err
- t.deepEqual(
+ t.same(
JSON.parse(result),
[
'darcyclarke',
@@ -401,7 +399,7 @@ t.test('team ls <scope:team>', t => {
if (err)
throw err
- t.deepEqual(result, '', 'should not output users if silent')
+ t.same(result, '', 'should not output users if silent')
t.end()
})
})
@@ -413,7 +411,7 @@ t.test('team ls <scope:team>', t => {
},
}
- const Team = requireInject('../../lib/team.js', {
+ const Team = t.mock('../../lib/team.js', {
...mocks,
libnpmteam,
})
@@ -435,7 +433,7 @@ t.test('team ls <scope:team>', t => {
},
}
- const Team = requireInject('../../lib/team.js', {
+ const Team = t.mock('../../lib/team.js', {
...mocks,
libnpmteam,
})
@@ -483,7 +481,7 @@ t.test('team rm <scope:team> <user>', t => {
if (err)
throw err
- t.deepEqual(
+ t.same(
JSON.parse(result),
{
removed: true,
@@ -503,7 +501,7 @@ t.test('team rm <scope:team> <user>', t => {
if (err)
throw err
- t.deepEqual(result, '', 'should not output rm result if silent')
+ t.same(result, '', 'should not output rm result if silent')
t.end()
})
})
diff --git a/test/lib/test.js b/test/lib/test.js
index f6f3d7afb..c151b1e82 100644
--- a/test/lib/test.js
+++ b/test/lib/test.js
@@ -1,5 +1,4 @@
const t = require('tap')
-const requireInject = require('require-inject')
let RUN_ARGS = null
const npm = {
commands: {
@@ -9,7 +8,7 @@ const npm = {
},
},
}
-const Test = requireInject('../../lib/test.js')
+const Test = require('../../lib/test.js')
const test = new Test(npm)
t.test('run a test', t => {
diff --git a/test/lib/token.js b/test/lib/token.js
index 3ca44ab5c..94218824d 100644
--- a/test/lib/token.js
+++ b/test/lib/token.js
@@ -1,5 +1,4 @@
-const { test } = require('tap')
-const requireInject = require('require-inject')
+const t = require('tap')
const mocks = {
profile: {},
@@ -11,7 +10,7 @@ const npm = {
output: (...args) => mocks.output(...args),
}
-const Token = requireInject('../../lib/token.js', {
+const Token = t.mock('../../lib/token.js', {
'../../lib/utils/otplease.js': (opts, fn) => {
return Promise.resolve().then(() => fn(opts))
},
@@ -53,7 +52,7 @@ const tokenWithMocks = (mockRequests) => {
return [token, reset]
}
-test('completion', (t) => {
+t.test('completion', (t) => {
t.plan(5)
const testComp = (argv, expect) => {
@@ -71,7 +70,7 @@ test('completion', (t) => {
)
})
-test('token foobar', (t) => {
+t.test('token foobar', (t) => {
t.plan(2)
const [, reset] = tokenWithMocks({
@@ -84,14 +83,14 @@ test('token foobar', (t) => {
},
})
- t.tearDown(reset)
+ t.teardown(reset)
token.exec(['foobar'], (err) => {
t.match(err.message, 'foobar is not a recognized subcommand')
})
})
-test('token list', (t) => {
+t.test('token list', (t) => {
t.plan(15)
const now = new Date().toISOString()
@@ -152,14 +151,14 @@ test('token list', (t) => {
},
})
- t.tearDown(reset)
+ t.teardown(reset)
token.exec([], (err) => {
- t.ifError(err, 'npm token list')
+ t.error(err, 'npm token list')
})
})
-test('token list json output', (t) => {
+t.test('token list json output', (t) => {
t.plan(8)
const now = new Date().toISOString()
@@ -206,14 +205,14 @@ test('token list json output', (t) => {
},
})
- t.tearDown(reset)
+ t.teardown(reset)
token.exec(['list'], (err) => {
- t.ifError(err, 'npm token list')
+ t.error(err, 'npm token list')
})
})
-test('token list parseable output', (t) => {
+t.test('token list parseable output', (t) => {
t.plan(12)
const now = new Date().toISOString()
@@ -274,14 +273,14 @@ test('token list parseable output', (t) => {
},
})
- t.tearDown(reset)
+ t.teardown(reset)
token.exec(['list'], (err) => {
- t.ifError(err, 'npm token list')
+ t.error(err, 'npm token list')
})
})
-test('token revoke', (t) => {
+t.test('token revoke', (t) => {
t.plan(10)
const [token, reset] = tokenWithMocks({
@@ -327,14 +326,14 @@ test('token revoke', (t) => {
},
})
- t.tearDown(reset)
+ t.teardown(reset)
token.exec(['rm', 'abcd'], (err) => {
- t.ifError(err, 'npm token rm')
+ t.error(err, 'npm token rm')
})
})
-test('token revoke multiple tokens', (t) => {
+t.test('token revoke multiple tokens', (t) => {
t.plan(10)
const [token, reset] = tokenWithMocks({
@@ -379,14 +378,14 @@ test('token revoke multiple tokens', (t) => {
},
})
- t.tearDown(reset)
+ t.teardown(reset)
token.exec(['revoke', 'abcd', 'efgh'], (err) => {
- t.ifError(err, 'npm token rm')
+ t.error(err, 'npm token rm')
})
})
-test('token revoke json output', (t) => {
+t.test('token revoke json output', (t) => {
t.plan(10)
const [token, reset] = tokenWithMocks({
@@ -431,14 +430,14 @@ test('token revoke json output', (t) => {
},
})
- t.tearDown(reset)
+ t.teardown(reset)
token.exec(['delete', 'abcd'], (err) => {
- t.ifError(err, 'npm token rm')
+ t.error(err, 'npm token rm')
})
})
-test('token revoke parseable output', (t) => {
+t.test('token revoke parseable output', (t) => {
t.plan(9)
const [token, reset] = tokenWithMocks({
@@ -481,14 +480,14 @@ test('token revoke parseable output', (t) => {
},
})
- t.tearDown(reset)
+ t.teardown(reset)
token.exec(['remove', 'abcd'], (err) => {
- t.ifError(err, 'npm token rm')
+ t.error(err, 'npm token rm')
})
})
-test('token revoke by token', (t) => {
+t.test('token revoke by token', (t) => {
t.plan(9)
const [token, reset] = tokenWithMocks({
@@ -531,14 +530,14 @@ test('token revoke by token', (t) => {
},
})
- t.tearDown(reset)
+ t.teardown(reset)
token.exec(['rm', 'efgh5678'], (err) => {
- t.ifError(err, 'npm token rm')
+ t.error(err, 'npm token rm')
})
})
-test('token revoke requires an id', (t) => {
+t.test('token revoke requires an id', (t) => {
t.plan(2)
const [token, reset] = tokenWithMocks({
@@ -551,14 +550,14 @@ test('token revoke requires an id', (t) => {
},
})
- t.tearDown(reset)
+ t.teardown(reset)
token.exec(['rm'], (err) => {
t.match(err.message, '`<tokenKey>` argument is required')
})
})
-test('token revoke ambiguous id errors', (t) => {
+t.test('token revoke ambiguous id errors', (t) => {
t.plan(7)
const [token, reset] = tokenWithMocks({
@@ -596,14 +595,14 @@ test('token revoke ambiguous id errors', (t) => {
},
})
- t.tearDown(reset)
+ t.teardown(reset)
token.exec(['rm', 'abcd'], (err) => {
t.match(err.message, 'Token ID "abcd" was ambiguous')
})
})
-test('token revoke unknown id errors', (t) => {
+t.test('token revoke unknown id errors', (t) => {
t.plan(7)
const [token, reset] = tokenWithMocks({
@@ -640,14 +639,14 @@ test('token revoke unknown id errors', (t) => {
},
})
- t.tearDown(reset)
+ t.teardown(reset)
token.exec(['rm', 'efgh'], (err) => {
t.match(err.message, 'Unknown token id or value "efgh".')
})
})
-test('token create', (t) => {
+t.test('token create', (t) => {
t.plan(15)
const now = new Date().toISOString()
@@ -704,14 +703,14 @@ test('token create', (t) => {
},
})
- t.tearDown(reset)
+ t.teardown(reset)
token.exec(['create'], (err) => {
- t.ifError(err, 'npm token create')
+ t.error(err, 'npm token create')
})
})
-test('token create json output', (t) => {
+t.test('token create json output', (t) => {
t.plan(10)
const now = new Date().toISOString()
@@ -763,14 +762,14 @@ test('token create json output', (t) => {
},
})
- t.tearDown(reset)
+ t.teardown(reset)
token.exec(['create'], (err) => {
- t.ifError(err, 'npm token create')
+ t.error(err, 'npm token create')
})
})
-test('token create parseable output', (t) => {
+t.test('token create parseable output', (t) => {
t.plan(12)
const now = new Date().toISOString()
@@ -829,14 +828,14 @@ test('token create parseable output', (t) => {
},
})
- t.tearDown(reset)
+ t.teardown(reset)
token.exec(['create'], (err) => {
- t.ifError(err, 'npm token create')
+ t.error(err, 'npm token create')
})
})
-test('token create ipv6 cidr', (t) => {
+t.test('token create ipv6 cidr', (t) => {
t.plan(4)
const password = 'thisisnotreallyapassword'
@@ -863,7 +862,7 @@ test('token create ipv6 cidr', (t) => {
},
})
- t.tearDown(reset)
+ t.teardown(reset)
token.exec(['create'], (err) => {
t.equal(err.message, 'CIDR whitelist can only contain IPv4 addresses, ::1/128 is IPv6', 'returns correct error')
@@ -871,7 +870,7 @@ test('token create ipv6 cidr', (t) => {
})
})
-test('token create invalid cidr', (t) => {
+t.test('token create invalid cidr', (t) => {
t.plan(4)
const password = 'thisisnotreallyapassword'
@@ -898,7 +897,7 @@ test('token create invalid cidr', (t) => {
},
})
- t.tearDown(reset)
+ t.teardown(reset)
token.exec(['create'], (err) => {
t.equal(err.message, 'CIDR whitelist contains invalid CIDR entry: apple/cider', 'returns correct error')
diff --git a/test/lib/uninstall.js b/test/lib/uninstall.js
index 589191ea2..8cf35bd42 100644
--- a/test/lib/uninstall.js
+++ b/test/lib/uninstall.js
@@ -1,7 +1,6 @@
const fs = require('fs')
const { resolve } = require('path')
const t = require('tap')
-const requireInject = require('require-inject')
const mockNpm = require('../fixtures/mock-npm')
const npm = mockNpm({
@@ -16,16 +15,15 @@ const mocks = {
'../../lib/utils/reify-finish.js': () => Promise.resolve(),
}
-const Uninstall = requireInject('../../lib/uninstall.js', mocks)
+const Uninstall = t.mock('../../lib/uninstall.js', mocks)
const uninstall = new Uninstall(npm)
-t.afterEach(cb => {
+t.afterEach(() => {
npm.globalDir = ''
npm.prefix = ''
npm.localPrefix = ''
npm.flatOptions.global = false
npm.flatOptions.prefix = ''
- cb()
})
t.test('remove single installed lib', t => {
@@ -231,7 +229,7 @@ t.test('no args global but no package.json', t => {
t.test('unknown error reading from localPrefix package.json', t => {
const path = t.testdir({})
- const Uninstall = requireInject('../../lib/uninstall.js', {
+ const Uninstall = t.mock('../../lib/uninstall.js', {
...mocks,
'read-package-json-fast': () => Promise.reject(new Error('ERR')),
})
diff --git a/test/lib/unpublish.js b/test/lib/unpublish.js
index ba99b5330..9af7242f2 100644
--- a/test/lib/unpublish.js
+++ b/test/lib/unpublish.js
@@ -1,5 +1,4 @@
const t = require('tap')
-const requireInject = require('require-inject')
const mockNpm = require('../fixtures/mock-npm')
let result = ''
@@ -28,12 +27,11 @@ const mocks = {
'../../lib/utils/get-identity.js': async () => 'foo',
}
-t.afterEach(cb => {
+t.afterEach(() => {
result = ''
config.force = false
config.loglevel = 'silly'
config.silent = false
- cb()
})
t.test('no args --force', t => {
@@ -66,7 +64,7 @@ t.test('no args --force', t => {
const libnpmpublish = {
unpublish (spec, opts) {
t.equal(spec, 'pkg@1.0.0', 'should unpublish expected spec')
- t.deepEqual(
+ t.same(
opts,
{
publishConfig: undefined,
@@ -76,7 +74,7 @@ t.test('no args --force', t => {
},
}
- const Unpublish = requireInject('../../lib/unpublish.js', {
+ const Unpublish = t.mock('../../lib/unpublish.js', {
...mocks,
npmlog,
libnpmpublish,
@@ -103,7 +101,7 @@ t.test('no args --force', t => {
t.test('no args --force missing package.json', t => {
config.force = true
- const Unpublish = requireInject('../../lib/unpublish.js', {
+ const Unpublish = t.mock('../../lib/unpublish.js', {
...mocks,
'read-package-json': (path, cb) => cb(Object.assign(
new Error('ENOENT'),
@@ -125,7 +123,7 @@ t.test('no args --force missing package.json', t => {
t.test('no args --force unknown error reading package.json', t => {
config.force = true
- const Unpublish = requireInject('../../lib/unpublish.js', {
+ const Unpublish = t.mock('../../lib/unpublish.js', {
...mocks,
'read-package-json': (path, cb) => cb(new Error('ERR')),
})
@@ -142,7 +140,7 @@ t.test('no args --force unknown error reading package.json', t => {
})
t.test('no args', t => {
- const Unpublish = requireInject('../../lib/unpublish.js', {
+ const Unpublish = t.mock('../../lib/unpublish.js', {
...mocks,
})
const unpublish = new Unpublish(npm)
@@ -158,7 +156,7 @@ t.test('no args', t => {
})
t.test('too many args', t => {
- const Unpublish = requireInject('../../lib/unpublish.js', {
+ const Unpublish = t.mock('../../lib/unpublish.js', {
...mocks,
})
const unpublish = new Unpublish(npm)
@@ -197,7 +195,7 @@ t.test('unpublish <pkg>@version', t => {
const libnpmpublish = {
unpublish (spec, opts) {
t.equal(spec, pa, 'should unpublish expected parsed spec')
- t.deepEqual(
+ t.same(
opts,
{},
'should unpublish with expected opts'
@@ -205,7 +203,7 @@ t.test('unpublish <pkg>@version', t => {
},
}
- const Unpublish = requireInject('../../lib/unpublish.js', {
+ const Unpublish = t.mock('../../lib/unpublish.js', {
...mocks,
npmlog,
libnpmpublish,
@@ -235,7 +233,7 @@ t.test('no version found in package.json', t => {
npa.resolve = () => ''
- const Unpublish = requireInject('../../lib/unpublish.js', {
+ const Unpublish = t.mock('../../lib/unpublish.js', {
...mocks,
'npm-package-arg': npa,
'read-package-json': (path, cb) => cb(null, {
@@ -260,7 +258,7 @@ t.test('no version found in package.json', t => {
t.test('unpublish <pkg> --force no version set', t => {
config.force = true
- const Unpublish = requireInject('../../lib/unpublish.js', {
+ const Unpublish = t.mock('../../lib/unpublish.js', {
...mocks,
'npm-package-arg': () => ({
name: 'pkg',
@@ -294,7 +292,7 @@ t.test('silent', t => {
npa.resolve = () => ''
- const Unpublish = requireInject('../../lib/unpublish.js', {
+ const Unpublish = t.mock('../../lib/unpublish.js', {
...mocks,
'npm-package-arg': npa,
})
@@ -323,7 +321,7 @@ t.test('completion', async t => {
}
t.test('completing with multiple versions from the registry', async t => {
- const Unpublish = requireInject('../../lib/unpublish.js', {
+ const Unpublish = t.mock('../../lib/unpublish.js', {
...mocks,
libnpmaccess: {
async lsPackages () {
@@ -361,7 +359,7 @@ t.test('completion', async t => {
})
t.test('no versions retrieved', async t => {
- const Unpublish = requireInject('../../lib/unpublish.js', {
+ const Unpublish = t.mock('../../lib/unpublish.js', {
...mocks,
libnpmaccess: {
async lsPackages () {
@@ -394,7 +392,7 @@ t.test('completion', async t => {
})
t.test('packages starting with same letters', async t => {
- const Unpublish = requireInject('../../lib/unpublish.js', {
+ const Unpublish = t.mock('../../lib/unpublish.js', {
...mocks,
libnpmaccess: {
async lsPackages () {
@@ -422,7 +420,7 @@ t.test('completion', async t => {
})
t.test('no packages retrieved', async t => {
- const Unpublish = requireInject('../../lib/unpublish.js', {
+ const Unpublish = t.mock('../../lib/unpublish.js', {
...mocks,
libnpmaccess: {
async lsPackages () {
@@ -442,7 +440,7 @@ t.test('completion', async t => {
})
t.test('no pkg name to complete', async t => {
- const Unpublish = requireInject('../../lib/unpublish.js', {
+ const Unpublish = t.mock('../../lib/unpublish.js', {
...mocks,
libnpmaccess: {
async lsPackages () {
@@ -465,7 +463,7 @@ t.test('completion', async t => {
})
t.test('no pkg names retrieved from user account', async t => {
- const Unpublish = requireInject('../../lib/unpublish.js', {
+ const Unpublish = t.mock('../../lib/unpublish.js', {
...mocks,
libnpmaccess: {
async lsPackages () {
@@ -485,7 +483,7 @@ t.test('completion', async t => {
})
t.test('logged out user', async t => {
- const Unpublish = requireInject('../../lib/unpublish.js', {
+ const Unpublish = t.mock('../../lib/unpublish.js', {
...mocks,
'../../lib/utils/get-identity.js': () => Promise.reject(new Error('ERR')),
})
@@ -500,7 +498,7 @@ t.test('completion', async t => {
})
t.test('too many args', async t => {
- const Unpublish = requireInject('../../lib/unpublish.js', mocks)
+ const Unpublish = t.mock('../../lib/unpublish.js', mocks)
const unpublish = new Unpublish(npm)
await testComp(t, {
diff --git a/test/lib/unstar.js b/test/lib/unstar.js
index 3f3487176..8b853230a 100644
--- a/test/lib/unstar.js
+++ b/test/lib/unstar.js
@@ -1,4 +1,3 @@
-const requireInject = require('require-inject')
const t = require('tap')
t.test('unstar', t => {
@@ -10,11 +9,11 @@ t.test('unstar', t => {
}
exec (args, cb) {
- t.deepEqual(args, ['pkg'], 'should forward packages')
+ t.same(args, ['pkg'], 'should forward packages')
cb()
}
}
- const Unstar = requireInject('../../lib/unstar.js', {
+ const Unstar = t.mock('../../lib/unstar.js', {
'../../lib/star.js': Star,
})
diff --git a/test/lib/update.js b/test/lib/update.js
index 780484afb..5396397d5 100644
--- a/test/lib/update.js
+++ b/test/lib/update.js
@@ -1,6 +1,5 @@
const { resolve } = require('path')
const t = require('tap')
-const requireInject = require('require-inject')
const mockNpm = require('../fixtures/mock-npm')
const config = {
@@ -23,11 +22,10 @@ const mocks = {
'../../lib/utils/usage.js': () => 'usage instructions',
}
-t.afterEach(cb => {
+t.afterEach(() => {
npm.prefix = ''
config.global = false
npm.globalDir = ''
- cb()
})
t.test('no args', t => {
@@ -37,7 +35,7 @@ t.test('no args', t => {
class Arborist {
constructor (args) {
- t.deepEqual(
+ t.same(
args,
{ ...npm.flatOptions, path: npm.prefix, log: noop },
'should call arborist contructor with expected args'
@@ -49,10 +47,10 @@ t.test('no args', t => {
}
}
- const Update = requireInject('../../lib/update.js', {
+ const Update = t.mock('../../lib/update.js', {
...mocks,
'../../lib/utils/reify-finish.js': (npm, arb) => {
- t.isLike(arb, Arborist, 'should reify-finish with arborist instance')
+ t.match(arb, Arborist, 'should reify-finish with arborist instance')
},
'@npmcli/arborist': Arborist,
})
@@ -71,7 +69,7 @@ t.test('with args', t => {
class Arborist {
constructor (args) {
- t.deepEqual(
+ t.same(
args,
{ ...npm.flatOptions, path: npm.prefix, log: noop },
'should call arborist contructor with expected args'
@@ -79,14 +77,14 @@ t.test('with args', t => {
}
reify ({ update }) {
- t.deepEqual(update, ['ipt'], 'should update listed deps')
+ t.same(update, ['ipt'], 'should update listed deps')
}
}
- const Update = requireInject('../../lib/update.js', {
+ const Update = t.mock('../../lib/update.js', {
...mocks,
'../../lib/utils/reify-finish.js': (npm, arb) => {
- t.isLike(arb, Arborist, 'should reify-finish with arborist instance')
+ t.match(arb, Arborist, 'should reify-finish with arborist instance')
},
'@npmcli/arborist': Arborist,
})
@@ -104,7 +102,7 @@ t.test('update --depth=<number>', t => {
npm.prefix = '/project/a'
config.depth = 1
- const Update = requireInject('../../lib/update.js', {
+ const Update = t.mock('../../lib/update.js', {
...mocks,
npmlog: {
warn: (title, msg) => {
@@ -139,7 +137,7 @@ t.test('update --global', t => {
class Arborist {
constructor (args) {
const { path, ...opts } = args
- t.deepEqual(
+ t.same(
opts,
{ ...npm.flatOptions, log: noop },
'should call arborist contructor with expected options'
@@ -155,7 +153,7 @@ t.test('update --global', t => {
reify () {}
}
- const Update = requireInject('../../lib/update.js', {
+ const Update = t.mock('../../lib/update.js', {
...mocks,
'@npmcli/arborist': Arborist,
})
diff --git a/test/lib/utils/audit-error.js b/test/lib/utils/audit-error.js
index d236f4f9e..c683053cb 100644
--- a/test/lib/utils/audit-error.js
+++ b/test/lib/utils/audit-error.js
@@ -13,11 +13,10 @@ const npm = {
},
output,
}
-t.afterEach(cb => {
+t.afterEach(() => {
npm.flatOptions = {}
OUTPUT.length = 0
LOGS.length = 0
- cb()
})
t.test('no error, not audit command', t => {
diff --git a/test/lib/utils/cleanup-log-files.js b/test/lib/utils/cleanup-log-files.js
index 7af0633fe..61240b7b5 100644
--- a/test/lib/utils/cleanup-log-files.js
+++ b/test/lib/utils/cleanup-log-files.js
@@ -1,10 +1,9 @@
const t = require('tap')
-const requireInject = require('require-inject')
const glob = require('glob')
const rimraf = require('rimraf')
const mocks = { glob, rimraf }
-const cleanup = requireInject('../../../lib/utils/cleanup-log-files.js', {
+const cleanup = t.mock('../../../lib/utils/cleanup-log-files.js', {
glob: (...args) => mocks.glob(...args),
rimraf: (...args) => mocks.rimraf(...args),
})
diff --git a/test/lib/utils/completion/installed-deep.js b/test/lib/utils/completion/installed-deep.js
index 0e80a5a19..ba14798bb 100644
--- a/test/lib/utils/completion/installed-deep.js
+++ b/test/lib/utils/completion/installed-deep.js
@@ -1,6 +1,5 @@
const { resolve } = require('path')
-const { test } = require('tap')
-const requireInject = require('require-inject')
+const t = require('tap')
let prefix
let globalDir = 'MISSING_GLOBAL_DIR'
@@ -12,7 +11,7 @@ const _flatOptions = {
},
}
const p = '../../../../lib/utils/completion/installed-deep.js'
-const installedDeep = requireInject(p)
+const installedDeep = require(p)
const npm = {
flatOptions: _flatOptions,
get prefix () {
@@ -144,7 +143,7 @@ const globalFixture = {
},
}
-test('get list of package names', async t => {
+t.test('get list of package names', async t => {
const fix = t.testdir({
local: fixture,
global: globalFixture,
@@ -154,7 +153,7 @@ test('get list of package names', async t => {
globalDir = resolve(fix, 'global/node_modules')
const res = await installedDeep(npm, null)
- t.deepEqual(
+ t.same(
res,
[
['bar', '-g'],
@@ -169,7 +168,7 @@ test('get list of package names', async t => {
t.end()
})
-test('get list of package names as global', async t => {
+t.test('get list of package names as global', async t => {
const fix = t.testdir({
local: fixture,
global: globalFixture,
@@ -181,7 +180,7 @@ test('get list of package names as global', async t => {
_flatOptions.global = true
const res = await installedDeep(npm, null)
- t.deepEqual(
+ t.same(
res,
[
'bar',
@@ -194,7 +193,7 @@ test('get list of package names as global', async t => {
t.end()
})
-test('limit depth', async t => {
+t.test('limit depth', async t => {
const fix = t.testdir({
local: fixture,
global: globalFixture,
@@ -206,7 +205,7 @@ test('limit depth', async t => {
_flatOptions.depth = 0
const res = await installedDeep(npm, null)
- t.deepEqual(
+ t.same(
res,
[
['bar', '-g'],
@@ -222,7 +221,7 @@ test('limit depth', async t => {
t.end()
})
-test('limit depth as global', async t => {
+t.test('limit depth as global', async t => {
const fix = t.testdir({
local: fixture,
global: globalFixture,
@@ -235,7 +234,7 @@ test('limit depth as global', async t => {
_flatOptions.depth = 0
const res = await installedDeep(npm, null)
- t.deepEqual(
+ t.same(
res,
[
'bar',
diff --git a/test/lib/utils/completion/installed-shallow.js b/test/lib/utils/completion/installed-shallow.js
index 1067a50ac..1445cbf2f 100644
--- a/test/lib/utils/completion/installed-shallow.js
+++ b/test/lib/utils/completion/installed-shallow.js
@@ -1,11 +1,10 @@
-const requireInject = require('require-inject')
const flatOptions = { global: false }
const npm = { flatOptions }
const t = require('tap')
const { resolve } = require('path')
const p = '../../../../lib/utils/completion/installed-shallow.js'
-const installed = requireInject(p)
+const installed = require(p)
t.test('global not set, include globals with -g', async t => {
const dir = t.testdir({
diff --git a/test/lib/utils/config/definitions.js b/test/lib/utils/config/definitions.js
index 0b80b34d5..dce69b7f6 100644
--- a/test/lib/utils/config/definitions.js
+++ b/test/lib/utils/config/definitions.js
@@ -1,6 +1,5 @@
const t = require('tap')
-const requireInject = require('require-inject')
const { resolve } = require('path')
// have to fake the node version, or else it'll only pass on this one
@@ -40,25 +39,25 @@ t.test('editor', t => {
t.test('has EDITOR and VISUAL, use EDITOR', t => {
process.env.EDITOR = 'vim'
process.env.VISUAL = 'mate'
- const defs = requireInject(defpath)
+ const defs = t.mock(defpath)
t.equal(defs.editor.default, 'vim')
t.end()
})
t.test('has VISUAL but no EDITOR, use VISUAL', t => {
delete process.env.EDITOR
process.env.VISUAL = 'mate'
- const defs = requireInject(defpath)
+ const defs = t.mock(defpath)
t.equal(defs.editor.default, 'mate')
t.end()
})
t.test('has neither EDITOR nor VISUAL, system specific', t => {
delete process.env.EDITOR
delete process.env.VISUAL
- const defsWin = requireInject(defpath, {
+ const defsWin = t.mock(defpath, {
[isWin]: true,
})
t.equal(defsWin.editor.default, 'notepad.exe')
- const defsNix = requireInject(defpath, {
+ const defsNix = t.mock(defpath, {
[isWin]: false,
})
t.equal(defsNix.editor.default, 'vi')
@@ -70,12 +69,12 @@ t.test('editor', t => {
t.test('shell', t => {
t.test('windows, env.ComSpec then cmd.exe', t => {
process.env.ComSpec = 'command.com'
- const defsComSpec = requireInject(defpath, {
+ const defsComSpec = t.mock(defpath, {
[isWin]: true,
})
t.equal(defsComSpec.shell.default, 'command.com')
delete process.env.ComSpec
- const defsNoComSpec = requireInject(defpath, {
+ const defsNoComSpec = t.mock(defpath, {
[isWin]: true,
})
t.equal(defsNoComSpec.shell.default, 'cmd')
@@ -84,12 +83,12 @@ t.test('shell', t => {
t.test('nix, SHELL then sh', t => {
process.env.SHELL = '/usr/local/bin/bash'
- const defsShell = requireInject(defpath, {
+ const defsShell = t.mock(defpath, {
[isWin]: false,
})
t.equal(defsShell.shell.default, '/usr/local/bin/bash')
delete process.env.SHELL
- const defsNoShell = requireInject(defpath, {
+ const defsNoShell = t.mock(defpath, {
[isWin]: false,
})
t.equal(defsNoShell.shell.default, 'sh')
@@ -108,7 +107,7 @@ t.test('local-address allowed types', t => {
eth69: [{ address: 'no place like home' }],
}),
}
- const defs = requireInject(defpath, { os })
+ const defs = t.mock(defpath, { os })
t.same(defs['local-address'].type, [
null,
'127.0.0.1',
@@ -123,7 +122,7 @@ t.test('local-address allowed types', t => {
throw new Error('no network interfaces for some reason')
},
}
- const defs = requireInject(defpath, { os })
+ const defs = t.mock(defpath, { os })
t.same(defs['local-address'].type, [null])
t.end()
})
@@ -138,42 +137,42 @@ t.test('unicode allowed?', t => {
process.env.LC_CTYPE = 'UTF-8'
process.env.LANG = 'Unicode utf-8'
- const lcAll = requireInject(defpath)
+ const lcAll = t.mock(defpath)
t.equal(lcAll.unicode.default, true)
process.env.LC_ALL = 'no unicode for youUUUU!'
- const noLcAll = requireInject(defpath)
+ const noLcAll = t.mock(defpath)
t.equal(noLcAll.unicode.default, false)
delete process.env.LC_ALL
- const lcCtype = requireInject(defpath)
+ const lcCtype = t.mock(defpath)
t.equal(lcCtype.unicode.default, true)
process.env.LC_CTYPE = 'something other than unicode version 8'
- const noLcCtype = requireInject(defpath)
+ const noLcCtype = t.mock(defpath)
t.equal(noLcCtype.unicode.default, false)
delete process.env.LC_CTYPE
- const lang = requireInject(defpath)
+ const lang = t.mock(defpath)
t.equal(lang.unicode.default, true)
process.env.LANG = 'ISO-8859-1'
- const noLang = requireInject(defpath)
+ const noLang = t.mock(defpath)
t.equal(noLang.unicode.default, false)
t.end()
})
t.test('cache', t => {
process.env.LOCALAPPDATA = 'app/data/local'
- const defsWinLocalAppData = requireInject(defpath, {
+ const defsWinLocalAppData = t.mock(defpath, {
[isWin]: true,
})
t.equal(defsWinLocalAppData.cache.default, 'app/data/local/npm-cache')
delete process.env.LOCALAPPDATA
- const defsWinNoLocalAppData = requireInject(defpath, {
+ const defsWinNoLocalAppData = t.mock(defpath, {
[isWin]: true,
})
t.equal(defsWinNoLocalAppData.cache.default, '~/npm-cache')
- const defsNix = requireInject(defpath, {
+ const defsNix = t.mock(defpath, {
[isWin]: false,
})
t.equal(defsNix.cache.default, '~/.npm')
@@ -236,7 +235,7 @@ t.test('flatteners that populate flat.omit array', t => {
t.strictSame(flat, { omit: ['optional'] }, 'do not omit what is included')
process.env.NODE_ENV = 'production'
- const defProdEnv = requireInject(defpath)
+ const defProdEnv = t.mock(defpath)
t.strictSame(defProdEnv.omit.default, ['dev'], 'omit dev in production')
t.end()
})
@@ -388,15 +387,15 @@ t.test('color', t => {
t.strictSame(flat, {color: true}, '--color turns on color when stdout is tty')
delete process.env.NO_COLOR
- const defsAllowColor = requireInject(defpath)
+ const defsAllowColor = t.mock(defpath)
t.equal(defsAllowColor.color.default, true, 'default true when no NO_COLOR env')
process.env.NO_COLOR = '0'
- const defsNoColor0 = requireInject(defpath)
+ const defsNoColor0 = t.mock(defpath)
t.equal(defsNoColor0.color.default, true, 'default true when no NO_COLOR=0')
process.env.NO_COLOR = '1'
- const defsNoColor1 = requireInject(defpath)
+ const defsNoColor1 = t.mock(defpath)
t.equal(defsNoColor1.color.default, false, 'default false when no NO_COLOR=1')
t.end()
@@ -695,7 +694,7 @@ YYYY\r
})
t.test('error other than ENOENT gets thrown', t => {
const poo = new Error('poo')
- const defnReadFileThrows = requireInject(defpath, {
+ const defnReadFileThrows = t.mock(defpath, {
fs: {
...require('fs'),
readFileSync: () => {
@@ -711,10 +710,10 @@ YYYY\r
})
t.test('detect CI', t => {
- const defnNoCI = requireInject(defpath, {
+ const defnNoCI = t.mock(defpath, {
'@npmcli/ci-detect': () => false,
})
- const defnCIFoo = requireInject(defpath, {
+ const defnCIFoo = t.mock(defpath, {
'@npmcli/ci-detect': () => 'foo',
})
t.equal(defnNoCI['ci-name'].default, null, 'null when not in CI')
diff --git a/test/lib/utils/did-you-mean.js b/test/lib/utils/did-you-mean.js
index 68893a800..15712b665 100644
--- a/test/lib/utils/did-you-mean.js
+++ b/test/lib/utils/did-you-mean.js
@@ -1,6 +1,5 @@
const t = require('tap')
-const requireInject = require('require-inject')
-const npm = requireInject('../../../lib/npm.js')
+const npm = require('../../../lib/npm.js')
const dym = require('../../../lib/utils/did-you-mean.js')
t.test('did-you-mean', t => {
diff --git a/test/lib/utils/error-handler.js b/test/lib/utils/error-handler.js
index b1d3e2ca7..a00bac76e 100644
--- a/test/lib/utils/error-handler.js
+++ b/test/lib/utils/error-handler.js
@@ -1,7 +1,6 @@
/* eslint-disable no-extend-native */
/* eslint-disable no-global-assign */
const EventEmitter = require('events')
-const requireInject = require('require-inject')
const t = require('tap')
// NOTE: Although these unit tests may look like the rest on the surface,
@@ -105,6 +104,7 @@ process = Object.assign(
cb()
} },
stderr: { write () {} },
+ hrtime: _process.hrtime,
}
)
// needs to put process back in its place
@@ -124,8 +124,7 @@ const mocks = {
'../../../lib/utils/cache-file.js': cacheFile,
}
-requireInject.installGlobally('../../../lib/utils/error-handler.js', mocks)
-let errorHandler = require('../../../lib/utils/error-handler.js')
+let errorHandler = t.mock('../../../lib/utils/error-handler.js', mocks)
t.test('default exit code', (t) => {
t.plan(1)
@@ -226,7 +225,7 @@ t.test('console.log output using --json', (t) => {
const _error = console.error
console.error = (jsonOutput) => {
- t.deepEqual(
+ t.same(
JSON.parse(jsonOutput),
{
error: {
@@ -258,7 +257,7 @@ t.test('throw a non-error obj', (t) => {
const _logError = npmlog.error
npmlog.error = (title, err) => {
t.equal(title, 'weird error', 'should name it a weird error')
- t.deepEqual(err, weirdError, 'should log given weird error')
+ t.same(err, weirdError, 'should log given weird error')
}
const _exit = process.exit
@@ -282,7 +281,7 @@ t.test('throw a string error', (t) => {
const _logError = npmlog.error
npmlog.error = (title, err) => {
t.equal(title, '', 'should have an empty name ref')
- t.deepEqual(err, 'foo bar', 'should log string error')
+ t.same(err, 'foo bar', 'should log string error')
}
const _exit = process.exit
@@ -372,9 +371,7 @@ t.test('it worked', (t) => {
t.test('uses code from errno', (t) => {
t.plan(1)
- // RESET MODULE INTERNAL VARS AND GLOBAL REFS
- requireInject.installGlobally.andClearCache('../../../lib/utils/error-handler.js', mocks)
- errorHandler = require('../../../lib/utils/error-handler.js')
+ errorHandler = t.mock('../../../lib/utils/error-handler.js', mocks)
npmlog.level = 'silent'
const _exit = process.exit
@@ -398,12 +395,7 @@ t.test('uses code from errno', (t) => {
t.test('uses exitCode as code if using a number', (t) => {
t.plan(1)
- // RESET MODULE INTERNAL VARS AND GLOBAL REFS
- requireInject.installGlobally.andClearCache(
- '../../../lib/utils/error-handler.js',
- mocks
- )
- errorHandler = require('../../../lib/utils/error-handler.js')
+ errorHandler = t.mock('../../../lib/utils/error-handler.js', mocks)
npmlog.level = 'silent'
const _exit = process.exit
@@ -427,12 +419,7 @@ t.test('uses exitCode as code if using a number', (t) => {
t.test('call errorHandler with no error', (t) => {
t.plan(1)
- // RESET MODULE INTERNAL VARS AND GLOBAL REFS
- requireInject.installGlobally.andClearCache(
- '../../../lib/utils/error-handler.js',
- mocks
- )
- errorHandler = require('../../../lib/utils/error-handler.js')
+ errorHandler = t.mock('../../../lib/utils/error-handler.js', mocks)
const _exit = process.exit
process.exit = (code) => {
@@ -490,12 +477,7 @@ t.test('defaults to log error msg if stack is missing', (t) => {
t.test('set it worked', (t) => {
t.plan(1)
- // RESET MODULE INTERNAL VARS AND GLOBAL REFS
- requireInject.installGlobally.andClearCache(
- '../../../lib/utils/error-handler.js',
- mocks
- )
- errorHandler = require('../../../lib/utils/error-handler.js')
+ errorHandler = t.mock('../../../lib/utils/error-handler.js', mocks)
const _exit = process.exit
process.exit = () => {
@@ -550,10 +532,7 @@ t.test('do no fancy handling for shellouts', t => {
t.equal(code, EXPECT_EXIT, 'got expected exit code')
EXPECT_EXIT = 0
}
- t.beforeEach((cb) => {
- LOG_RECORD.length = 0
- cb()
- })
+ t.beforeEach(() => LOG_RECORD.length = 0)
const loudNoises = () => LOG_RECORD
.filter(({ level }) => ['warn', 'error'].includes(level))
diff --git a/test/lib/utils/error-message.js b/test/lib/utils/error-message.js
index 86db7c94b..7529aac2d 100644
--- a/test/lib/utils/error-message.js
+++ b/test/lib/utils/error-message.js
@@ -10,22 +10,6 @@ Object.defineProperty(process, 'arch', {
configurable: true,
})
-const beWindows = () => {
- Object.defineProperty(process, 'platform', {
- value: 'win32',
- configurable: true,
- })
- delete require.cache[require.resolve('../../../lib/utils/is-windows.js')]
-}
-
-const bePosix = () => {
- Object.defineProperty(process, 'platform', {
- value: 'posix',
- configurable: true,
- })
- delete require.cache[require.resolve('../../../lib/utils/is-windows.js')]
-}
-
const { resolve } = require('path')
const npm = require('../../../lib/npm.js')
const CACHE = '/some/cache/dir'
@@ -56,16 +40,36 @@ npmlog.verbose = (...message) => {
verboseLogs.push(message)
}
-const requireInject = require('require-inject')
const EXPLAIN_CALLED = []
-const errorMessage = requireInject('../../../lib/utils/error-message.js', {
+const mocks = {
'../../../lib/utils/explain-eresolve.js': {
report: (...args) => {
EXPLAIN_CALLED.push(args)
return 'explanation'
},
},
-})
+ '../../../lib/npm.js': require('../../../lib/npm.js'),
+ get '../../../lib/utils/is-windows.js' () {
+ return process.platform === 'win32'
+ },
+}
+let errorMessage = t.mock('../../../lib/utils/error-message.js', { ...mocks })
+
+const beWindows = () => {
+ Object.defineProperty(process, 'platform', {
+ value: 'win32',
+ configurable: true,
+ })
+ errorMessage = t.mock('../../../lib/utils/error-message.js', { ...mocks })
+}
+
+const bePosix = () => {
+ Object.defineProperty(process, 'platform', {
+ value: 'posix',
+ configurable: true,
+ })
+ errorMessage = t.mock('../../../lib/utils/error-message.js', { ...mocks })
+}
t.test('just simple messages', t => {
npm.command = 'audit'
diff --git a/test/lib/utils/explain-dep.js b/test/lib/utils/explain-dep.js
index 1fee61050..cab4d7b59 100644
--- a/test/lib/utils/explain-dep.js
+++ b/test/lib/utils/explain-dep.js
@@ -1,7 +1,6 @@
const t = require('tap')
-const requireInject = require('require-inject')
const npm = {}
-const { explainNode, printNode } = requireInject('../../../lib/utils/explain-dep.js', {
+const { explainNode, printNode } = t.mock('../../../lib/utils/explain-dep.js', {
'../../../lib/npm.js': npm,
})
diff --git a/test/lib/utils/explain-eresolve.js b/test/lib/utils/explain-eresolve.js
index 8dae1b92c..90795bb44 100644
--- a/test/lib/utils/explain-eresolve.js
+++ b/test/lib/utils/explain-eresolve.js
@@ -1,7 +1,6 @@
const t = require('tap')
-const requireInject = require('require-inject')
const npm = {}
-const { explain, report } = requireInject('../../../lib/utils/explain-eresolve.js', {
+const { explain, report } = t.mock('../../../lib/utils/explain-eresolve.js', {
'../../../lib/npm.js': npm,
})
const { statSync, readFileSync, unlinkSync } = require('fs')
diff --git a/test/lib/utils/file-exists.js b/test/lib/utils/file-exists.js
index 473a4b050..c8edf4d96 100644
--- a/test/lib/utils/file-exists.js
+++ b/test/lib/utils/file-exists.js
@@ -1,7 +1,7 @@
-const { test } = require('tap')
+const t = require('tap')
const fileExists = require('../../../lib/utils/file-exists.js')
-test('returns true when arg is a file', async (t) => {
+t.test('returns true when arg is a file', async (t) => {
const path = t.testdir({
foo: 'just some file',
})
@@ -11,7 +11,7 @@ test('returns true when arg is a file', async (t) => {
t.end()
})
-test('returns false when arg is not a file', async (t) => {
+t.test('returns false when arg is not a file', async (t) => {
const path = t.testdir({
foo: {},
})
@@ -21,7 +21,7 @@ test('returns false when arg is not a file', async (t) => {
t.end()
})
-test('returns false when arg does not exist', async (t) => {
+t.test('returns false when arg does not exist', async (t) => {
const path = t.testdir()
const result = await fileExists(`${path}/foo`)
diff --git a/test/lib/utils/get-identity.js b/test/lib/utils/get-identity.js
index cc713b337..5e6de9ca9 100644
--- a/test/lib/utils/get-identity.js
+++ b/test/lib/utils/get-identity.js
@@ -1,9 +1,8 @@
-const { test } = require('tap')
-const requireInject = require('require-inject')
+const t = require('tap')
-test('throws ENOREGISTRY when no registry option is provided', async (t) => {
+t.test('throws ENOREGISTRY when no registry option is provided', async (t) => {
t.plan(2)
- const getIdentity = requireInject('../../../lib/utils/get-identity.js')
+ const getIdentity = t.mock('../../../lib/utils/get-identity.js')
try {
await getIdentity({})
@@ -13,10 +12,10 @@ test('throws ENOREGISTRY when no registry option is provided', async (t) => {
}
})
-test('returns username from uri when provided', async (t) => {
+t.test('returns username from uri when provided', async (t) => {
t.plan(1)
- const getIdentity = requireInject('../../../lib/utils/get-identity.js')
+ const getIdentity = t.mock('../../../lib/utils/get-identity.js')
const npm = {
config: {
getCredentialsByURI: () => {
@@ -29,7 +28,7 @@ test('returns username from uri when provided', async (t) => {
t.equal(identity, 'foo', 'returns username from uri')
})
-test('calls registry whoami when token is provided', async (t) => {
+t.test('calls registry whoami when token is provided', async (t) => {
t.plan(3)
const options = {
@@ -37,7 +36,7 @@ test('calls registry whoami when token is provided', async (t) => {
token: 'thisisnotreallyatoken',
}
- const getIdentity = requireInject('../../../lib/utils/get-identity.js', {
+ const getIdentity = t.mock('../../../lib/utils/get-identity.js', {
'npm-registry-fetch': {
json: (path, opts) => {
t.equal(path, '/-/whoami', 'calls whoami')
@@ -56,7 +55,7 @@ test('calls registry whoami when token is provided', async (t) => {
t.equal(identity, 'foo', 'fetched username from registry')
})
-test('throws ENEEDAUTH when response does not include a username', async (t) => {
+t.test('throws ENEEDAUTH when response does not include a username', async (t) => {
t.plan(3)
const options = {
@@ -64,7 +63,7 @@ test('throws ENEEDAUTH when response does not include a username', async (t) =>
token: 'thisisnotreallyatoken',
}
- const getIdentity = requireInject('../../../lib/utils/get-identity.js', {
+ const getIdentity = t.mock('../../../lib/utils/get-identity.js', {
'npm-registry-fetch': {
json: (path, opts) => {
t.equal(path, '/-/whoami', 'calls whoami')
@@ -86,9 +85,9 @@ test('throws ENEEDAUTH when response does not include a username', async (t) =>
}
})
-test('throws ENEEDAUTH when neither username nor token is configured', async (t) => {
+t.test('throws ENEEDAUTH when neither username nor token is configured', async (t) => {
t.plan(1)
- const getIdentity = requireInject('../../../lib/utils/get-identity.js', {
+ const getIdentity = t.mock('../../../lib/utils/get-identity.js', {
})
const npm = {
config: {
diff --git a/test/lib/utils/npm-usage.js b/test/lib/utils/npm-usage.js
index ebf637ae1..f846a0110 100644
--- a/test/lib/utils/npm-usage.js
+++ b/test/lib/utils/npm-usage.js
@@ -2,11 +2,10 @@ const t = require('tap')
const npm = require('../../../lib/npm.js')
t.test('usage', t => {
- t.afterEach((cb) => {
+ t.afterEach(() => {
npm.config.set('viewer', null)
npm.config.set('long', false)
npm.config.set('userconfig', '/some/config/file/.npmrc')
- cb()
})
const { dirname } = require('path')
const basedir = dirname(dirname(dirname(__dirname)))
diff --git a/test/lib/utils/open-url.js b/test/lib/utils/open-url.js
index 781b70d3e..a31a8cb68 100644
--- a/test/lib/utils/open-url.js
+++ b/test/lib/utils/open-url.js
@@ -1,5 +1,4 @@
-const { test } = require('tap')
-const requireInject = require('require-inject')
+const t = require('tap')
const OUTPUT = []
const output = (...args) => OUTPUT.push(args)
@@ -26,11 +25,11 @@ const opener = (url, opts, cb) => {
return cb(openerResult)
}
-const openUrl = requireInject('../../../lib/utils/open-url.js', {
+const openUrl = t.mock('../../../lib/utils/open-url.js', {
opener,
})
-test('opens a url', async (t) => {
+t.test('opens a url', async (t) => {
t.teardown(() => {
openerUrl = null
openerOpts = null
@@ -42,7 +41,7 @@ test('opens a url', async (t) => {
t.same(OUTPUT, [], 'printed no output')
})
-test('returns error for non-https and non-file url', async (t) => {
+t.test('returns error for non-https and non-file url', async (t) => {
t.teardown(() => {
openerUrl = null
openerOpts = null
@@ -52,10 +51,10 @@ test('returns error for non-https and non-file url', async (t) => {
t.equal(openerUrl, null, 'did not open')
t.same(openerOpts, null, 'did not open')
t.same(OUTPUT, [], 'printed no output')
- t.done()
+ t.end()
})
-test('returns error for non-parseable url', async (t) => {
+t.test('returns error for non-parseable url', async (t) => {
t.teardown(() => {
openerUrl = null
openerOpts = null
@@ -65,10 +64,10 @@ test('returns error for non-parseable url', async (t) => {
t.equal(openerUrl, null, 'did not open')
t.same(openerOpts, null, 'did not open')
t.same(OUTPUT, [], 'printed no output')
- t.done()
+ t.end()
})
-test('opens a url with the given browser', async (t) => {
+t.test('opens a url with the given browser', async (t) => {
npm.config.set('browser', 'chrome')
t.teardown(() => {
openerUrl = null
@@ -80,10 +79,10 @@ test('opens a url with the given browser', async (t) => {
t.equal(openerUrl, 'https://www.npmjs.com', 'opened the given url')
t.same(openerOpts, { command: 'chrome' }, 'passed the given browser as command')
t.same(OUTPUT, [], 'printed no output')
- t.done()
+ t.end()
})
-test('prints where to go when browser is disabled', async (t) => {
+t.test('prints where to go when browser is disabled', async (t) => {
npm.config.set('browser', false)
t.teardown(() => {
openerUrl = null
@@ -97,10 +96,10 @@ test('prints where to go when browser is disabled', async (t) => {
t.equal(OUTPUT.length, 1, 'got one logged message')
t.equal(OUTPUT[0].length, 1, 'logged message had one value')
t.matchSnapshot(OUTPUT[0][0], 'printed expected message')
- t.done()
+ t.end()
})
-test('prints where to go when browser is disabled and json is enabled', async (t) => {
+t.test('prints where to go when browser is disabled and json is enabled', async (t) => {
npm.config.set('browser', false)
npm.config.set('json', true)
t.teardown(() => {
@@ -116,10 +115,10 @@ test('prints where to go when browser is disabled and json is enabled', async (t
t.equal(OUTPUT.length, 1, 'got one logged message')
t.equal(OUTPUT[0].length, 1, 'logged message had one value')
t.matchSnapshot(OUTPUT[0][0], 'printed expected message')
- t.done()
+ t.end()
})
-test('prints where to go when given browser does not exist', async (t) => {
+t.test('prints where to go when given browser does not exist', async (t) => {
npm.config.set('browser', 'firefox')
openerResult = Object.assign(new Error('failed'), { code: 'ENOENT' })
t.teardown(() => {
@@ -134,10 +133,10 @@ test('prints where to go when given browser does not exist', async (t) => {
t.equal(OUTPUT.length, 1, 'got one logged message')
t.equal(OUTPUT[0].length, 1, 'logged message had one value')
t.matchSnapshot(OUTPUT[0][0], 'printed expected message')
- t.done()
+ t.end()
})
-test('handles unknown opener error', async (t) => {
+t.test('handles unknown opener error', async (t) => {
npm.config.set('browser', 'firefox')
openerResult = Object.assign(new Error('failed'), { code: 'ENOBRIAN' })
t.teardown(() => {
@@ -147,5 +146,5 @@ test('handles unknown opener error', async (t) => {
npm.config.set('browser', true)
})
t.rejects(openUrl(npm, 'https://www.npmjs.com', 'npm home'), 'failed', 'got the correct error')
- t.done()
+ t.end()
})
diff --git a/test/lib/utils/otplease.js b/test/lib/utils/otplease.js
index 048856b48..fb9476120 100644
--- a/test/lib/utils/otplease.js
+++ b/test/lib/utils/otplease.js
@@ -1,15 +1,14 @@
-const { test } = require('tap')
-const requireInject = require('require-inject')
+const t = require('tap')
const readUserInfo = {
otp: async () => '1234',
}
-const otplease = requireInject('../../../lib/utils/otplease.js', {
+const otplease = t.mock('../../../lib/utils/otplease.js', {
'../../../lib/utils/read-user-info.js': readUserInfo,
})
-test('prompts for otp for EOTP', async (t) => {
+t.test('prompts for otp for EOTP', async (t) => {
const stdinTTY = process.stdin.isTTY
const stdoutTTY = process.stdout.isTTY
process.stdin.isTTY = true
@@ -26,13 +25,13 @@ test('prompts for otp for EOTP', async (t) => {
t.equal(opts.some, 'prop', 'carried original options')
t.equal(opts.otp, '1234', 'received the otp')
- t.done()
+ t.end()
}
await otplease({ some: 'prop' }, fn)
})
-test('prompts for otp for 401', async (t) => {
+t.test('prompts for otp for 401', async (t) => {
const stdinTTY = process.stdin.isTTY
const stdoutTTY = process.stdout.isTTY
process.stdin.isTTY = true
@@ -53,13 +52,13 @@ test('prompts for otp for 401', async (t) => {
t.equal(opts.some, 'prop', 'carried original options')
t.equal(opts.otp, '1234', 'received the otp')
- t.done()
+ t.end()
}
await otplease({ some: 'prop' }, fn)
})
-test('does not prompt for non-otp errors', async (t) => {
+t.test('does not prompt for non-otp errors', async (t) => {
const stdinTTY = process.stdin.isTTY
const stdoutTTY = process.stdout.isTTY
process.stdin.isTTY = true
@@ -76,7 +75,7 @@ test('does not prompt for non-otp errors', async (t) => {
t.rejects(otplease({ some: 'prop' }, fn), { message: 'nope' }, 'rejects with the original error')
})
-test('does not prompt if stdin or stdout is not a tty', async (t) => {
+t.test('does not prompt if stdin or stdout is not a tty', async (t) => {
const stdinTTY = process.stdin.isTTY
const stdoutTTY = process.stdout.isTTY
process.stdin.isTTY = false
diff --git a/test/lib/utils/path.js b/test/lib/utils/path.js
index 74fb93462..0a7846d94 100644
--- a/test/lib/utils/path.js
+++ b/test/lib/utils/path.js
@@ -1,13 +1,12 @@
const t = require('tap')
-const requireInject = require('require-inject')
const mod = '../../../lib/utils/path.js'
const delim = require('../../../lib/utils/is-windows.js') ? ';' : ':'
Object.defineProperty(process, 'env', {
value: {},
})
process.env.path = ['foo', 'bar', 'baz'].join(delim)
-t.strictSame(requireInject(mod), ['foo', 'bar', 'baz'])
+t.strictSame(t.mock(mod), ['foo', 'bar', 'baz'])
process.env.Path = ['a', 'b', 'c'].join(delim)
-t.strictSame(requireInject(mod), ['a', 'b', 'c'])
+t.strictSame(t.mock(mod), ['a', 'b', 'c'])
process.env.PATH = ['x', 'y', 'z'].join(delim)
-t.strictSame(requireInject(mod), ['x', 'y', 'z'])
+t.strictSame(t.mock(mod), ['x', 'y', 'z'])
diff --git a/test/lib/utils/ping.js b/test/lib/utils/ping.js
index 6e0451538..1bebfa69d 100644
--- a/test/lib/utils/ping.js
+++ b/test/lib/utils/ping.js
@@ -1,12 +1,11 @@
-const { test } = require('tap')
-const requireInject = require('require-inject')
+const t = require('tap')
-test('pings', async (t) => {
+t.test('pings', async (t) => {
t.plan(3)
const options = { fake: 'options' }
const response = { some: 'details' }
- const ping = requireInject('../../../lib/utils/ping.js', {
+ const ping = t.mock('../../../lib/utils/ping.js', {
'npm-registry-fetch': (url, opts) => {
t.equal(url, '/-/ping?write=true', 'calls the correct url')
t.equal(opts, options, 'passes through options')
@@ -18,12 +17,12 @@ test('pings', async (t) => {
t.match(res, response, 'returns json response')
})
-test('catches errors and returns empty json', async (t) => {
+t.test('catches errors and returns empty json', async (t) => {
t.plan(3)
const options = { fake: 'options' }
const response = { some: 'details' }
- const ping = requireInject('../../../lib/utils/ping.js', {
+ const ping = t.mock('../../../lib/utils/ping.js', {
'npm-registry-fetch': (url, opts) => {
t.equal(url, '/-/ping?write=true', 'calls the correct url')
t.equal(opts, options, 'passes through options')
diff --git a/test/lib/utils/proc-log-listener.js b/test/lib/utils/proc-log-listener.js
index 2c1009503..d580defa8 100644
--- a/test/lib/utils/proc-log-listener.js
+++ b/test/lib/utils/proc-log-listener.js
@@ -1,5 +1,4 @@
const t = require('tap')
-const requireInject = require('require-inject')
const { inspect } = require('util')
const logs = []
@@ -8,7 +7,7 @@ const npmlog = {
verbose: (...args) => logs.push(['verbose', ...args]),
}
-requireInject('../../../lib/utils/proc-log-listener.js', {
+t.mock('../../../lib/utils/proc-log-listener.js', {
npmlog,
})()
diff --git a/test/lib/utils/pulse-till-done.js b/test/lib/utils/pulse-till-done.js
index 16c2d521d..c1d7902c0 100644
--- a/test/lib/utils/pulse-till-done.js
+++ b/test/lib/utils/pulse-till-done.js
@@ -1,5 +1,4 @@
-const { test } = require('tap')
-const requireInject = require('require-inject')
+const t = require('tap')
let pulseStarted = null
const npmlog = {
@@ -11,11 +10,11 @@ const npmlog = {
},
}
-const pulseTillDone = requireInject('../../../lib/utils/pulse-till-done.js', {
+const pulseTillDone = t.mock('../../../lib/utils/pulse-till-done.js', {
npmlog,
})
-test('pulses (with promise)', async (t) => {
+t.test('pulses (with promise)', async (t) => {
t.teardown(() => {
pulseStarted = null
})
diff --git a/test/lib/utils/read-local-package.js b/test/lib/utils/read-local-package.js
index 4b693afb4..966e74a7a 100644
--- a/test/lib/utils/read-local-package.js
+++ b/test/lib/utils/read-local-package.js
@@ -1,5 +1,4 @@
-const requireInject = require('require-inject')
-const { test } = require('tap')
+const t = require('tap')
const mockNpm = require('../../fixtures/mock-npm')
const config = {
@@ -8,9 +7,9 @@ const config = {
}
const npm = mockNpm({ config })
-const readLocalPackageName = requireInject('../../../lib/utils/read-local-package.js')
+const readLocalPackageName = require('../../../lib/utils/read-local-package.js')
-test('read local package.json', async (t) => {
+t.test('read local package.json', async (t) => {
npm.prefix = t.testdir({
'package.json': JSON.stringify({
name: 'my-local-package',
@@ -25,7 +24,7 @@ test('read local package.json', async (t) => {
)
})
-test('read local scoped-package.json', async (t) => {
+t.test('read local scoped-package.json', async (t) => {
npm.prefix = t.testdir({
'package.json': JSON.stringify({
name: '@my-scope/my-local-package',
@@ -40,7 +39,7 @@ test('read local scoped-package.json', async (t) => {
)
})
-test('read using --global', async (t) => {
+t.test('read using --global', async (t) => {
npm.prefix = t.testdir({})
config.global = true
const packageName = await readLocalPackageName(npm)
diff --git a/test/lib/utils/read-user-info.js b/test/lib/utils/read-user-info.js
index 99d85d66c..5d937ff78 100644
--- a/test/lib/utils/read-user-info.js
+++ b/test/lib/utils/read-user-info.js
@@ -1,5 +1,4 @@
-const { test } = require('tap')
-const requireInject = require('require-inject')
+const t = require('tap')
let readOpts = null
let readResult = null
@@ -28,13 +27,13 @@ const npmUserValidate = {
},
}
-const readUserInfo = requireInject('../../../lib/utils/read-user-info.js', {
+const readUserInfo = t.mock('../../../lib/utils/read-user-info.js', {
read,
npmlog,
'npm-user-validate': npmUserValidate,
})
-test('otp', async (t) => {
+t.test('otp', async (t) => {
readResult = '1234'
t.teardown(() => {
readResult = null
@@ -44,7 +43,7 @@ test('otp', async (t) => {
t.equal(result, '1234', 'received the otp')
})
-test('password', async (t) => {
+t.test('password', async (t) => {
readResult = 'password'
t.teardown(() => {
readResult = null
@@ -57,7 +56,7 @@ test('password', async (t) => {
}, 'got the correct options')
})
-test('username', async (t) => {
+t.test('username', async (t) => {
readResult = 'username'
t.teardown(() => {
readResult = null
@@ -67,7 +66,7 @@ test('username', async (t) => {
t.equal(result, 'username', 'received the username')
})
-test('username - invalid warns and retries', async (t) => {
+t.test('username - invalid warns and retries', async (t) => {
readResult = 'invalid'
t.teardown(() => {
readResult = null
@@ -87,7 +86,7 @@ test('username - invalid warns and retries', async (t) => {
t.equal(logMsg, 'invalid username')
})
-test('email', async (t) => {
+t.test('email', async (t) => {
readResult = 'foo@bar.baz'
t.teardown(() => {
readResult = null
@@ -97,7 +96,7 @@ test('email', async (t) => {
t.equal(result, 'foo@bar.baz', 'received the email')
})
-test('email - invalid warns and retries', async (t) => {
+t.test('email - invalid warns and retries', async (t) => {
readResult = 'invalid@bar.baz'
t.teardown(() => {
readResult = null
diff --git a/test/lib/utils/reify-finish.js b/test/lib/utils/reify-finish.js
index 7ff5146a6..bbe8a3d99 100644
--- a/test/lib/utils/reify-finish.js
+++ b/test/lib/utils/reify-finish.js
@@ -1,5 +1,4 @@
const t = require('tap')
-const requireInject = require('require-inject')
const npm = {
config: {
@@ -30,7 +29,7 @@ const fs = {
},
}
-const reifyFinish = requireInject('../../../lib/utils/reify-finish.js', {
+const reifyFinish = t.mock('../../../lib/utils/reify-finish.js', {
fs,
'../../../lib/utils/reify-output.js': reifyOutput,
})
@@ -79,7 +78,7 @@ t.test('should write if everything above passes', async t => {
})
t.test('works without fs.promises', async t => {
- t.doesNotThrow(() => requireInject('../../../lib/utils/reify-finish.js', {
+ t.doesNotThrow(() => t.mock('../../../lib/utils/reify-finish.js', {
fs: { ...fs, promises: null },
'../../../lib/npm.js': npm,
'../../../lib/utils/reify-output.js': reifyOutput,
diff --git a/test/lib/utils/reify-output.js b/test/lib/utils/reify-output.js
index e4f58b466..2142566b9 100644
--- a/test/lib/utils/reify-output.js
+++ b/test/lib/utils/reify-output.js
@@ -15,7 +15,7 @@ const npm = {
const reifyOutput = require('../../../lib/utils/reify-output.js')
t.test('missing info', (t) => {
t.plan(1)
- npm.output = out => t.doesNotHave(
+ npm.output = out => t.notMatch(
out,
'looking for funding',
'should not print fund message if missing info'
@@ -33,7 +33,7 @@ t.test('missing info', (t) => {
t.test('even more missing info', t => {
t.plan(1)
- npm.output = out => t.doesNotHave(
+ npm.output = out => t.notMatch(
out,
'looking for funding',
'should not print fund message if missing info'
diff --git a/test/lib/utils/replace-info.js b/test/lib/utils/replace-info.js
index ea9f06520..e4b83783a 100644
--- a/test/lib/utils/replace-info.js
+++ b/test/lib/utils/replace-info.js
@@ -49,7 +49,7 @@ t.equal(
'should replace single item within a phrase'
)
-t.deepEqual(
+t.same(
replaceInfo([
'Something https://user:pass@registry.npmjs.org/ foo bar',
'http://foo:bar@registry.npmjs.org',
@@ -63,7 +63,7 @@ t.deepEqual(
'should replace single item within a phrase'
)
-t.deepEqual(
+t.same(
replaceInfo([
'Something https://user:pass@registry.npmjs.org/ foo bar',
null,
diff --git a/test/lib/utils/setup-log.js b/test/lib/utils/setup-log.js
index 4398200ab..3daf3b8a5 100644
--- a/test/lib/utils/setup-log.js
+++ b/test/lib/utils/setup-log.js
@@ -1,14 +1,12 @@
const t = require('tap')
-const requireInject = require('require-inject')
const settings = {
level: 'warn',
}
-t.afterEach(cb => {
+t.afterEach(() => {
Object.keys(settings).forEach(k => {
delete settings[k]
})
- cb()
})
const WARN_CALLED = []
@@ -61,7 +59,7 @@ const npmlog = {
}
const EXPLAIN_CALLED = []
-const setupLog = requireInject('../../../lib/utils/setup-log.js', {
+const setupLog = t.mock('../../../lib/utils/setup-log.js', {
'../../../lib/utils/explain-eresolve.js': {
explain: (...args) => {
EXPLAIN_CALLED.push(args)
diff --git a/test/lib/utils/split-package-names.js b/test/lib/utils/split-package-names.js
index c69bb2a3d..82b8f5578 100644
--- a/test/lib/utils/split-package-names.js
+++ b/test/lib/utils/split-package-names.js
@@ -1,9 +1,9 @@
'use strict'
-const { test } = require('tap')
+const t = require('tap')
const splitPackageNames = require('../../../lib/utils/split-package-names.js')
-test('splitPackageNames', t => {
+t.test('splitPackageNames', t => {
const assertions = [
['semver', 'semver'],
['read-pkg/semver', 'read-pkg/node_modules/semver'],
diff --git a/test/lib/utils/tar.js b/test/lib/utils/tar.js
index d9b8c5584..5758442fc 100644
--- a/test/lib/utils/tar.js
+++ b/test/lib/utils/tar.js
@@ -1,7 +1,6 @@
-const { test } = require('tap')
+const t = require('tap')
const pack = require('libnpmpack')
const ssri = require('ssri')
-const requireInject = require('require-inject')
const { logTar, getContents } = require('../../../lib/utils/tar.js')
@@ -18,7 +17,7 @@ const printLogs = (tarball, unicode) => {
return logs.join('\n')
}
-test('should log tarball contents', async (t) => {
+t.test('should log tarball contents', async (t) => {
const testDir = t.testdir({
'package.json': JSON.stringify({
name: 'my-cool-pkg',
@@ -42,8 +41,8 @@ test('should log tarball contents', async (t) => {
t.matchSnapshot(printLogs(tarballContents, false))
})
-test('should log tarball contents with unicode', async (t) => {
- const { logTar } = requireInject('../../../lib/utils/tar.js', {
+t.test('should log tarball contents with unicode', async (t) => {
+ const { logTar } = t.mock('../../../lib/utils/tar.js', {
npmlog: {
notice: (str) => {
t.ok(true, 'defaults to npmlog')
@@ -60,8 +59,8 @@ test('should log tarball contents with unicode', async (t) => {
t.end()
})
-test('should default to npmlog', async (t) => {
- const { logTar } = requireInject('../../../lib/utils/tar.js', {
+t.test('should default to npmlog', async (t) => {
+ const { logTar } = t.mock('../../../lib/utils/tar.js', {
npmlog: {
notice: (str) => {
t.ok(true, 'defaults to npmlog')
@@ -78,7 +77,7 @@ test('should default to npmlog', async (t) => {
t.end()
})
-test('should getContents of a tarball', async (t) => {
+t.test('should getContents of a tarball', async (t) => {
const testDir = t.testdir({
'package.json': JSON.stringify({
name: 'my-cool-pkg',
diff --git a/test/lib/utils/unsupported.js b/test/lib/utils/unsupported.js
index f14cba9b7..3a05d9066 100644
--- a/test/lib/utils/unsupported.js
+++ b/test/lib/utils/unsupported.js
@@ -1,4 +1,4 @@
-const test = require('tap').test
+const t = require('tap')
const unsupported = require('../../../lib/utils/unsupported.js')
const versions = [
@@ -33,20 +33,20 @@ const versions = [
['v13.0.0-0', false, false],
]
-test('versions', function (t) {
+t.test('versions', function (t) {
t.plan(versions.length * 2)
versions.forEach(function (verinfo) {
const version = verinfo[0]
const broken = verinfo[1]
const unsupp = verinfo[2]
const nodejs = unsupported.checkVersion(version)
- t.is(nodejs.broken, broken, version + ' ' + (broken ? '' : 'not ') + 'broken')
- t.is(nodejs.unsupported, unsupp, version + ' ' + (unsupp ? 'unsupported' : 'supported'))
+ t.equal(nodejs.broken, broken, version + ' ' + (broken ? '' : 'not ') + 'broken')
+ t.equal(nodejs.unsupported, unsupp, version + ' ' + (unsupp ? 'unsupported' : 'supported'))
})
- t.done()
+ t.end()
})
-test('checkForBrokenNode', t => {
+t.test('checkForBrokenNode', t => {
// run it once to not fail
unsupported.checkForBrokenNode()
@@ -77,7 +77,7 @@ test('checkForBrokenNode', t => {
unsupported.checkForBrokenNode()
})
-test('checkForUnsupportedNode', t => {
+t.test('checkForUnsupportedNode', t => {
const npmlog = require('npmlog')
const { warn } = npmlog
const versionPropDesc = Object.getOwnPropertyDescriptor(process, 'version')
diff --git a/test/lib/utils/update-notifier.js b/test/lib/utils/update-notifier.js
index 99c9dfc26..1735b3105 100644
--- a/test/lib/utils/update-notifier.js
+++ b/test/lib/utils/update-notifier.js
@@ -1,5 +1,4 @@
const t = require('tap')
-const requireInject = require('require-inject')
let ciMock = null
const flatOptions = { global: false, cache: t.testdir() + '/_cacache' }
@@ -52,6 +51,7 @@ let STAT_ERROR = null
let STAT_MTIME = null
let WRITE_ERROR = null
const fs = {
+ ...require('fs'),
stat: (path, cb) => {
if (basename(path) !== '_update-notifier-last-checked') {
console.error(new Error('should only write to notifier last checked file'))
@@ -72,19 +72,18 @@ const fs = {
},
}
-const updateNotifier = requireInject('../../../lib/utils/update-notifier.js', {
+const updateNotifier = t.mock('../../../lib/utils/update-notifier.js', {
'@npmcli/ci-detect': () => ciMock,
pacote,
fs,
})
-t.afterEach(cb => {
+t.afterEach(() => {
MANIFEST_REQUEST.length = 0
STAT_ERROR = null
PACOTE_ERROR = null
STAT_MTIME = null
WRITE_ERROR = null
- cb()
})
t.test('situations in which we do not notify', t => {
diff --git a/test/lib/version.js b/test/lib/version.js
index 35d3d92cd..9cd5f47a0 100644
--- a/test/lib/version.js
+++ b/test/lib/version.js
@@ -1,5 +1,4 @@
const t = require('tap')
-const requireInject = require('require-inject')
const mockNpm = require('../fixtures/mock-npm')
let result = []
@@ -22,16 +21,15 @@ const mocks = {
libnpmversion: noop,
}
-const Version = requireInject('../../lib/version.js', mocks)
+const Version = t.mock('../../lib/version.js', mocks)
const version = new Version(npm)
const _processVersions = process.versions
-t.afterEach(cb => {
+t.afterEach(() => {
config.json = false
npm.prefix = ''
process.versions = _processVersions
result = []
- cb()
})
t.test('no args', t => {
@@ -48,7 +46,7 @@ t.test('no args', t => {
if (err)
throw err
- t.deepEqual(
+ t.same(
result,
[{
'test-version-no-args': '3.2.1',
@@ -103,7 +101,7 @@ t.test('failure reading package.json', t => {
if (err)
throw err
- t.deepEqual(
+ t.same(
result,
[{
npm: '1.0.0',
@@ -125,7 +123,7 @@ t.test('--json option', t => {
version.exec([], err => {
if (err)
throw err
- t.deepEqual(
+ t.same(
result,
['{\n "npm": "1.0.0"\n}'],
'should return json stringified result'
@@ -135,11 +133,11 @@ t.test('--json option', t => {
})
t.test('with one arg', t => {
- const Version = requireInject('../../lib/version.js', {
+ const Version = t.mock('../../lib/version.js', {
...mocks,
libnpmversion: (arg, opts) => {
t.equal(arg, 'major', 'should forward expected value')
- t.deepEqual(
+ t.same(
opts,
{
path: '',
diff --git a/test/lib/view.js b/test/lib/view.js
index 91ce18786..eb2beb9ff 100644
--- a/test/lib/view.js
+++ b/test/lib/view.js
@@ -1,16 +1,18 @@
const t = require('tap')
-const requireInject = require('require-inject')
+
+// run the same as tap does when running directly with node
+process.stdout.columns = undefined
+
const mockNpm = require('../fixtures/mock-npm')
let logs
-const cleanLogs = (done) => {
+const cleanLogs = () => {
logs = ''
const fn = (...args) => {
logs += '\n'
args.map(el => logs += el)
}
console.log = fn
- done()
}
const packument = (nv, opts) => {
@@ -240,7 +242,7 @@ const packument = (nv, opts) => {
t.beforeEach(cleanLogs)
t.test('should log package info', t => {
- const View = requireInject('../../lib/view.js', {
+ const View = t.mock('../../lib/view.js', {
pacote: {
packument,
},
@@ -250,7 +252,7 @@ t.test('should log package info', t => {
})
const view = new View(npm)
- const ViewJson = requireInject('../../lib/view.js', {
+ const ViewJson = t.mock('../../lib/view.js', {
pacote: {
packument,
},
@@ -260,7 +262,7 @@ t.test('should log package info', t => {
})
const viewJson = new ViewJson(jsonNpm)
- const ViewUnicode = requireInject('../../lib/view.js', {
+ const ViewUnicode = t.mock('../../lib/view.js', {
pacote: {
packument,
},
@@ -303,7 +305,7 @@ t.test('should log package info', t => {
t.test('package with no versions', t => {
view.exec(['brown'], () => {
- t.equals(logs, '', 'no info to display')
+ t.equal(logs, '', 'no info to display')
t.end()
})
})
@@ -331,7 +333,7 @@ t.test('should log package info', t => {
t.test('package with --json and no versions', t => {
viewJson.exec(['brown'], () => {
- t.equals(logs, '', 'no info to display')
+ t.equal(logs, '', 'no info to display')
t.end()
})
})
@@ -347,7 +349,7 @@ t.test('should log info of package in current working dir', t => {
}, null, 2),
})
- const View = requireInject('../../lib/view.js', {
+ const View = t.mock('../../lib/view.js', {
pacote: {
packument,
},
@@ -379,7 +381,7 @@ t.test('should log info of package in current working dir', t => {
})
t.test('should log info by field name', t => {
- const ViewJson = requireInject('../../lib/view.js', {
+ const ViewJson = t.mock('../../lib/view.js', {
pacote: {
packument,
},
@@ -393,7 +395,7 @@ t.test('should log info by field name', t => {
const viewJson = new ViewJson(jsonNpm)
- const View = requireInject('../../lib/view.js', {
+ const View = t.mock('../../lib/view.js', {
pacote: {
packument,
},
@@ -447,7 +449,7 @@ t.test('should log info by field name', t => {
t.test('unknown nested field ', t => {
view.exec(['yellow@1.0.0', 'dist.foobar'], () => {
- t.equals(logs, '', 'no info to display')
+ t.equal(logs, '', 'no info to display')
t.end()
})
})
@@ -470,13 +472,13 @@ t.test('should log info by field name', t => {
})
t.test('throw error if global mode', (t) => {
- const View = requireInject('../../lib/view.js')
+ const View = t.mock('../../lib/view.js')
const npm = mockNpm({
config: { global: true },
})
const view = new View(npm)
view.exec([], (err) => {
- t.equals(err.message, 'Cannot use view command in global mode.')
+ t.equal(err.message, 'Cannot use view command in global mode.')
t.end()
})
})
@@ -484,7 +486,7 @@ t.test('throw error if global mode', (t) => {
t.test('throw ENOENT error if package.json misisng', (t) => {
const testDir = t.testdir({})
- const View = requireInject('../../lib/view.js')
+ const View = t.mock('../../lib/view.js')
const npm = mockNpm({
prefix: testDir,
config: { global: false },
@@ -501,7 +503,7 @@ t.test('throw EJSONPARSE error if package.json not json', (t) => {
'package.json': 'not json, nope, not even a little bit!',
})
- const View = requireInject('../../lib/view.js')
+ const View = t.mock('../../lib/view.js')
const npm = mockNpm({
prefix: testDir,
config: { global: false },
@@ -518,20 +520,20 @@ t.test('throw error if package.json has no name', (t) => {
'package.json': '{}',
})
- const View = requireInject('../../lib/view.js')
+ const View = t.mock('../../lib/view.js')
const npm = mockNpm({
prefix: testDir,
config: { global: false },
})
const view = new View(npm)
view.exec([], (err) => {
- t.equals(err.message, 'Invalid package.json, no "name" field')
+ t.equal(err.message, 'Invalid package.json, no "name" field')
t.end()
})
})
t.test('throws when unpublished', (t) => {
- const View = requireInject('../../lib/view.js', {
+ const View = t.mock('../../lib/view.js', {
pacote: {
packument,
},
@@ -544,16 +546,15 @@ t.test('throws when unpublished', (t) => {
})
const view = new View(npm)
view.exec(['red'], (err) => {
- t.equals(err.code, 'E404')
+ t.equal(err.code, 'E404')
t.end()
})
})
t.test('workspaces', t => {
- t.beforeEach((done) => {
+ t.beforeEach(() => {
warnMsg = undefined
config.json = false
- done()
})
const testDir = t.testdir({
'package.json': JSON.stringify({
@@ -574,7 +575,7 @@ t.test('workspaces', t => {
}),
},
})
- const View = requireInject('../../lib/view.js', {
+ const View = t.mock('../../lib/view.js', {
pacote: {
packument,
},
@@ -675,7 +676,7 @@ t.test('workspaces', t => {
})
t.test('completion', async t => {
- const View = requireInject('../../lib/view.js', {
+ const View = t.mock('../../lib/view.js', {
pacote: {
packument,
},
@@ -695,7 +696,7 @@ t.test('completion', async t => {
})
t.test('no registry completion', async t => {
- const View = requireInject('../../lib/view.js')
+ const View = t.mock('../../lib/view.js')
const npm = mockNpm({
config: {
tag: '1.0.1',
diff --git a/test/lib/whoami.js b/test/lib/whoami.js
index b242ea894..5e350a32e 100644
--- a/test/lib/whoami.js
+++ b/test/lib/whoami.js
@@ -1,10 +1,9 @@
-const { test } = require('tap')
-const requireInject = require('require-inject')
+const t = require('tap')
const mockNpm = require('../fixtures/mock-npm')
-test('whoami', (t) => {
+t.test('whoami', (t) => {
t.plan(3)
- const Whoami = requireInject('../../lib/whoami.js', {
+ const Whoami = t.mock('../../lib/whoami.js', {
'../../lib/utils/get-identity.js': () => Promise.resolve('foo'),
})
const npm = mockNpm({
@@ -17,14 +16,14 @@ test('whoami', (t) => {
const whoami = new Whoami(npm)
whoami.exec([], (err) => {
- t.ifError(err, 'npm whoami')
+ t.error(err, 'npm whoami')
t.ok('should successfully print username')
})
})
-test('whoami json', (t) => {
+t.test('whoami json', (t) => {
t.plan(3)
- const Whoami = requireInject('../../lib/whoami.js', {
+ const Whoami = t.mock('../../lib/whoami.js', {
'../../lib/utils/get-identity.js': () => Promise.resolve('foo'),
})
const npm = mockNpm({
@@ -36,7 +35,7 @@ test('whoami json', (t) => {
const whoami = new Whoami(npm)
whoami.exec([], (err) => {
- t.ifError(err, 'npm whoami')
+ t.error(err, 'npm whoami')
t.ok('should successfully print username as json')
})
})
diff --git a/test/lib/workspaces/get-workspaces.js b/test/lib/workspaces/get-workspaces.js
index ebed9dd35..4ea055e02 100644
--- a/test/lib/workspaces/get-workspaces.js
+++ b/test/lib/workspaces/get-workspaces.js
@@ -77,7 +77,7 @@ t.test('get-workspaces', async t => {
let workspaces
workspaces = await getWorkspaces(['a', 'b'], { path })
- t.deepEqual(
+ t.same(
clean(workspaces, path),
new Map(Object.entries({
a: '{PATH}/packages/a',
@@ -87,7 +87,7 @@ t.test('get-workspaces', async t => {
)
workspaces = await getWorkspaces(['./packages/c'], { path })
- t.deepEqual(
+ t.same(
clean(workspaces, path),
new Map(Object.entries({
c: '{PATH}/packages/c',
@@ -96,7 +96,7 @@ t.test('get-workspaces', async t => {
)
workspaces = await getWorkspaces(['packages/c'], { path })
- t.deepEqual(
+ t.same(
clean(workspaces, path),
new Map(Object.entries({
c: '{PATH}/packages/c',
@@ -105,7 +105,7 @@ t.test('get-workspaces', async t => {
)
workspaces = await getWorkspaces([resolve(path, 'packages/c')], { path })
- t.deepEqual(
+ t.same(
clean(workspaces, path),
new Map(Object.entries({
c: '{PATH}/packages/c',
@@ -114,7 +114,7 @@ t.test('get-workspaces', async t => {
)
workspaces = await getWorkspaces(['packages'], { path })
- t.deepEqual(
+ t.same(
clean(workspaces, path),
new Map(Object.entries({
a: '{PATH}/packages/a',
@@ -128,7 +128,7 @@ t.test('get-workspaces', async t => {
)
workspaces = await getWorkspaces(['./packages/'], { path })
- t.deepEqual(
+ t.same(
clean(workspaces, path),
new Map(Object.entries({
a: '{PATH}/packages/a',
@@ -142,7 +142,7 @@ t.test('get-workspaces', async t => {
)
workspaces = await getWorkspaces([resolve(path, './packages')], { path })
- t.deepEqual(
+ t.same(
clean(workspaces, path),
new Map(Object.entries({
a: '{PATH}/packages/a',
@@ -156,7 +156,7 @@ t.test('get-workspaces', async t => {
)
workspaces = await getWorkspaces([], { path })
- t.deepEqual(
+ t.same(
clean(workspaces, path),
new Map(Object.entries({
a: '{PATH}/packages/a',