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

pulse-till-done.js « utils « lib « test - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9f7a94614d3bb56cb416386c92bdf75095b3f3c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const t = require('tap')

let pulseStarted = null

const pulseTillDone = t.mock('../../../lib/utils/pulse-till-done.js', {
  npmlog: {
    gauge: {
      pulse: () => {
        if (pulseStarted) {
          pulseStarted()
        }
      },
    },
  },
})

t.test('pulses (with promise)', async (t) => {
  t.teardown(() => {
    pulseStarted = null
  })

  let resolver
  const promise = new Promise(resolve => {
    resolver = resolve
  })

  const result = pulseTillDone.withPromise(promise)
  // wait until the gauge has fired at least once
  await new Promise(resolve => {
    pulseStarted = resolve
  })
  resolver('value')
  t.resolveMatch(result, 'value', 'returned the resolved promise')
})