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>2021-01-29 20:40:03 +0300
committerisaacs <i@izs.me>2021-02-01 23:00:32 +0300
commita8e77f2b163e64328b12f4a824292cfac097ecea (patch)
treeb54b389d4fc54cddd9c6ec7e0305ca0759bcb3d4 /test/lib/ci.js
parent0ea134e4190f322138299c51672eab5387ec41bb (diff)
wrap a timer around the rimraf call in npm-ciisaacs/ci-rm-timer
Fix: https://github.com/npm/arborist/issues/207 PR-URL: https://github.com/npm/cli/pull/2573 Credit: @isaacs Close: #2573 Reviewed-by: @nlf
Diffstat (limited to 'test/lib/ci.js')
-rw-r--r--test/lib/ci.js52
1 files changed, 45 insertions, 7 deletions
diff --git a/test/lib/ci.js b/test/lib/ci.js
index b1fba2ab1..28c66b056 100644
--- a/test/lib/ci.js
+++ b/test/lib/ci.js
@@ -51,9 +51,45 @@ test('should use Arborist and run-script', (t) => {
'prepare',
'postprepare',
]
+
+ // set to true when timer starts, false when it ends
+ // when the test is done, we assert that all timers ended
+ const timers = {}
+ const onTime = msg => {
+ if (timers[msg])
+ throw new Error(`saw duplicate timer: ${msg}`)
+ timers[msg] = true
+ }
+ const onTimeEnd = msg => {
+ if (!timers[msg])
+ throw new Error(`ended timer that was not started: ${msg}`)
+ timers[msg] = false
+ }
+ process.on('time', onTime)
+ process.on('timeEnd', onTimeEnd)
+ t.teardown(() => {
+ process.removeListener('time', onTime)
+ process.removeListener('timeEnd', onTimeEnd)
+ })
+
+ const path = t.testdir({
+ node_modules: {
+ foo: {
+ 'package.json': JSON.stringify({
+ name: 'foo',
+ version: '1.2.3',
+ }),
+ },
+ '.dotdir': {},
+ '.dotfile': 'a file with a dot',
+ },
+ })
+ const expectRimrafs = 3
+ let actualRimrafs = 0
+
const ci = requireInject('../../lib/ci.js', {
'../../lib/npm.js': {
- prefix: 'foo',
+ prefix: path,
flatOptions: {
global: false,
},
@@ -72,13 +108,11 @@ test('should use Arborist and run-script', (t) => {
t.ok(true, 'reify is called')
}
},
- util: {
- inherits: () => {},
- promisify: (fn) => fn,
- },
- rimraf: (path) => {
+ rimraf: (path, ...args) => {
+ actualRimrafs++
t.ok(path, 'rimraf called with path')
- return Promise.resolve(true)
+ // callback is always last arg
+ args.pop()()
},
'../../lib/utils/reify-output.js': function (arb) {
t.ok(arb, 'gets arborist tree')
@@ -87,6 +121,10 @@ test('should use Arborist and run-script', (t) => {
ci(null, er => {
if (er)
throw er
+ for (const [msg, result] of Object.entries(timers))
+ t.notOk(result, `properly resolved ${msg} timer`)
+ t.match(timers, { 'npm-ci:rm': false }, 'saw the rimraf timer')
+ t.equal(actualRimrafs, expectRimrafs, 'removed the right number of things')
t.strictSame(scripts, [], 'called all scripts')
t.end()
})