Debian Codegraph @

nyc/test/report.js

raw
1 'use strict'
2
3 const fs = require('fs')
4 const path = require('path')
5 const { promisify } = require('util')
6
7 const t = require('tap')
8 const isWindows = require('is-windows')()
9 const rimraf = promisify(require('rimraf'))
10
11 const NYC = require('../self-coverage')
12
13 const { parseArgv, runNYC, resetState } = require('./helpers')
14
15 const fixtures = path.resolve(__dirname, 'fixtures')
16
17 t.beforeEach(resetState)
18
19 async function testSignal (t, signal) {
20 if (isWindows) {
21 t.end()
22
23 return
24 }
25
26 const nyc = new NYC(await parseArgv(fixtures))
27 await runNYC({
28 args: [`./${signal}.js`],
29 cwd: fixtures
30 })
31
32 const checkFile = path.join(fixtures, `${signal}.js`)
33 const reports = (await nyc.coverageData()).filter(report => report[checkFile])
34
35 t.strictEqual(reports.length, 1)
36 }
37
38 t.test('writes coverage report when process is killed with SIGTERM', t => testSignal(t, 'sigterm'))
39
40 t.test('writes coverage report when process is killed with SIGINT', t => testSignal(t, 'sigint'))
41
42 t.test('allows coverage report to be output in an alternative directory', async t => {
43 const nyc = new NYC(await parseArgv(undefined, [
44 '--report-dir=./alternative-report',
45 '--reporter=lcov'
46 ]))
47 await nyc.reset()
48
49 await nyc.report()
50 t.strictEqual(fs.existsSync('./alternative-report/lcov.info'), true)
51 await rimraf('./alternative-report')
52 })