• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1const t = require('tap')
2const tmock = require('../../fixtures/tmock')
3
4let pulseStarted = null
5
6const pulseTillDone = tmock(t, '{LIB}/utils/pulse-till-done.js', {
7  npmlog: {
8    gauge: {
9      pulse: () => {
10        if (pulseStarted) {
11          pulseStarted()
12        }
13      },
14    },
15  },
16})
17
18t.test('pulses (with promise)', async (t) => {
19  t.teardown(() => {
20    pulseStarted = null
21  })
22
23  let resolver
24  const promise = new Promise(resolve => {
25    resolver = resolve
26  })
27
28  const result = pulseTillDone.withPromise(promise)
29  // wait until the gauge has fired at least once
30  await new Promise(resolve => {
31    pulseStarted = resolve
32  })
33  resolver('value')
34  t.resolveMatch(result, 'value', 'returned the resolved promise')
35})
36