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
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2020-11-17 04:56:54 +0300
committerRuy Adorno <ruyadorno@hotmail.com>2020-11-17 22:38:18 +0300
commitb1d850960fda95650cd828a7bd8586648d9e2672 (patch)
tree2f9f436ccdf8b97bcaa87a5e0d236c33068d9444 /test/lib/utils
parentde82b6257d6cb81809be8f9e290d4962929e0c25 (diff)
lint tests before publishing
We have a lot of tests that were not handling errors in callbacks, not defining variables, defining variables that weren't used, and just generally not formatted like the rest of npm. Hazard of moving fast. Thankfully, machines can help.
Diffstat (limited to 'test/lib/utils')
-rw-r--r--test/lib/utils/audit-error.js34
-rw-r--r--test/lib/utils/cleanup-log-files.js20
-rw-r--r--test/lib/utils/completion/installed-deep.js122
-rw-r--r--test/lib/utils/completion/installed-shallow.js56
-rw-r--r--test/lib/utils/completion/none.js2
-rw-r--r--test/lib/utils/config.js49
-rw-r--r--test/lib/utils/error-handler.js52
-rw-r--r--test/lib/utils/error-message.js102
-rw-r--r--test/lib/utils/escape-arg.js2
-rw-r--r--test/lib/utils/escape-exec-path.js2
-rw-r--r--test/lib/utils/explain-dep.js2
-rw-r--r--test/lib/utils/explain-eresolve.js2
-rw-r--r--test/lib/utils/file-exists.js4
-rw-r--r--test/lib/utils/flat-options.js52
-rw-r--r--test/lib/utils/get-identity.js34
-rw-r--r--test/lib/utils/get-project-scope.js10
-rw-r--r--test/lib/utils/hosted-git-info-from-manifest.js6
-rw-r--r--test/lib/utils/is-windows-bash.js4
-rw-r--r--test/lib/utils/is-windows-shell.js2
-rw-r--r--test/lib/utils/is-windows.js2
-rw-r--r--test/lib/utils/lifecycle-cmd.js6
-rw-r--r--test/lib/utils/path.js2
-rw-r--r--test/lib/utils/perf.js10
-rw-r--r--test/lib/utils/ping.js4
-rw-r--r--test/lib/utils/proc-log-listener.js16
-rw-r--r--test/lib/utils/read-local-package.js16
-rw-r--r--test/lib/utils/reify-output.js152
-rw-r--r--test/lib/utils/setup-log.js85
-rw-r--r--test/lib/utils/tar.js55
-rw-r--r--test/lib/utils/unsupported.js6
-rw-r--r--test/lib/utils/update-notifier.js33
31 files changed, 493 insertions, 451 deletions
diff --git a/test/lib/utils/audit-error.js b/test/lib/utils/audit-error.js
index f183a16e8..cc5f4c006 100644
--- a/test/lib/utils/audit-error.js
+++ b/test/lib/utils/audit-error.js
@@ -6,14 +6,14 @@ const npm = {
command: null,
flatOptions: {},
log: {
- warn: (...msg) => LOGS.push(msg)
- }
+ warn: (...msg) => LOGS.push(msg),
+ },
}
const OUTPUT = []
const output = (...msg) => OUTPUT.push(msg)
const auditError = requireInject('../../../lib/utils/audit-error.js', {
'../../../lib/npm.js': npm,
- '../../../lib/utils/output.js': output
+ '../../../lib/utils/output.js': output,
})
t.afterEach(cb => {
@@ -40,10 +40,10 @@ t.test('error, not audit command', t => {
method: 'POST',
uri: 'https://example.com/not/a/registry',
headers: {
- head: ['ers']
+ head: ['ers'],
},
- statusCode: '420'
- }
+ statusCode: '420',
+ },
}), true, 'had error')
t.strictSame(OUTPUT, [], 'no output')
t.strictSame(LOGS, [], 'no warnings')
@@ -60,14 +60,14 @@ t.test('error, audit command, not json', t => {
method: 'POST',
uri: 'https://example.com/not/a/registry',
headers: {
- head: ['ers']
+ head: ['ers'],
},
- statusCode: '420'
- }
+ statusCode: '420',
+ },
}))
- t.strictSame(OUTPUT, [ [ 'body' ] ], 'some output')
- t.strictSame(LOGS, [ [ 'audit', 'message' ] ], 'some warnings')
+ t.strictSame(OUTPUT, [['body']], 'some output')
+ t.strictSame(LOGS, [['audit', 'message']], 'some warnings')
t.end()
})
@@ -81,10 +81,10 @@ t.test('error, audit command, json', t => {
method: 'POST',
uri: 'https://example.com/not/a/registry',
headers: {
- head: ['ers']
+ head: ['ers'],
},
- statusCode: '420'
- }
+ statusCode: '420',
+ },
}))
t.strictSame(OUTPUT, [
@@ -102,9 +102,9 @@ t.test('error, audit command, json', t => {
' "body": {\n' +
' "response": "body"\n' +
' }\n' +
- '}'
- ]
+ '}',
+ ],
], 'some output')
- t.strictSame(LOGS, [ [ 'audit', 'message' ] ], 'some warnings')
+ t.strictSame(LOGS, [['audit', 'message']], 'some warnings')
t.end()
})
diff --git a/test/lib/utils/cleanup-log-files.js b/test/lib/utils/cleanup-log-files.js
index ee2c11e62..7af0633fe 100644
--- a/test/lib/utils/cleanup-log-files.js
+++ b/test/lib/utils/cleanup-log-files.js
@@ -6,7 +6,7 @@ const rimraf = require('rimraf')
const mocks = { glob, rimraf }
const cleanup = requireInject('../../../lib/utils/cleanup-log-files.js', {
glob: (...args) => mocks.glob(...args),
- rimraf: (...args) => mocks.rimraf(...args)
+ rimraf: (...args) => mocks.rimraf(...args),
})
const { basename } = require('path')
@@ -19,15 +19,15 @@ t.test('clean up those files', t => {
'2-debug.log': 'hello',
'3-debug.log': 'hello',
'4-debug.log': 'hello',
- '5-debug.log': 'hello'
- }
+ '5-debug.log': 'hello',
+ },
})
const warn = (...warning) => t.fail('failed cleanup', { warning })
return cleanup(cache, 3, warn).then(() => {
t.strictSame(fs.readdirSync(cache + '/_logs').sort(), [
'3-debug.log',
'4-debug.log',
- '5-debug.log'
+ '5-debug.log',
])
})
})
@@ -36,14 +36,14 @@ t.test('nothing to clean up', t => {
const cache = t.testdir({
_logs: {
'4-debug.log': 'hello',
- '5-debug.log': 'hello'
- }
+ '5-debug.log': 'hello',
+ },
})
const warn = (...warning) => t.fail('failed cleanup', { warning })
return cleanup(cache, 3, warn).then(() => {
t.strictSame(fs.readdirSync(cache + '/_logs').sort(), [
'4-debug.log',
- '5-debug.log'
+ '5-debug.log',
])
})
})
@@ -66,15 +66,15 @@ t.test('rimraf fail', t => {
'2-debug.log': 'hello',
'3-debug.log': 'hello',
'4-debug.log': 'hello',
- '5-debug.log': 'hello'
- }
+ '5-debug.log': 'hello',
+ },
})
const warnings = []
const warn = (...warning) => warnings.push(basename(warning[2]))
return cleanup(cache, 3, warn).then(() => {
t.strictSame(warnings.sort((a, b) => a.localeCompare(b)), [
'1-debug.log',
- '2-debug.log'
+ '2-debug.log',
])
})
})
diff --git a/test/lib/utils/completion/installed-deep.js b/test/lib/utils/completion/installed-deep.js
index 74c15e8f7..a2a375610 100644
--- a/test/lib/utils/completion/installed-deep.js
+++ b/test/lib/utils/completion/installed-deep.js
@@ -7,19 +7,25 @@ let globalDir = 'MISSING_GLOBAL_DIR'
const _flatOptions = {
depth: Infinity,
global: false,
- get prefix () { return prefix }
+ get prefix () {
+ return prefix
+ },
}
const installedDeep = requireInject('../../../../lib/utils/completion/installed-deep.js', {
'../../../../lib/npm.js': {
flatOptions: _flatOptions,
- get prefix () { return _flatOptions.prefix },
- get globalDir () { return globalDir },
+ get prefix () {
+ return _flatOptions.prefix
+ },
+ get globalDir () {
+ return globalDir
+ },
config: {
get (key) {
return _flatOptions[key]
- }
- }
- }
+ },
+ },
+ },
})
const fixture = {
@@ -29,14 +35,14 @@ const fixture = {
dependencies: {
a: '^1.0.0',
b: '^1.0.0',
- c: '^1.0.0'
+ c: '^1.0.0',
},
devDependencies: {
- d: '^1.0.0'
+ d: '^1.0.0',
},
peerDependencies: {
- e: '^1.0.0'
- }
+ e: '^1.0.0',
+ },
}),
node_modules: {
a: {
@@ -44,33 +50,33 @@ const fixture = {
name: 'a',
version: '1.0.0',
dependencies: {
- f: '^1.0.0'
- }
- })
+ f: '^1.0.0',
+ },
+ }),
},
b: {
'package.json': JSON.stringify({
name: 'b',
- version: '1.0.0'
- })
+ version: '1.0.0',
+ }),
},
c: {
'package.json': JSON.stringify({
name: 'c',
- version: '1.0.0'
- })
+ version: '1.0.0',
+ }),
},
d: {
'package.json': JSON.stringify({
name: 'd',
- version: '1.0.0'
- })
+ version: '1.0.0',
+ }),
},
e: {
'package.json': JSON.stringify({
name: 'e',
- version: '1.0.0'
- })
+ version: '1.0.0',
+ }),
},
f: {
'package.json': JSON.stringify({
@@ -78,8 +84,8 @@ const fixture = {
version: '1.0.0',
dependencies: {
g: '^1.0.0',
- e: '^2.0.0'
- }
+ e: '^2.0.0',
+ },
}),
node_modules: {
e: {
@@ -87,27 +93,27 @@ const fixture = {
name: 'e',
version: '2.0.0',
dependencies: {
- bb: '^1.0.0'
- }
+ bb: '^1.0.0',
+ },
}),
node_modules: {
bb: {
'package.json': JSON.stringify({
name: 'bb',
- version: '1.0.0'
- })
- }
- }
- }
- }
+ version: '1.0.0',
+ }),
+ },
+ },
+ },
+ },
},
g: {
'package.json': JSON.stringify({
name: 'g',
- version: '1.0.0'
- })
- }
- }
+ version: '1.0.0',
+ }),
+ },
+ },
}
const globalFixture = {
@@ -115,33 +121,33 @@ const globalFixture = {
foo: {
'package.json': JSON.stringify({
name: 'foo',
- version: '1.0.0'
- })
+ version: '1.0.0',
+ }),
},
bar: {
'package.json': JSON.stringify({
name: 'bar',
version: '1.0.0',
dependencies: {
- 'a-bar': '^1.0.0'
- }
+ 'a-bar': '^1.0.0',
+ },
}),
node_modules: {
'a-bar': {
'package.json': JSON.stringify({
name: 'a-bar',
- version: '1.0.0'
- })
- }
- }
- }
- }
+ version: '1.0.0',
+ }),
+ },
+ },
+ },
+ },
}
test('get list of package names', (t) => {
const fix = t.testdir({
local: fixture,
- global: globalFixture
+ global: globalFixture,
})
prefix = resolve(fix, 'local')
@@ -152,12 +158,12 @@ test('get list of package names', (t) => {
t.deepEqual(
res,
[
- [ 'bar', '-g' ],
- [ 'foo', '-g' ],
- [ 'a-bar', '-g' ],
+ ['bar', '-g'],
+ ['foo', '-g'],
+ ['a-bar', '-g'],
'a', 'b', 'c',
'd', 'e', 'f',
- 'g', 'bb'
+ 'g', 'bb',
],
'should return list of package names and global flag'
)
@@ -168,7 +174,7 @@ test('get list of package names', (t) => {
test('get list of package names as global', (t) => {
const fix = t.testdir({
local: fixture,
- global: globalFixture
+ global: globalFixture,
})
prefix = resolve(fix, 'local')
@@ -183,7 +189,7 @@ test('get list of package names as global', (t) => {
[
'bar',
'foo',
- 'a-bar'
+ 'a-bar',
],
'should return list of global packages with no extra flags'
)
@@ -195,7 +201,7 @@ test('get list of package names as global', (t) => {
test('limit depth', (t) => {
const fix = t.testdir({
local: fixture,
- global: globalFixture
+ global: globalFixture,
})
prefix = resolve(fix, 'local')
@@ -208,12 +214,12 @@ test('limit depth', (t) => {
t.deepEqual(
res,
[
- [ 'bar', '-g' ],
- [ 'foo', '-g' ],
+ ['bar', '-g'],
+ ['foo', '-g'],
'a', 'b',
'c', 'd',
'e', 'f',
- 'g'
+ 'g',
],
'should print only packages up to the specified depth'
)
@@ -225,7 +231,7 @@ test('limit depth', (t) => {
test('limit depth as global', (t) => {
const fix = t.testdir({
local: fixture,
- global: globalFixture
+ global: globalFixture,
})
prefix = resolve(fix, 'local')
@@ -240,7 +246,7 @@ test('limit depth as global', (t) => {
res,
[
'bar',
- 'foo'
+ 'foo',
],
'should reorder so that packages above that level depth goes last'
)
diff --git a/test/lib/utils/completion/installed-shallow.js b/test/lib/utils/completion/installed-shallow.js
index eb628a8ce..1d6369bc7 100644
--- a/test/lib/utils/completion/installed-shallow.js
+++ b/test/lib/utils/completion/installed-shallow.js
@@ -6,7 +6,7 @@ const { resolve } = require('path')
const p = '../../../../lib/utils/completion/installed-shallow.js'
const installed = requireInject(p, {
- '../../../../lib/npm.js': npm
+ '../../../../lib/npm.js': npm,
})
t.test('global not set, include globals with -g', t => {
@@ -15,32 +15,32 @@ t.test('global not set, include globals with -g', t => {
node_modules: {
x: {},
'@scope': {
- y: {}
- }
- }
+ y: {},
+ },
+ },
},
local: {
node_modules: {
a: {},
'@scope': {
- b: {}
- }
- }
- }
+ b: {},
+ },
+ },
+ },
})
npm.globalDir = resolve(dir, 'global/node_modules')
npm.localDir = resolve(dir, 'local/node_modules')
flatOptions.global = false
const opt = { conf: { argv: { remain: [] } } }
installed(opt, (er, res) => {
- if (er) {
+ if (er)
throw er
- }
+
t.strictSame(res.sort(), [
'@scope/y -g',
'x -g',
'a',
- '@scope/b'
+ '@scope/b',
].sort())
t.end()
})
@@ -52,18 +52,18 @@ t.test('global set, include globals and not locals', t => {
node_modules: {
x: {},
'@scope': {
- y: {}
- }
- }
+ y: {},
+ },
+ },
},
local: {
node_modules: {
a: {},
'@scope': {
- b: {}
- }
- }
- }
+ b: {},
+ },
+ },
+ },
})
npm.globalDir = resolve(dir, 'global/node_modules')
npm.localDir = resolve(dir, 'local/node_modules')
@@ -72,7 +72,7 @@ t.test('global set, include globals and not locals', t => {
installed(opt, (er, res) => {
t.strictSame(res.sort(), [
'@scope/y',
- 'x'
+ 'x',
].sort())
t.end()
})
@@ -84,27 +84,27 @@ t.test('more than 3 items in argv, skip it', t => {
node_modules: {
x: {},
'@scope': {
- y: {}
- }
- }
+ y: {},
+ },
+ },
},
local: {
node_modules: {
a: {},
'@scope': {
- b: {}
- }
- }
- }
+ b: {},
+ },
+ },
+ },
})
npm.globalDir = resolve(dir, 'global/node_modules')
npm.localDir = resolve(dir, 'local/node_modules')
flatOptions.global = false
const opt = { conf: { argv: { remain: [1, 2, 3, 4, 5, 6] } } }
installed(opt, (er, res) => {
- if (er) {
+ if (er)
throw er
- }
+
t.strictSame(res, null)
t.end()
})
diff --git a/test/lib/utils/completion/none.js b/test/lib/utils/completion/none.js
index 27f713b81..70488be07 100644
--- a/test/lib/utils/completion/none.js
+++ b/test/lib/utils/completion/none.js
@@ -1,6 +1,6 @@
const t = require('tap')
const none = require('../../../../lib/utils/completion/none.js')
-none({any:'thing'}, (er, res) => {
+none({any: 'thing'}, (er, res) => {
t.equal(er, null)
t.strictSame(res, [])
})
diff --git a/test/lib/utils/config.js b/test/lib/utils/config.js
index e8133eecb..38fbe6753 100644
--- a/test/lib/utils/config.js
+++ b/test/lib/utils/config.js
@@ -4,25 +4,25 @@ Object.defineProperty(process, 'umask', {
value: () => 0o26,
writable: true,
configurable: true,
- enumerable: true
+ enumerable: true,
})
// have to fake the node version, or else it'll only pass on this one
Object.defineProperty(process, 'version', {
- value: 'v14.8.0'
+ value: 'v14.8.0',
})
t.formatSnapshot = obj => {
- if (typeof obj !== 'object' || !obj || !obj.types) {
+ if (typeof obj !== 'object' || !obj || !obj.types)
return obj
- }
+
return {
...obj,
defaults: {
...obj.defaults,
- cache: '{CACHE DIR} ' + path.basename(obj.defaults.cache)
+ cache: '{CACHE DIR} ' + path.basename(obj.defaults.cache),
},
- types: formatTypes(obj.types)
+ types: formatTypes(obj.types),
}
}
@@ -38,19 +38,18 @@ const formatTypes = (types) => Object.entries(types).map(([key, value]) => {
}, {})
const formatTypeValue = (value) => {
- if (Array.isArray(value)) {
+ if (Array.isArray(value))
return value.map(formatTypeValue)
- } else if (value === url) {
+ else if (value === url)
return '{URL MODULE}'
- } else if (value === path) {
+ else if (value === path)
return '{PATH MODULE}'
- } else if (value === semver) {
+ else if (value === semver)
return '{SEMVER MODULE}'
- } else if (typeof value === 'function') {
+ else if (typeof value === 'function')
return `{${value.name} TYPE}`
- } else {
+ else
return value
- }
}
process.env.ComSpec = 'cmd.exe'
@@ -65,8 +64,8 @@ const networkInterfacesThrow = () => {
throw new Error('no network interfaces for some reason')
}
const networkInterfaces = () => ({
- 'eth420': [{ address: '127.0.0.1' }],
- 'eth69': [{ address: 'no place like home' }]
+ eth420: [{ address: '127.0.0.1' }],
+ eth69: [{ address: 'no place like home' }],
})
const tmpdir = () => '/tmp'
const os = { networkInterfaces, tmpdir }
@@ -77,7 +76,7 @@ t.test('working network interfaces, not windows', t => {
os,
'@npmcli/ci-detect': () => false,
'../../../lib/utils/is-windows.js': false,
- '../../../package.json': pkg
+ '../../../package.json': pkg,
})
t.matchSnapshot(config)
t.end()
@@ -88,7 +87,7 @@ t.test('no working network interfaces, on windows', t => {
os: { tmpdir, networkInterfaces: networkInterfacesThrow },
'@npmcli/ci-detect': () => false,
'../../../lib/utils/is-windows.js': true,
- '../../../package.json': pkg
+ '../../../package.json': pkg,
})
t.matchSnapshot(config)
t.end()
@@ -99,21 +98,21 @@ t.test('no process.umask() method', t => {
value: null,
writable: true,
configurable: true,
- enumerable: true
+ enumerable: true,
})
t.teardown(() => {
Object.defineProperty(process, 'umask', {
value: () => 0o26,
writable: true,
configurable: true,
- enumerable: true
+ enumerable: true,
})
})
const config = requireInject('../../../lib/utils/config.js', {
os: { tmpdir, networkInterfaces: networkInterfacesThrow },
'@npmcli/ci-detect': () => false,
'../../../lib/utils/is-windows.js': true,
- '../../../package.json': pkg
+ '../../../package.json': pkg,
})
t.equal(config.defaults.umask, 0o22)
t.matchSnapshot(config)
@@ -125,7 +124,7 @@ t.test('no comspec on windows', t => {
const config = requireInject('../../../lib/utils/config.js', {
os: { tmpdir, networkInterfaces: networkInterfacesThrow },
'@npmcli/ci-detect': () => false,
- '../../../lib/utils/is-windows.js': true
+ '../../../lib/utils/is-windows.js': true,
})
t.equal(config.defaults.shell, 'cmd')
t.end()
@@ -136,7 +135,7 @@ t.test('no shell on posix', t => {
const config = requireInject('../../../lib/utils/config.js', {
os,
'@npmcli/ci-detect': () => false,
- '../../../lib/utils/is-windows.js': false
+ '../../../lib/utils/is-windows.js': false,
})
t.equal(config.defaults.shell, 'sh')
t.end()
@@ -147,7 +146,7 @@ t.test('no EDITOR env, use VISUAL', t => {
const config = requireInject('../../../lib/utils/config.js', {
os,
'@npmcli/ci-detect': () => false,
- '../../../lib/utils/is-windows.js': false
+ '../../../lib/utils/is-windows.js': false,
})
t.equal(config.defaults.editor, 'mate')
t.end()
@@ -158,7 +157,7 @@ t.test('no VISUAL, use system default, not windows', t => {
const config = requireInject('../../../lib/utils/config.js', {
os,
'@npmcli/ci-detect': () => false,
- '../../../lib/utils/is-windows.js': false
+ '../../../lib/utils/is-windows.js': false,
})
t.equal(config.defaults.editor, 'vi')
t.end()
@@ -169,7 +168,7 @@ t.test('no VISUAL, use system default, not windows', t => {
const config = requireInject('../../../lib/utils/config.js', {
os,
'@npmcli/ci-detect': () => false,
- '../../../lib/utils/is-windows.js': true
+ '../../../lib/utils/is-windows.js': true,
})
t.equal(config.defaults.editor, 'notepad.exe')
t.end()
diff --git a/test/lib/utils/error-handler.js b/test/lib/utils/error-handler.js
index 9e32dfc5f..2dc116a4d 100644
--- a/test/lib/utils/error-handler.js
+++ b/test/lib/utils/error-handler.js
@@ -26,23 +26,23 @@ t.cleanSnapshot = (str) => redactCwd(str)
// internal modules mocks
const cacheFile = {
append: () => null,
- write: () => null
+ write: () => null,
}
const config = {
values: {
cache: 'cachefolder',
- timing: true
+ timing: true,
},
loaded: true,
updateNotification: null,
get (key) {
return this.values[key]
- }
+ },
}
const npm = {
version: '1.0.0',
- config
+ config,
}
const npmlog = {
@@ -52,26 +52,34 @@ const npmlog = {
id: this.record.length,
level,
message: args.reduce((res, i) => `${res} ${i.message ? i.message : i}`, ''),
- prefix: level !== 'verbose' ? 'foo' : ''
+ prefix: level !== 'verbose' ? 'foo' : '',
})
},
- error (...args) { this.log('error', ...args) },
- info (...args) { this.log('info', ...args) },
+ error (...args) {
+ this.log('error', ...args)
+ },
+ info (...args) {
+ this.log('info', ...args)
+ },
level: 'silly',
levels: {
silly: 0,
verbose: 1,
info: 2,
error: 3,
- silent: 4
+ silent: 4,
+ },
+ notice (...args) {
+ this.log('notice', ...args)
},
- notice (...args) { this.log('notice', ...args) },
record: [],
- verbose (...args) { this.log('verbose', ...args) }
+ verbose (...args) {
+ this.log('verbose', ...args)
+ },
}
const metrics = {
- stop: () => null
+ stop: () => null,
}
// overrides OS type/release for cross platform snapshots
@@ -96,8 +104,10 @@ process = Object.assign(
exit () {},
exitCode: 0,
version: 'v1.0.0',
- stdout: { write (_, cb) { cb() } },
- stderr: { write () {} }
+ stdout: { write (_, cb) {
+ cb()
+ } },
+ stderr: { write () {} },
}
)
// needs to put process back in its place
@@ -112,10 +122,10 @@ const mocks = {
'../../../lib/utils/error-message.js': (err) => ({
...err,
summary: [['ERR', err.message]],
- detail: [['ERR', err.message]]
+ detail: [['ERR', err.message]],
}),
'../../../lib/utils/metrics.js': metrics,
- '../../../lib/utils/cache-file.js': cacheFile
+ '../../../lib/utils/cache-file.js': cacheFile,
}
requireInject.installGlobally('../../../lib/utils/error-handler.js', mocks)
@@ -226,8 +236,8 @@ t.test('console.log output using --json', (t) => {
error: {
code: 'EBADTHING', // should default error code to E[A-Z]+
summary: 'Error: EBADTHING Something happened',
- detail: 'Error: EBADTHING Something happened'
- }
+ detail: 'Error: EBADTHING Something happened',
+ },
},
'should output expected json output'
)
@@ -246,7 +256,7 @@ t.test('throw a non-error obj', (t) => {
const weirdError = {
code: 'ESOMETHING',
- message: 'foo bar'
+ message: 'foo bar',
}
const _logError = npmlog.error
@@ -379,7 +389,7 @@ t.test('uses code from errno', (t) => {
errorHandler(Object.assign(
new Error('Error with errno'),
{
- errno: 127
+ errno: 127,
}
))
@@ -408,7 +418,7 @@ t.test('uses exitCode as code if using a number', (t) => {
errorHandler(Object.assign(
new Error('Error with code type number'),
{
- code: 404
+ code: 404,
}
))
@@ -464,7 +474,7 @@ t.test('defaults to log error msg if stack is missing', (t) => {
new Error('Error with no stack'),
{
code: 'ENOSTACK',
- errno: 127
+ errno: 127,
}
)
delete noStackErr.stack
diff --git a/test/lib/utils/error-message.js b/test/lib/utils/error-message.js
index 2647a8e19..86db7c94b 100644
--- a/test/lib/utils/error-message.js
+++ b/test/lib/utils/error-message.js
@@ -7,13 +7,13 @@ process.getgid = () => 420
Object.defineProperty(process, 'arch', {
value: 'x64',
- configurable: true
+ configurable: true,
})
const beWindows = () => {
Object.defineProperty(process, 'platform', {
value: 'win32',
- configurable: true
+ configurable: true,
})
delete require.cache[require.resolve('../../../lib/utils/is-windows.js')]
}
@@ -21,7 +21,7 @@ const beWindows = () => {
const bePosix = () => {
Object.defineProperty(process, 'platform', {
value: 'posix',
- configurable: true
+ configurable: true,
})
delete require.cache[require.resolve('../../../lib/utils/is-windows.js')]
}
@@ -33,22 +33,21 @@ npm.config = {
loaded: false,
localPrefix: '/some/prefix/dir',
get: key => {
- if (key === 'cache') {
+ if (key === 'cache')
return CACHE
- } else if (key === 'node-version') {
+ else if (key === 'node-version')
return '99.99.99'
- } else if (key === 'global') {
+ else if (key === 'global')
return false
- } else {
+ else
throw new Error('unexpected config lookup: ' + key)
- }
- }
+ },
}
npm.version = '123.69.420-npm'
Object.defineProperty(process, 'version', {
value: '123.69.420-node',
- configurable: true
+ configurable: true,
})
const npmlog = require('npmlog')
@@ -64,8 +63,8 @@ const errorMessage = requireInject('../../../lib/utils/error-message.js', {
report: (...args) => {
EXPLAIN_CALLED.push(args)
return 'explanation'
- }
- }
+ },
+ },
})
t.test('just simple messages', t => {
@@ -92,7 +91,7 @@ t.test('just simple messages', t => {
'EINVALIDTYPE',
'ETOOMANYARGS',
'ETARGET',
- 'E403'
+ 'E403',
]
t.plan(codes.length)
codes.forEach(code => {
@@ -100,13 +99,12 @@ t.test('just simple messages', t => {
const pkgid = 'some@package'
const file = '/some/file'
const stack = 'dummy stack trace'
- const required = { node: '1.2.3', npm: '4.2.0' }
const er = Object.assign(new Error('foo'), {
code,
path,
pkgid,
file,
- stack
+ stack,
})
t.matchSnapshot(errorMessage(er))
})
@@ -132,18 +130,19 @@ t.test('replace message/stack sensistive info', t => {
t.test('bad engine with config loaded', t => {
npm.config.loaded = true
- t.teardown(() => { npm.config.loaded = false })
+ t.teardown(() => {
+ npm.config.loaded = false
+ })
const path = '/some/path'
const pkgid = 'some@package'
const file = '/some/file'
const stack = 'dummy stack trace'
- const required = { node: '1.2.3', npm: '4.2.0' }
const er = Object.assign(new Error('foo'), {
code: 'EBADENGINE',
path,
pkgid,
file,
- stack
+ stack,
})
t.matchSnapshot(errorMessage(er))
t.end()
@@ -152,14 +151,12 @@ t.test('bad engine with config loaded', t => {
t.test('enoent without a file', t => {
const path = '/some/path'
const pkgid = 'some@package'
- const file = '/some/file'
const stack = 'dummy stack trace'
- const required = { node: '1.2.3', npm: '4.2.0' }
const er = Object.assign(new Error('foo'), {
code: 'ENOENT',
path,
pkgid,
- stack
+ stack,
})
t.matchSnapshot(errorMessage(er))
t.end()
@@ -171,13 +168,12 @@ t.test('enolock without a command', t => {
const pkgid = 'some@package'
const file = '/some/file'
const stack = 'dummy stack trace'
- const required = { node: '1.2.3', npm: '4.2.0' }
const er = Object.assign(new Error('foo'), {
code: 'ENOLOCK',
path,
pkgid,
file,
- stack
+ stack,
})
t.matchSnapshot(errorMessage(er))
t.end()
@@ -191,18 +187,18 @@ t.test('default message', t => {
signal: 'SIGYOLO',
args: ['a', 'r', 'g', 's'],
stdout: 'stdout',
- stderr: 'stderr'
+ stderr: 'stderr',
})))
t.end()
})
t.test('eacces/eperm', t => {
const runTest = (windows, loaded, cachePath, cacheDest) => t => {
- if (windows) {
+ if (windows)
beWindows()
- } else {
+ else
bePosix()
- }
+
npm.config.loaded = loaded
const path = `${cachePath ? CACHE : '/not/cache/dir'}/path`
const dest = `${cacheDest ? CACHE : '/not/cache/dir'}/dest`
@@ -210,7 +206,7 @@ t.test('eacces/eperm', t => {
code: 'EACCES',
path,
dest,
- stack: 'dummy stack trace'
+ stack: 'dummy stack trace',
})
verboseLogs.length = 0
t.matchSnapshot(errorMessage(er))
@@ -272,36 +268,36 @@ t.test('json parse', t => {
}
}
}
-`
+`,
})
const { prefix } = npm
const { argv } = process
t.teardown(() => {
Object.defineProperty(npm, 'prefix', {
value: prefix,
- configurable: true
+ configurable: true,
})
process.argv = argv
})
Object.defineProperty(npm, 'prefix', { value: dir, configurable: true })
process.argv = ['arg', 'v']
- const ok = t.matchSnapshot(errorMessage(Object.assign(new Error('conflicted'), {
+ t.matchSnapshot(errorMessage(Object.assign(new Error('conflicted'), {
code: 'EJSONPARSE',
- file: resolve(dir, 'package.json')
+ file: resolve(dir, 'package.json'),
})))
t.end()
})
t.test('just regular bad json in package.json', t => {
const dir = t.testdir({
- 'package.json': 'not even slightly json'
+ 'package.json': 'not even slightly json',
})
const { prefix } = npm
const { argv } = process
t.teardown(() => {
Object.defineProperty(npm, 'prefix', {
value: prefix,
- configurable: true
+ configurable: true,
})
process.argv = argv
})
@@ -309,14 +305,14 @@ t.test('json parse', t => {
process.argv = ['arg', 'v']
t.matchSnapshot(errorMessage(Object.assign(new Error('not json'), {
code: 'EJSONPARSE',
- file: resolve(dir, 'package.json')
+ file: resolve(dir, 'package.json'),
})))
t.end()
})
t.test('json somewhere else', t => {
const dir = t.testdir({
- 'blerg.json': 'not even slightly json'
+ 'blerg.json': 'not even slightly json',
})
const { argv } = process
t.teardown(() => {
@@ -325,7 +321,7 @@ t.test('json parse', t => {
process.argv = ['arg', 'v']
t.matchSnapshot(errorMessage(Object.assign(new Error('not json'), {
code: 'EJSONPARSE',
- file: `${dir}/blerg.json`
+ file: `${dir}/blerg.json`,
})))
t.end()
})
@@ -336,7 +332,7 @@ t.test('json parse', t => {
t.test('eotp/e401', t => {
t.test('401, no auth headers', t => {
t.matchSnapshot(errorMessage(Object.assign(new Error('nope'), {
- code: 'E401'
+ code: 'E401',
})))
t.end()
})
@@ -350,7 +346,7 @@ t.test('eotp/e401', t => {
t.test('one-time pass challenge code', t => {
t.matchSnapshot(errorMessage(Object.assign(new Error('nope'), {
- code: 'EOTP'
+ code: 'EOTP',
})))
t.end()
})
@@ -358,7 +354,7 @@ t.test('eotp/e401', t => {
t.test('one-time pass challenge message', t => {
const message = 'one-time pass'
t.matchSnapshot(errorMessage(Object.assign(new Error(message), {
- code: 'E401'
+ code: 'E401',
})))
t.end()
})
@@ -368,16 +364,16 @@ t.test('eotp/e401', t => {
'Bearer realm=do, charset="UTF-8", challenge="yourself"',
'Basic realm=by, charset="UTF-8", challenge="your friends"',
'PickACardAnyCard realm=friday, charset="UTF-8"',
- 'WashYourHands, charset="UTF-8"'
+ 'WashYourHands, charset="UTF-8"',
]
t.plan(auths.length)
for (const auth of auths) {
t.test(auth, t => {
const er = Object.assign(new Error('challenge!'), {
headers: {
- 'www-authenticate': [ auth ]
+ 'www-authenticate': [auth],
},
- code: 'E401'
+ code: 'E401',
})
t.matchSnapshot(errorMessage(er))
t.end()
@@ -397,7 +393,7 @@ t.test('404', t => {
t.test('you should publish it', t => {
const er = Object.assign(new Error('404 not found'), {
pkgid: 'yolo',
- code: 'E404'
+ code: 'E404',
})
t.matchSnapshot(errorMessage(er))
t.end()
@@ -405,7 +401,7 @@ t.test('404', t => {
t.test('name with warning', t => {
const er = Object.assign(new Error('404 not found'), {
pkgid: new Array(215).fill('x').join(''),
- code: 'E404'
+ code: 'E404',
})
t.matchSnapshot(errorMessage(er))
t.end()
@@ -413,7 +409,7 @@ t.test('404', t => {
t.test('name with error', t => {
const er = Object.assign(new Error('404 not found'), {
pkgid: 'node_modules',
- code: 'E404'
+ code: 'E404',
})
t.matchSnapshot(errorMessage(er))
t.end()
@@ -427,13 +423,13 @@ t.test('bad platform', t => {
pkgid: 'lodash@1.0.0',
current: {
os: 'posix',
- cpu: 'x64'
+ cpu: 'x64',
},
required: {
os: '!yours',
- cpu: 'x420'
+ cpu: 'x420',
},
- code: 'EBADPLATFORM'
+ code: 'EBADPLATFORM',
})
t.matchSnapshot(errorMessage(er))
t.end()
@@ -443,13 +439,13 @@ t.test('bad platform', t => {
pkgid: 'lodash@1.0.0',
current: {
os: 'posix',
- cpu: 'x64'
+ cpu: 'x64',
},
required: {
os: ['!yours', 'mine'],
- cpu: ['x420', 'x69']
+ cpu: ['x420', 'x69'],
},
- code: 'EBADPLATFORM'
+ code: 'EBADPLATFORM',
})
t.matchSnapshot(errorMessage(er))
t.end()
@@ -460,7 +456,7 @@ t.test('bad platform', t => {
t.test('explain ERESOLVE errors', t => {
const er = Object.assign(new Error('could not resolve'), {
- code: 'ERESOLVE'
+ code: 'ERESOLVE',
})
t.matchSnapshot(errorMessage(er))
t.strictSame(EXPLAIN_CALLED, [[er]])
diff --git a/test/lib/utils/escape-arg.js b/test/lib/utils/escape-arg.js
index 413fa4783..b80a63f0b 100644
--- a/test/lib/utils/escape-arg.js
+++ b/test/lib/utils/escape-arg.js
@@ -2,7 +2,7 @@ const requireInject = require('require-inject')
const t = require('tap')
const getEscape = win => requireInject('../../../lib/utils/escape-arg.js', {
'../../../lib/utils/is-windows.js': win,
- path: require('path')[win ? 'win32' : 'posix']
+ path: require('path')[win ? 'win32' : 'posix'],
})
const winEscape = getEscape(true)
diff --git a/test/lib/utils/escape-exec-path.js b/test/lib/utils/escape-exec-path.js
index 28fe75c2a..f16c576ec 100644
--- a/test/lib/utils/escape-exec-path.js
+++ b/test/lib/utils/escape-exec-path.js
@@ -2,7 +2,7 @@ const requireInject = require('require-inject')
const t = require('tap')
const getEscape = win => requireInject('../../../lib/utils/escape-exec-path.js', {
'../../../lib/utils/is-windows.js': win,
- path: require('path')[win ? 'win32' : 'posix']
+ path: require('path')[win ? 'win32' : 'posix'],
})
const winEscape = getEscape(true)
diff --git a/test/lib/utils/explain-dep.js b/test/lib/utils/explain-dep.js
index 9a205e3c3..28f14477a 100644
--- a/test/lib/utils/explain-dep.js
+++ b/test/lib/utils/explain-dep.js
@@ -143,7 +143,7 @@ cases.manyDeps = {
{
type: 'prod',
name: 'manydep',
- spec:'>1.0.0-beta <1.0.1',
+ spec: '>1.0.0-beta <1.0.1',
from: {
location: '/path/to/project',
},
diff --git a/test/lib/utils/explain-eresolve.js b/test/lib/utils/explain-eresolve.js
index def13153d..8dae1b92c 100644
--- a/test/lib/utils/explain-eresolve.js
+++ b/test/lib/utils/explain-eresolve.js
@@ -2,7 +2,7 @@ const t = require('tap')
const requireInject = require('require-inject')
const npm = {}
const { explain, report } = requireInject('../../../lib/utils/explain-eresolve.js', {
- '../../../lib/npm.js': npm
+ '../../../lib/npm.js': npm,
})
const { statSync, readFileSync, unlinkSync } = require('fs')
// strip out timestamps from reports
diff --git a/test/lib/utils/file-exists.js b/test/lib/utils/file-exists.js
index f247f564e..473a4b050 100644
--- a/test/lib/utils/file-exists.js
+++ b/test/lib/utils/file-exists.js
@@ -3,7 +3,7 @@ const fileExists = require('../../../lib/utils/file-exists.js')
test('returns true when arg is a file', async (t) => {
const path = t.testdir({
- foo: 'just some file'
+ foo: 'just some file',
})
const result = await fileExists(`${path}/foo`)
@@ -13,7 +13,7 @@ test('returns true when arg is a file', async (t) => {
test('returns false when arg is not a file', async (t) => {
const path = t.testdir({
- foo: {}
+ foo: {},
})
const result = await fileExists(`${path}/foo`)
diff --git a/test/lib/utils/flat-options.js b/test/lib/utils/flat-options.js
index 7601c78d2..82c00fc7e 100644
--- a/test/lib/utils/flat-options.js
+++ b/test/lib/utils/flat-options.js
@@ -12,7 +12,7 @@ class Mocknpm {
this.modes = {
exec: 0o777,
file: 0o666,
- umask: 0o22
+ umask: 0o22,
}
this.color = true
this.projectScope = '@npmcli'
@@ -110,14 +110,16 @@ class MockConfig {
'user-agent': 'user-agent',
'@scope:registry': '@scope:registry',
'//nerf.dart:_authToken': '//nerf.dart:_authToken',
- 'proxy': 'proxy',
- 'noproxy': 'noproxy',
- ...opts
+ proxy: 'proxy',
+ noproxy: 'noproxy',
+ ...opts,
}]
}
+
get (key) {
return this.list[0][key]
}
+
set (key, val) {
this.list[0][key] = val
}
@@ -127,7 +129,7 @@ const flatOptions = require('../../../lib/utils/flat-options.js')
t.match(logs, [[
'verbose',
'npm-session',
- /^[0-9a-f]{16}$/
+ /^[0-9a-f]{16}$/,
]], 'logged npm session verbosely')
logs.length = 0
@@ -139,7 +141,7 @@ t.test('basic', t => {
npmBin: '/path/to/npm/bin.js',
log: {},
npmSession: '12345',
- cache: generatedFlat.cache.replace(/\\/g, '/')
+ cache: generatedFlat.cache.replace(/\\/g, '/'),
}
t.matchSnapshot(clean, 'flat options')
t.equal(generatedFlat.npmCommand, null, 'command not set yet')
@@ -158,7 +160,7 @@ t.test('basic', t => {
t.test('get preferOffline from cache-min', t => {
const npm = new Mocknpm({
'cache-min': 9999999,
- 'prefer-offline': undefined
+ 'prefer-offline': undefined,
})
const opts = flatOptions(npm)
t.equal(opts.preferOffline, true, 'got preferOffline from cache min')
@@ -172,7 +174,7 @@ t.test('get preferOffline from cache-min', t => {
t.test('get preferOnline from cache-max', t => {
const npm = new Mocknpm({
'cache-max': -1,
- 'prefer-online': undefined
+ 'prefer-online': undefined,
})
const opts = flatOptions(npm)
t.equal(opts.preferOnline, true, 'got preferOnline from cache min')
@@ -194,7 +196,7 @@ t.test('tag emits warning', t => {
t.test('omit/include options', t => {
t.test('omit explicitly', t => {
const npm = new Mocknpm({
- omit: ['dev', 'optional', 'peer']
+ omit: ['dev', 'optional', 'peer'],
})
t.strictSame(flatOptions(npm).omit, ['dev', 'optional', 'peer'])
t.end()
@@ -203,7 +205,7 @@ t.test('omit/include options', t => {
t.test('omit and include some', t => {
const npm = new Mocknpm({
omit: ['dev', 'optional', 'peer'],
- include: ['peer']
+ include: ['peer'],
})
t.strictSame(flatOptions(npm).omit, ['dev', 'optional'])
t.end()
@@ -213,7 +215,7 @@ t.test('omit/include options', t => {
const npm = new Mocknpm({
omit: ['dev', 'optional', 'peer'],
include: [],
- dev: true
+ dev: true,
})
t.strictSame(flatOptions(npm).omit, ['optional', 'peer'])
t.end()
@@ -223,7 +225,7 @@ t.test('omit/include options', t => {
const npm = new Mocknpm({
omit: [],
include: [],
- production: true
+ production: true,
})
t.strictSame(flatOptions(npm).omit, ['dev'])
t.end()
@@ -236,7 +238,7 @@ t.test('omit/include options', t => {
const npm = new Mocknpm({
omit: [],
include: [],
- only: c
+ only: c,
})
t.strictSame(flatOptions(npm).omit, ['dev'])
t.end()
@@ -246,7 +248,7 @@ t.test('omit/include options', t => {
t.test('also dev', t => {
const npm = new Mocknpm({
omit: ['dev', 'optional', 'peer'],
- also: 'dev'
+ also: 'dev',
})
t.strictSame(flatOptions(npm).omit, ['optional', 'peer'])
t.end()
@@ -256,7 +258,7 @@ t.test('omit/include options', t => {
const npm = new Mocknpm({
optional: false,
omit: null,
- include: null
+ include: null,
})
t.strictSame(flatOptions(npm).omit, ['optional'])
t.end()
@@ -276,9 +278,9 @@ t.test('various default values and falsey fallbacks', t => {
'script-shell': false,
registry: 'http://example.com',
'metrics-registry': null,
- 'searchlimit': 0,
+ searchlimit: 0,
'save-exact': false,
- 'save-prefix': '>='
+ 'save-prefix': '>=',
})
const opts = flatOptions(npm)
t.equal(opts.scriptShell, undefined, 'scriptShell is undefined if falsey')
@@ -298,7 +300,7 @@ t.test('legacy _auth token', t => {
t.strictSame(
flatOptions(npm)._auth,
'asdfasdf',
- 'should set legacy _auth token',
+ 'should set legacy _auth token'
)
t.end()
})
@@ -308,7 +310,7 @@ t.test('save-type', t => {
'save-optional': false,
'save-peer': false,
'save-dev': false,
- 'save-prod': false
+ 'save-prod': false,
}
const cases = [
['peerOptional', {
@@ -316,23 +318,23 @@ t.test('save-type', t => {
'save-peer': true,
}],
['optional', {
- 'save-optional': true
+ 'save-optional': true,
}],
['dev', {
- 'save-dev': true
+ 'save-dev': true,
}],
['peer', {
- 'save-peer': true
+ 'save-peer': true,
}],
['prod', {
- 'save-prod': true
+ 'save-prod': true,
}],
- [null, {}]
+ [null, {}],
]
for (const [expect, options] of cases) {
const opts = flatOptions(new Mocknpm({
...base,
- ...options
+ ...options,
}))
t.equal(opts.saveType, expect, JSON.stringify(options))
}
diff --git a/test/lib/utils/get-identity.js b/test/lib/utils/get-identity.js
index c72f48b2e..8a4de8835 100644
--- a/test/lib/utils/get-identity.js
+++ b/test/lib/utils/get-identity.js
@@ -4,7 +4,7 @@ const requireInject = require('require-inject')
test('throws ENOREGISTRY when no registry option is provided', async (t) => {
t.plan(2)
const getIdentity = requireInject('../../../lib/utils/get-identity.js', {
- '../../../lib/npm.js': {}
+ '../../../lib/npm.js': {},
})
try {
@@ -23,9 +23,9 @@ test('returns username from uri when provided', async (t) => {
config: {
getCredentialsByURI: () => {
return { username: 'foo' }
- }
- }
- }
+ },
+ },
+ },
})
const identity = await getIdentity({ registry: 'https://registry.npmjs.org' })
@@ -37,22 +37,22 @@ test('calls registry whoami when token is provided', async (t) => {
const options = {
registry: 'https://registry.npmjs.org',
- token: 'thisisnotreallyatoken'
+ token: 'thisisnotreallyatoken',
}
const getIdentity = requireInject('../../../lib/utils/get-identity.js', {
'../../../lib/npm.js': {
config: {
- getCredentialsByURI: () => options
- }
+ getCredentialsByURI: () => options,
+ },
},
'npm-registry-fetch': {
json: (path, opts) => {
t.equal(path, '/-/whoami', 'calls whoami')
t.same(opts, options, 'passes through provided options')
return { username: 'foo' }
- }
- }
+ },
+ },
})
const identity = await getIdentity(options)
@@ -64,22 +64,22 @@ test('throws ENEEDAUTH when response does not include a username', async (t) =>
const options = {
registry: 'https://registry.npmjs.org',
- token: 'thisisnotreallyatoken'
+ token: 'thisisnotreallyatoken',
}
const getIdentity = requireInject('../../../lib/utils/get-identity.js', {
'../../../lib/npm.js': {
config: {
- getCredentialsByURI: () => options
- }
+ getCredentialsByURI: () => options,
+ },
},
'npm-registry-fetch': {
json: (path, opts) => {
t.equal(path, '/-/whoami', 'calls whoami')
t.same(opts, options, 'passes through provided options')
return {}
- }
- }
+ },
+ },
})
try {
@@ -94,9 +94,9 @@ test('throws ENEEDAUTH when neither username nor token is configured', async (t)
const getIdentity = requireInject('../../../lib/utils/get-identity.js', {
'../../../lib/npm.js': {
config: {
- getCredentialsByURI: () => ({})
- }
- }
+ getCredentialsByURI: () => ({}),
+ },
+ },
})
try {
diff --git a/test/lib/utils/get-project-scope.js b/test/lib/utils/get-project-scope.js
index 15ab2bdef..9737b0643 100644
--- a/test/lib/utils/get-project-scope.js
+++ b/test/lib/utils/get-project-scope.js
@@ -3,7 +3,7 @@ const t = require('tap')
t.test('package.json with scope', t => {
const dir = t.testdir({
- 'package.json': JSON.stringify({ name: '@foo/bar' })
+ 'package.json': JSON.stringify({ name: '@foo/bar' }),
})
t.equal(getProjectScope(dir), '@foo')
t.end()
@@ -11,7 +11,7 @@ t.test('package.json with scope', t => {
t.test('package.json with slash, but no @', t => {
const dir = t.testdir({
- 'package.json': JSON.stringify({ name: 'foo/bar' })
+ 'package.json': JSON.stringify({ name: 'foo/bar' }),
})
t.equal(getProjectScope(dir), '')
t.end()
@@ -19,7 +19,7 @@ t.test('package.json with slash, but no @', t => {
t.test('package.json without scope', t => {
const dir = t.testdir({
- 'package.json': JSON.stringify({ name: 'foo' })
+ 'package.json': JSON.stringify({ name: 'foo' }),
})
t.equal(getProjectScope(dir), '')
t.end()
@@ -27,7 +27,7 @@ t.test('package.json without scope', t => {
t.test('package.json without name', t => {
const dir = t.testdir({
- 'package.json': JSON.stringify({})
+ 'package.json': JSON.stringify({}),
})
t.equal(getProjectScope(dir), '')
t.end()
@@ -35,7 +35,7 @@ t.test('package.json without name', t => {
t.test('package.json not JSON', t => {
const dir = t.testdir({
- 'package.json': 'hello'
+ 'package.json': 'hello',
})
t.equal(getProjectScope(dir), '')
t.end()
diff --git a/test/lib/utils/hosted-git-info-from-manifest.js b/test/lib/utils/hosted-git-info-from-manifest.js
index f87cb84ee..516d3d586 100644
--- a/test/lib/utils/hosted-git-info-from-manifest.js
+++ b/test/lib/utils/hosted-git-info-from-manifest.js
@@ -9,13 +9,13 @@ t.equal(hostedFromMani({ repository: 'not hosted anywhere' }), null)
t.equal(hostedFromMani({ repository: { url: 'not hosted anywhere' } }), null)
t.match(hostedFromMani({
- repository: 'git+https://github.com/isaacs/abbrev-js'
+ repository: 'git+https://github.com/isaacs/abbrev-js',
}), hostedGitInfo.fromUrl('git+https://github.com/isaacs/abbrev-js'))
t.match(hostedFromMani({
- repository: { url: 'git+https://github.com/isaacs/abbrev-js' }
+ repository: { url: 'git+https://github.com/isaacs/abbrev-js' },
}), hostedGitInfo.fromUrl('https://github.com/isaacs/abbrev-js'))
t.match(hostedFromMani({
- repository: { url: 'git+ssh://git@github.com/isaacs/abbrev-js' }
+ repository: { url: 'git+ssh://git@github.com/isaacs/abbrev-js' },
}), hostedGitInfo.fromUrl('ssh://git@github.com/isaacs/abbrev-js'))
diff --git a/test/lib/utils/is-windows-bash.js b/test/lib/utils/is-windows-bash.js
index 730dfe301..94fde0ace 100644
--- a/test/lib/utils/is-windows-bash.js
+++ b/test/lib/utils/is-windows-bash.js
@@ -8,13 +8,13 @@ const isWindowsBash = () => {
Object.defineProperty(process, 'platform', {
value: 'posix',
- configurable: true
+ configurable: true,
})
t.equal(isWindowsBash(), false, 'false when not windows')
Object.defineProperty(process, 'platform', {
value: 'win32',
- configurable: true
+ configurable: true,
})
process.env.MSYSTEM = 'not ming'
process.env.TERM = 'dumb'
diff --git a/test/lib/utils/is-windows-shell.js b/test/lib/utils/is-windows-shell.js
index e2164c222..95519925c 100644
--- a/test/lib/utils/is-windows-shell.js
+++ b/test/lib/utils/is-windows-shell.js
@@ -1,6 +1,6 @@
const t = require('tap')
Object.defineProperty(process, 'platform', {
- value: 'win32'
+ value: 'win32',
})
const isWindows = require('../../../lib/utils/is-windows.js')
const isWindowsBash = require('../../../lib/utils/is-windows-bash.js')
diff --git a/test/lib/utils/is-windows.js b/test/lib/utils/is-windows.js
index 910007169..f8f2999c9 100644
--- a/test/lib/utils/is-windows.js
+++ b/test/lib/utils/is-windows.js
@@ -2,7 +2,7 @@ const t = require('tap')
const actuallyWindows = process.platform === 'win32'
t.equal(actuallyWindows, require('../../../lib/utils/is-windows.js'))
Object.defineProperty(process, 'platform', {
- value: actuallyWindows ? 'posix' : 'win32'
+ value: actuallyWindows ? 'posix' : 'win32',
})
delete require.cache[require.resolve('../../../lib/utils/is-windows.js')]
t.equal(!actuallyWindows, require('../../../lib/utils/is-windows.js'))
diff --git a/test/lib/utils/lifecycle-cmd.js b/test/lib/utils/lifecycle-cmd.js
index 733822954..0eb342cee 100644
--- a/test/lib/utils/lifecycle-cmd.js
+++ b/test/lib/utils/lifecycle-cmd.js
@@ -3,9 +3,9 @@ const requireInject = require('require-inject')
const lifecycleCmd = requireInject('../../../lib/utils/lifecycle-cmd.js', {
'../../../lib/npm.js': {
commands: {
- run: (args, cb) => cb(null, 'called npm.commands.run')
- }
- }
+ run: (args, cb) => cb(null, 'called npm.commands.run'),
+ },
+ },
})
t.test('create a lifecycle command', t => {
diff --git a/test/lib/utils/path.js b/test/lib/utils/path.js
index facee0645..74fb93462 100644
--- a/test/lib/utils/path.js
+++ b/test/lib/utils/path.js
@@ -3,7 +3,7 @@ const requireInject = require('require-inject')
const mod = '../../../lib/utils/path.js'
const delim = require('../../../lib/utils/is-windows.js') ? ';' : ':'
Object.defineProperty(process, 'env', {
- value: {}
+ value: {},
})
process.env.path = ['foo', 'bar', 'baz'].join(delim)
t.strictSame(requireInject(mod), ['foo', 'bar', 'baz'])
diff --git a/test/lib/utils/perf.js b/test/lib/utils/perf.js
index 9b38a3da8..840dcb6e3 100644
--- a/test/lib/utils/perf.js
+++ b/test/lib/utils/perf.js
@@ -20,15 +20,15 @@ t.test('time some stuff', t => {
process.emit('timeEnd', 'foo')
process.emit('timeEnd', 'baz')
t.match(logs, [
- [ 'timing', 'foo', /Completed in [0-9]+ms/ ],
- [ 'timing', 'bar', /Completed in [0-9]+ms/ ],
- [ 'timing', 'foo', /Completed in [0-9]+ms/ ],
+ ['timing', 'foo', /Completed in [0-9]+ms/],
+ ['timing', 'bar', /Completed in [0-9]+ms/],
+ ['timing', 'foo', /Completed in [0-9]+ms/],
[
'silly',
'timing',
"Tried to end timer that doesn't exist:",
- 'baz'
- ]
+ 'baz',
+ ],
])
t.match(timings, { foo: Number, bar: Number })
t.equal(timings.foo > timings.bar, true, 'foo should be > bar')
diff --git a/test/lib/utils/ping.js b/test/lib/utils/ping.js
index d2b269556..6e0451538 100644
--- a/test/lib/utils/ping.js
+++ b/test/lib/utils/ping.js
@@ -11,7 +11,7 @@ test('pings', async (t) => {
t.equal(url, '/-/ping?write=true', 'calls the correct url')
t.equal(opts, options, 'passes through options')
return { json: () => Promise.resolve(response) }
- }
+ },
})
const res = await ping(options)
@@ -28,7 +28,7 @@ test('catches errors and returns empty json', async (t) => {
t.equal(url, '/-/ping?write=true', 'calls the correct url')
t.equal(opts, options, 'passes through options')
return { json: () => Promise.reject(response) }
- }
+ },
})
const res = await ping(options)
diff --git a/test/lib/utils/proc-log-listener.js b/test/lib/utils/proc-log-listener.js
index 0a6119d1a..2c1009503 100644
--- a/test/lib/utils/proc-log-listener.js
+++ b/test/lib/utils/proc-log-listener.js
@@ -5,11 +5,11 @@ const { inspect } = require('util')
const logs = []
const npmlog = {
warn: (...args) => logs.push(['warn', ...args]),
- verbose: (...args) => logs.push(['verbose', ...args])
+ verbose: (...args) => logs.push(['verbose', ...args]),
}
requireInject('../../../lib/utils/proc-log-listener.js', {
- npmlog
+ npmlog,
})()
process.emit('log', 'warn', 'hello', 'i am a warning')
@@ -17,22 +17,26 @@ t.strictSame(logs, [['warn', 'hello', 'i am a warning']])
logs.length = 0
const nopeError = new Error('nope')
-npmlog.warn = () => { throw nopeError }
+npmlog.warn = () => {
+ throw nopeError
+}
process.emit('log', 'warn', 'fail')
t.strictSame(logs, [[
'verbose',
`attempt to log ${inspect(['warn', 'fail'])} crashed`,
- nopeError
+ nopeError,
]])
logs.length = 0
-npmlog.verbose = () => { throw nopeError }
+npmlog.verbose = () => {
+ throw nopeError
+}
const consoleErrors = []
console.error = (...args) => consoleErrors.push(args)
process.emit('log', 'warn', 'fail2')
t.strictSame(logs, [])
t.strictSame(consoleErrors, [[
`attempt to log ${inspect(['warn', 'fail2'])} crashed`,
- nopeError
+ nopeError,
]])
diff --git a/test/lib/utils/read-local-package.js b/test/lib/utils/read-local-package.js
index 8854cf4e5..33a408eb5 100644
--- a/test/lib/utils/read-local-package.js
+++ b/test/lib/utils/read-local-package.js
@@ -5,21 +5,23 @@ let prefix
const _flatOptions = {
json: false,
global: false,
- get prefix () { return prefix }
+ get prefix () {
+ return prefix
+ },
}
const readLocalPackageName = requireInject('../../../lib/utils/read-local-package.js', {
'../../../lib/npm.js': {
- flatOptions: _flatOptions
- }
+ flatOptions: _flatOptions,
+ },
})
test('read local package.json', async (t) => {
prefix = t.testdir({
'package.json': JSON.stringify({
name: 'my-local-package',
- version: '1.0.0'
- })
+ version: '1.0.0',
+ }),
})
const packageName = await readLocalPackageName()
t.equal(
@@ -33,8 +35,8 @@ test('read local scoped-package.json', async (t) => {
prefix = t.testdir({
'package.json': JSON.stringify({
name: '@my-scope/my-local-package',
- version: '1.0.0'
- })
+ version: '1.0.0',
+ }),
})
const packageName = await readLocalPackageName()
t.equal(
diff --git a/test/lib/utils/reify-output.js b/test/lib/utils/reify-output.js
index 55f77f1d9..b905c9ab0 100644
--- a/test/lib/utils/reify-output.js
+++ b/test/lib/utils/reify-output.js
@@ -9,18 +9,18 @@ log.level = 'warn'
t.cleanSnapshot = str => str.replace(/in [0-9]+m?s/g, 'in {TIME}')
const settings = {
- fund: true
+ fund: true,
}
const npmock = {
started: Date.now(),
- flatOptions: settings
+ flatOptions: settings,
}
const getReifyOutput = tester =>
requireInject(
'../../../lib/utils/reify-output.js',
{
'../../../lib/npm.js': npmock,
- '../../../lib/utils/output.js': tester
+ '../../../lib/utils/output.js': tester,
}
)
@@ -36,11 +36,11 @@ t.test('missing info', (t) => {
reifyOutput({
actualTree: {
- children: []
+ children: [],
},
diff: {
- children: []
- }
+ children: [],
+ },
})
})
@@ -56,12 +56,11 @@ t.test('even more missing info', t => {
reifyOutput({
actualTree: {
- children: []
- }
+ children: [],
+ },
})
})
-
t.test('single package', (t) => {
t.plan(1)
const reifyOutput = getReifyOutput(
@@ -81,14 +80,14 @@ t.test('single package', (t) => {
// the command is not 'audit'
auditReport: {
error: {
- message: 'no audit for youuuuu'
- }
+ message: 'no audit for youuuuu',
+ },
},
actualTree: {
name: 'foo',
package: {
name: 'foo',
- version: '1.0.0'
+ version: '1.0.0',
},
edgesOut: new Map([
['bar', {
@@ -97,26 +96,27 @@ t.test('single package', (t) => {
package: {
name: 'bar',
version: '1.0.0',
- funding: { type: 'foo', url: 'http://example.com' }
- }
- }
- }]
- ])
+ funding: { type: 'foo', url: 'http://example.com' },
+ },
+ },
+ }],
+ ]),
},
diff: {
- children: []
- }
+ children: [],
+ },
})
})
t.test('no message when funding config is false', (t) => {
- t.teardown(() => { settings.fund = true })
+ t.teardown(() => {
+ settings.fund = true
+ })
settings.fund = false
const reifyOutput = getReifyOutput(
out => {
- if (out.endsWith('looking for funding')) {
+ if (out.endsWith('looking for funding'))
t.fail('should not print funding info', { actual: out })
- }
}
)
@@ -125,7 +125,7 @@ t.test('no message when funding config is false', (t) => {
name: 'foo',
package: {
name: 'foo',
- version: '1.0.0'
+ version: '1.0.0',
},
edgesOut: new Map([
['bar', {
@@ -134,15 +134,15 @@ t.test('no message when funding config is false', (t) => {
package: {
name: 'bar',
version: '1.0.0',
- funding: { type: 'foo', url: 'http://example.com' }
- }
- }
- }]
- ])
+ funding: { type: 'foo', url: 'http://example.com' },
+ },
+ },
+ }],
+ ]),
},
diff: {
- children: []
- }
+ children: [],
+ },
})
t.end()
@@ -167,7 +167,7 @@ t.test('print appropriate message for many packages', (t) => {
name: 'foo',
package: {
name: 'foo',
- version: '1.0.0'
+ version: '1.0.0',
},
edgesOut: new Map([
['bar', {
@@ -176,9 +176,9 @@ t.test('print appropriate message for many packages', (t) => {
package: {
name: 'bar',
version: '1.0.0',
- funding: { type: 'foo', url: 'http://example.com' }
- }
- }
+ funding: { type: 'foo', url: 'http://example.com' },
+ },
+ },
}],
['lorem', {
to: {
@@ -186,9 +186,9 @@ t.test('print appropriate message for many packages', (t) => {
package: {
name: 'lorem',
version: '1.0.0',
- funding: { type: 'foo', url: 'http://example.com' }
- }
- }
+ funding: { type: 'foo', url: 'http://example.com' },
+ },
+ },
}],
['ipsum', {
to: {
@@ -196,15 +196,15 @@ t.test('print appropriate message for many packages', (t) => {
package: {
name: 'ipsum',
version: '1.0.0',
- funding: { type: 'foo', url: 'http://example.com' }
- }
- }
- }]
- ])
+ funding: { type: 'foo', url: 'http://example.com' },
+ },
+ },
+ }],
+ ]),
},
diff: {
- children: []
- }
+ children: [],
+ },
})
})
@@ -217,19 +217,21 @@ t.test('no output when silent', t => {
reifyOutput({
actualTree: { inventory: { size: 999 }, children: [] },
auditReport: {
- toJSON: () => mock.auditReport,
+ toJSON: () => {
+ throw new Error('this should not get called')
+ },
vulnerabilities: {},
metadata: {
vulnerabilities: {
- total: 99
- }
- }
+ total: 99,
+ },
+ },
},
diff: {
children: [
- { action: 'ADD', ideal: { location: 'loc' } }
- ]
- }
+ { action: 'ADD', ideal: { location: 'loc' } },
+ ],
+ },
})
t.end()
})
@@ -251,22 +253,22 @@ t.test('packages changed message', t => {
vulnerabilities: {},
metadata: {
vulnerabilities: {
- total: 0
- }
- }
+ total: 0,
+ },
+ },
} : null,
diff: {
children: [
- { action: 'some random unexpected junk' }
- ]
- }
+ { action: 'some random unexpected junk' },
+ ],
+ },
}
- for (let i = 0; i < added; i++) {
+ for (let i = 0; i < added; i++)
mock.diff.children.push({ action: 'ADD', ideal: { location: 'loc' } })
- }
- for (let i = 0; i < removed; i++) {
+
+ for (let i = 0; i < removed; i++)
mock.diff.children.push({ action: 'REMOVE', actual: { location: 'loc' } })
- }
+
for (let i = 0; i < changed; i++) {
const actual = { location: 'loc' }
const ideal = { location: 'loc' }
@@ -279,7 +281,7 @@ t.test('packages changed message', t => {
removed,
changed,
audited,
- json
+ json,
}))
}
@@ -288,9 +290,8 @@ t.test('packages changed message', t => {
for (const removed of [0, 1, 2]) {
for (const changed of [0, 1, 2]) {
for (const audited of [0, 1, 2]) {
- for (const json of [true, false]) {
+ for (const json of [true, false])
cases.push([added, removed, changed, audited, json, 'install'])
- }
}
}
}
@@ -301,9 +302,8 @@ t.test('packages changed message', t => {
cases.push([0, 0, 0, 2, false, 'audit'])
t.plan(cases.length)
- for (const [added, removed, changed, audited, json, command] of cases) {
+ for (const [added, removed, changed, audited, json, command] of cases)
testCase(t, added, removed, changed, audited, json, command)
- }
t.end()
})
@@ -319,14 +319,14 @@ t.test('added packages should be looked up within returned tree', t => {
actualTree: {
name: 'foo',
inventory: {
- has: () => true
- }
+ has: () => true,
+ },
},
diff: {
children: [
- { action: 'ADD', ideal: { name: 'baz' } }
- ]
- }
+ { action: 'ADD', ideal: { name: 'baz' } },
+ ],
+ },
})
})
@@ -340,14 +340,14 @@ t.test('added packages should be looked up within returned tree', t => {
actualTree: {
name: 'foo',
inventory: {
- has: () => false
- }
+ has: () => false,
+ },
},
diff: {
children: [
- { action: 'ADD', ideal: { name: 'baz' } }
- ]
- }
+ { action: 'ADD', ideal: { name: 'baz' } },
+ ],
+ },
})
})
t.end()
diff --git a/test/lib/utils/setup-log.js b/test/lib/utils/setup-log.js
index 2d5d794f1..4398200ab 100644
--- a/test/lib/utils/setup-log.js
+++ b/test/lib/utils/setup-log.js
@@ -1,15 +1,18 @@
const t = require('tap')
const requireInject = require('require-inject')
-const settings = {}
+const settings = {
+ level: 'warn',
+}
t.afterEach(cb => {
- Object.keys(settings).forEach(k => { delete settings[k] })
+ Object.keys(settings).forEach(k => {
+ delete settings[k]
+ })
cb()
})
const WARN_CALLED = []
const npmlog = {
- level: 'warn',
warn: (...args) => {
WARN_CALLED.push(args)
},
@@ -22,17 +25,39 @@ const npmlog = {
notice: 3500,
warn: 4000,
error: 5000,
- silent: Infinity
+ silent: Infinity,
},
settings,
- enableColor: () => { settings.color = true },
- disableColor: () => { settings.color = false },
- enableUnicode: () => { settings.unicode = true },
- disableUnicode: () => { settings.unicode = false },
- enableProgress: () => { settings.progress = true },
- disableProgress: () => { settings.progress = false },
- set heading (h) { settings.heading = h },
- set level (l) { settings.level = l }
+ enableColor: () => {
+ settings.color = true
+ },
+ disableColor: () => {
+ settings.color = false
+ },
+ enableUnicode: () => {
+ settings.unicode = true
+ },
+ disableUnicode: () => {
+ settings.unicode = false
+ },
+ enableProgress: () => {
+ settings.progress = true
+ },
+ disableProgress: () => {
+ settings.progress = false
+ },
+ get heading () {
+ return settings.heading
+ },
+ set heading (h) {
+ settings.heading = h
+ },
+ get level () {
+ return settings.level
+ },
+ set level (l) {
+ settings.level = l
+ },
}
const EXPLAIN_CALLED = []
@@ -41,9 +66,9 @@ const setupLog = requireInject('../../../lib/utils/setup-log.js', {
explain: (...args) => {
EXPLAIN_CALLED.push(args)
return 'explanation'
- }
+ },
},
- npmlog
+ npmlog,
})
const config = obj => ({
@@ -52,7 +77,7 @@ const config = obj => ({
},
set (k, v) {
obj[k] = v
- }
+ },
})
t.test('setup with color=always and unicode', t => {
@@ -65,7 +90,7 @@ t.test('setup with color=always and unicode', t => {
loglevel: 'warn',
color: 'always',
unicode: true,
- progress: false
+ progress: false,
})), true)
npmlog.warn('ERESOLVE', 'hello', { some: { other: 'object' } })
@@ -73,7 +98,7 @@ t.test('setup with color=always and unicode', t => {
'log.warn(ERESOLVE) patched to call explainEresolve()')
t.strictSame(WARN_CALLED, [
['ERESOLVE', 'hello'],
- ['', 'explanation']
+ ['', 'explanation'],
], 'warn the explanation')
EXPLAIN_CALLED.length = 0
WARN_CALLED.length = 0
@@ -86,7 +111,7 @@ t.test('setup with color=always and unicode', t => {
color: true,
unicode: true,
progress: false,
- heading: 'npm'
+ heading: 'npm',
})
t.end()
@@ -106,7 +131,7 @@ t.test('setup with color=true, no unicode, and non-TTY terminal', t => {
loglevel: 'warn',
color: false,
progress: false,
- heading: 'asdf'
+ heading: 'asdf',
})), false)
t.strictSame(settings, {
@@ -114,7 +139,7 @@ t.test('setup with color=true, no unicode, and non-TTY terminal', t => {
color: false,
unicode: false,
progress: false,
- heading: 'asdf'
+ heading: 'asdf',
})
t.end()
@@ -137,7 +162,7 @@ t.test('setup with color=true, no unicode, and dumb TTY terminal', t => {
loglevel: 'warn',
color: true,
progress: false,
- heading: 'asdf'
+ heading: 'asdf',
})), true)
t.strictSame(settings, {
@@ -145,7 +170,7 @@ t.test('setup with color=true, no unicode, and dumb TTY terminal', t => {
color: true,
unicode: false,
progress: false,
- heading: 'asdf'
+ heading: 'asdf',
})
t.end()
@@ -168,7 +193,7 @@ t.test('setup with color=true, no unicode, and non-dumb TTY terminal', t => {
loglevel: 'warn',
color: true,
progress: true,
- heading: 'asdf'
+ heading: 'asdf',
})), true)
t.strictSame(settings, {
@@ -176,7 +201,7 @@ t.test('setup with color=true, no unicode, and non-dumb TTY terminal', t => {
color: true,
unicode: false,
progress: true,
- heading: 'asdf'
+ heading: 'asdf',
})
t.end()
@@ -199,7 +224,7 @@ t.test('setup with non-TTY stdout, TTY stderr', t => {
loglevel: 'warn',
color: true,
progress: true,
- heading: 'asdf'
+ heading: 'asdf',
})), false)
t.strictSame(settings, {
@@ -207,7 +232,7 @@ t.test('setup with non-TTY stdout, TTY stderr', t => {
color: true,
unicode: false,
progress: true,
- heading: 'asdf'
+ heading: 'asdf',
})
t.end()
@@ -229,7 +254,7 @@ t.test('setup with TTY stdout, non-TTY stderr', t => {
loglevel: 'warn',
color: true,
progress: true,
- heading: 'asdf'
+ heading: 'asdf',
})), true)
t.strictSame(settings, {
@@ -237,7 +262,7 @@ t.test('setup with TTY stdout, non-TTY stderr', t => {
color: false,
unicode: false,
progress: false,
- heading: 'asdf'
+ heading: 'asdf',
})
t.end()
@@ -246,7 +271,7 @@ t.test('setup with TTY stdout, non-TTY stderr', t => {
t.test('set loglevel to timing', t => {
setupLog(config({
timing: true,
- loglevel: 'notice'
+ loglevel: 'notice',
}))
t.equal(settings.level, 'timing')
t.end()
@@ -266,7 +291,7 @@ t.test('silent has no logging', t => {
process.env.TERM = 'totes not dum'
setupLog(config({
- loglevel: 'silent'
+ loglevel: 'silent',
}))
t.equal(settings.progress, false, 'progress disabled when silent')
t.end()
diff --git a/test/lib/utils/tar.js b/test/lib/utils/tar.js
index 827bc9262..b780a73e5 100644
--- a/test/lib/utils/tar.js
+++ b/test/lib/utils/tar.js
@@ -11,9 +11,9 @@ const printLogs = (tarball, unicode) => {
log: {
notice: (...args) => {
args.map(el => logs.push(el))
- }
+ },
},
- unicode
+ unicode,
})
return logs.join('\n')
}
@@ -24,19 +24,19 @@ test('should log tarball contents', async (t) => {
name: 'my-cool-pkg',
version: '1.0.0',
bundleDependencies: [
- 'bundle-dep'
- ]
+ 'bundle-dep',
+ ],
}, null, 2),
- 'node_modules': {
- 'bundle-dep': 'toto'
- }
+ node_modules: {
+ 'bundle-dep': 'toto',
+ },
})
const tarball = await pack(testDir)
const tarballContents = await getContents({
_id: '1',
name: 'my-cool-pkg',
- version: '1.0.0'
+ version: '1.0.0',
}, tarball)
t.matchSnapshot(printLogs(tarballContents, false))
@@ -44,36 +44,36 @@ test('should log tarball contents', async (t) => {
test('should log tarball contents with unicode', async (t) => {
const { logTar } = requireInject('../../../lib/utils/tar.js', {
- 'npmlog': {
- 'notice': (str) => {
+ npmlog: {
+ notice: (str) => {
t.ok(true, 'defaults to npmlog')
return str
- }
- }
+ },
+ },
})
-
- logTar({
- files: [],
+
+ logTar({
+ files: [],
bundled: [],
- integrity: ''
+ integrity: '',
}, { unicode: true })
t.end()
})
test('should default to npmlog', async (t) => {
const { logTar } = requireInject('../../../lib/utils/tar.js', {
- 'npmlog': {
- 'notice': (str) => {
+ npmlog: {
+ notice: (str) => {
t.ok(true, 'defaults to npmlog')
return str
- }
- }
+ },
+ },
})
logTar({
files: [],
bundled: [],
- integrity: ''
+ integrity: '',
})
t.end()
})
@@ -82,19 +82,19 @@ test('should getContents of a tarball', async (t) => {
const testDir = t.testdir({
'package.json': JSON.stringify({
name: 'my-cool-pkg',
- version: '1.0.0'
- }, null, 2)
+ version: '1.0.0',
+ }, null, 2),
})
const tarball = await pack(testDir)
const tarballContents = await getContents({
name: 'my-cool-pkg',
- version: '1.0.0'
+ version: '1.0.0',
}, tarball)
const integrity = await ssri.fromData(tarball, {
- algorithms: ['sha1', 'sha512']
+ algorithms: ['sha1', 'sha512'],
})
t.strictSame(tarballContents, {
@@ -106,10 +106,9 @@ test('should getContents of a tarball', async (t) => {
shasum: 'c0bfd67a5142104e429afda09119eedd6a30d2fc',
integrity: ssri.parse(integrity.sha512[0]),
filename: 'my-cool-pkg-1.0.0.tgz',
- files: [ { path: 'package.json', size: 49, mode: 420 } ],
+ files: [{ path: 'package.json', size: 49, mode: 420 }],
entryCount: 1,
- bundled: []
+ bundled: [],
}, 'contents are correct')
t.end()
-
})
diff --git a/test/lib/utils/unsupported.js b/test/lib/utils/unsupported.js
index 89ee6af23..f14cba9b7 100644
--- a/test/lib/utils/unsupported.js
+++ b/test/lib/utils/unsupported.js
@@ -30,7 +30,7 @@ const versions = [
['v10.0.0-0', false, false],
['v11.0.0-0', false, false],
['v12.0.0-0', false, false],
- ['v13.0.0-0', false, false]
+ ['v13.0.0-0', false, false],
]
test('versions', function (t) {
@@ -71,7 +71,7 @@ test('checkForBrokenNode', t => {
const expectLogs = [
'ERROR: npm is known not to run on Node.js 1.2.3',
"You'll need to upgrade to a newer Node.js version in order to use this",
- 'version of npm. You can find the latest version at https://nodejs.org/'
+ 'version of npm. You can find the latest version at https://nodejs.org/',
]
console.error = msg => logs.push(msg)
unsupported.checkForBrokenNode()
@@ -92,7 +92,7 @@ test('checkForUnsupportedNode', t => {
'npm does not support Node.js 8.0.0',
'You should probably upgrade to a newer version of node as we',
"can't make any promises that npm will work with this version.",
- 'You can find the latest version at https://nodejs.org/'
+ 'You can find the latest version at https://nodejs.org/',
]
npmlog.warn = (section, msg) => logs.push(msg)
diff --git a/test/lib/utils/update-notifier.js b/test/lib/utils/update-notifier.js
index 903e888a5..99c9dfc26 100644
--- a/test/lib/utils/update-notifier.js
+++ b/test/lib/utils/update-notifier.js
@@ -22,15 +22,15 @@ const pacote = {
process.exit(1)
}
MANIFEST_REQUEST.push(spec)
- if (PACOTE_ERROR) {
+ if (PACOTE_ERROR)
throw PACOTE_ERROR
- }
+
return {
version: spec === 'npm@latest' ? CURRENT_VERSION
- : /-/.test(spec) ? CURRENT_BETA
- : NEXT_VERSION
+ : /-/.test(spec) ? CURRENT_BETA
+ : NEXT_VERSION,
}
- }
+ },
}
const npm = {
@@ -38,13 +38,12 @@ const npm = {
log: { useColor: () => true },
version: CURRENT_VERSION,
config: { get: (k) => k !== 'global' },
- flatOptions,
command: 'view',
- argv: ['npm']
+ argv: ['npm'],
}
const npmNoColor = {
...npm,
- log: { useColor: () => false }
+ log: { useColor: () => false },
}
const { basename } = require('path')
@@ -70,17 +69,15 @@ const fs = {
process.exit(1)
}
process.nextTick(() => cb(WRITE_ERROR))
- }
+ },
}
const updateNotifier = requireInject('../../../lib/utils/update-notifier.js', {
'@npmcli/ci-detect': () => ciMock,
pacote,
- fs
+ fs,
})
-const semver = require('semver')
-
t.afterEach(cb => {
MANIFEST_REQUEST.length = 0
STAT_ERROR = null
@@ -94,7 +91,7 @@ t.test('situations in which we do not notify', t => {
t.test('nothing to do if notifier disabled', async t => {
t.equal(await updateNotifier({
...npm,
- config: { get: (k) => k === 'update-notifier' ? false : true }
+ config: { get: (k) => k !== 'update-notifier' },
}), null)
t.strictSame(MANIFEST_REQUEST, [], 'no requests for manifests')
})
@@ -104,7 +101,7 @@ t.test('situations in which we do not notify', t => {
...npm,
flatOptions: { ...flatOptions, global: true },
command: 'install',
- argv: ['npm']
+ argv: ['npm'],
}), null)
t.strictSame(MANIFEST_REQUEST, [], 'no requests for manifests')
})
@@ -140,7 +137,9 @@ t.test('situations in which we do not notify', t => {
})
t.test('do not update in CI', async t => {
- t.teardown(() => { ciMock = null })
+ t.teardown(() => {
+ ciMock = null
+ })
ciMock = 'something'
t.equal(await updateNotifier(npm), null)
t.strictSame(MANIFEST_REQUEST, [], 'no requests for manifests')
@@ -148,14 +147,14 @@ t.test('situations in which we do not notify', t => {
t.test('only check weekly for GA releases', async t => {
// the 10 is fuzz factor for test environment
- STAT_MTIME = Date.now() - (1000*60*60*24*7) + 10
+ STAT_MTIME = Date.now() - (1000 * 60 * 60 * 24 * 7) + 10
t.equal(await updateNotifier(npm), null)
t.strictSame(MANIFEST_REQUEST, [], 'no requests for manifests')
})
t.test('only check daily for betas', async t => {
// the 10 is fuzz factor for test environment
- STAT_MTIME = Date.now() - (1000*60*60*24) + 10
+ STAT_MTIME = Date.now() - (1000 * 60 * 60 * 24) + 10
t.equal(await updateNotifier({ ...npm, version: HAVE_BETA }), null)
t.strictSame(MANIFEST_REQUEST, [], 'no requests for manifests')
})