UNPKG

758 BJavaScriptView Raw
1'use strict'
2
3const { test } = require('tap')
4const rimraf = require('rimraf')
5const ClinicDoctor = require('../index.js')
6
7test('cmd - test collect - emits "analysing" event', function (t) {
8 const tool = new ClinicDoctor()
9
10 function cleanup (err, dirname) {
11 t.ifError(err)
12 t.match(dirname, /^[0-9]+\.clinic-doctor/)
13 rimraf(dirname, (err) => {
14 t.ifError(err)
15 t.end()
16 })
17 }
18
19 let seenAnalysing = false
20 tool.on('analysing', () => {
21 seenAnalysing = true
22 })
23
24 tool.collect(
25 [process.execPath, '-e', 'setTimeout(() => {}, 123)'],
26 function (err, dirname) {
27 if (err) return cleanup(err, dirname)
28
29 t.ok(seenAnalysing) // should've happened before this callback
30 cleanup(null, dirname)
31 }
32 )
33})