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/audit.js
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/audit.js')
-rw-r--r--test/lib/audit.js47
1 files changed, 25 insertions, 22 deletions
diff --git a/test/lib/audit.js b/test/lib/audit.js
index 723675c32..cc7379394 100644
--- a/test/lib/audit.js
+++ b/test/lib/audit.js
@@ -14,14 +14,14 @@ t.test('should audit using Arborist', t => {
'../../lib/npm.js': {
prefix: 'foo',
flatOptions: {
- json: false
+ json: false,
},
},
'npm-audit-report': () => {
AUDIT_REPORT_CALLED = true
return {
report: 'there are vulnerabilities',
- exitCode: 0
+ exitCode: 0,
}
},
'@npmcli/arborist': function (args) {
@@ -33,14 +33,14 @@ t.test('should audit using Arborist', t => {
}
},
'../../lib/utils/reify-finish.js': arb => {
- if (arb !== ARB_OBJ) {
+ if (arb !== ARB_OBJ)
throw new Error('got wrong object passed to reify-output')
- }
+
REIFY_FINISH_CALLED = true
},
'../../lib/utils/output.js': () => {
OUTPUT_CALLED = true
- }
+ },
})
t.test('audit', t => {
@@ -68,12 +68,12 @@ t.test('should audit - json', t => {
'../../lib/npm.js': {
prefix: 'foo',
flatOptions: {
- json: true
+ json: true,
},
},
'npm-audit-report': () => ({
report: 'there are vulnerabilities',
- exitCode: 0
+ exitCode: 0,
}),
'@npmcli/arborist': function () {
this.audit = () => {
@@ -81,7 +81,7 @@ t.test('should audit - json', t => {
}
},
'../../lib/utils/reify-output.js': () => {},
- '../../lib/utils/output.js': () => {}
+ '../../lib/utils/output.js': () => {},
})
audit([], (err) => {
@@ -100,11 +100,11 @@ t.test('report endpoint error', t => {
prefix: 'foo',
command: 'audit',
flatOptions: {
- json
+ json,
},
log: {
- warn: (...warning) => LOGS.push(warning)
- }
+ warn: (...warning) => LOGS.push(warning),
+ },
},
'npm-audit-report': () => {
throw new Error('should not call audit report when there are errors')
@@ -117,25 +117,25 @@ t.test('report endpoint error', t => {
method: 'POST',
uri: 'https://example.com/',
headers: {
- head: ['ers']
+ head: ['ers'],
},
statusCode: 420,
body: json ? { nope: 'lol' }
- : Buffer.from('i had a vuln but i eated it lol')
- }
+ : Buffer.from('i had a vuln but i eated it lol'),
+ },
}
}
},
'../../lib/utils/reify-output.js': () => {},
'../../lib/utils/output.js': (...msg) => {
OUTPUT.push(msg)
- }
+ },
}
// have to pass mocks to both to get the npm and output set right
const auditError = requireInject('../../lib/utils/audit-error.js', mocks)
const audit = requireInject('../../lib/audit.js', {
...mocks,
- '../../lib/utils/audit-error.js': auditError
+ '../../lib/utils/audit-error.js': auditError,
})
audit([], (err) => {
@@ -156,8 +156,8 @@ t.test('report endpoint error', t => {
' "nope": "lol"\n' +
' }\n' +
'}'
- : 'i had a vuln but i eated it lol'
- ]
+ : 'i had a vuln but i eated it lol',
+ ],
])
t.strictSame(LOGS, [['audit', 'hello, this didnt work']])
t.end()
@@ -170,8 +170,10 @@ t.test('report endpoint error', t => {
t.test('completion', t => {
t.test('fix', t => {
audit.completion({
- conf: { argv: { remain: ['npm', 'audit'] } }
+ conf: { argv: { remain: ['npm', 'audit'] } },
}, (err, res) => {
+ if (err)
+ throw err
const subcmd = res.pop()
t.equals('fix', subcmd, 'completes to fix')
t.end()
@@ -180,16 +182,17 @@ t.test('completion', t => {
t.test('subcommand fix', t => {
audit.completion({
- conf: { argv: { remain: ['npm', 'audit', 'fix'] } }
+ conf: { argv: { remain: ['npm', 'audit', 'fix'] } },
}, (err) => {
- t.notOk(err, 'no errors')
+ if (err)
+ throw err
t.end()
})
})
t.test('subcommand not recognized', t => {
audit.completion({
- conf: { argv: { remain: ['npm', 'audit', 'repare'] } }
+ conf: { argv: { remain: ['npm', 'audit', 'repare'] } },
}, (err) => {
t.ok(err, 'not recognized')
t.end()