Debian Codegraph @

istanbul-lib-processinfo/test/process-info.js

raw
1 'use strict'
2 const t = require('tap')
3 const {ProcessInfo} = require('../')
4 const uuidRe = /^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/
5 const NYC = require('nyc')
6 const rimraf = require('rimraf').sync
7 const fs = require('fs')
8 const path = require('path')
9
10 t.test('basic creation', t => {
11 const pi = new ProcessInfo({
12 foo: 'bar',
13 directory: '/some/path',
14 time: 1234,
15 cwd: '/some/cwd',
16 pid: 420,
17 ppid: 69,
18 externalId: 'florp',
19 execArgv: [1,2,3],
20 argv: ['a','b','c'],
21 uuid: 'a universally unique identifier',
22 nodes: [4,2,0],
23 })
24 t.matchSnapshot(pi)
25 t.same(pi.nodes, [4, 2, 0])
26 t.equal(pi.directory, path.resolve('/some/path'))
27 t.equal(pi.label, 'a b c')
28 t.equal(pi.label, 'a b c', 'second time to cover memoization')
29 t.match(new ProcessInfo().uuid, uuidRe)
30 t.end()
31 })
32
33 t.test('saveSync', t => {
34 const file = __dirname + '/fixtures/.nyc_output/processinfo/blerg.json'
35 t.teardown(() => rimraf(file))
36
37 const pi = new ProcessInfo({
38 directory: __dirname + '/fixtures/.nyc_output/processinfo',
39 uuid: 'blerg',
40 })
41
42 pi.saveSync()
43
44 t.match(pi, JSON.parse(fs.readFileSync(file, 'utf8')))
45 t.end()
46 })
47
48 t.test('save', async t => {
49 const file = __dirname + '/fixtures/.nyc_output/processinfo/blerg.json'
50 t.teardown(() => rimraf(file))
51
52 const pi = new ProcessInfo({
53 directory: __dirname + '/fixtures/.nyc_output/processinfo',
54 uuid: 'blerg',
55 })
56
57 await pi.save()
58
59 t.match(pi, JSON.parse(fs.readFileSync(file, 'utf8')))
60 })
61
62 t.test('nyc stuff', async t => {
63 const nyc = new NYC({
64 tempDir: __dirname + '/fixtures/.nyc_output',
65 cwd: path.resolve(__dirname + '/..'),
66 })
67
68 const uuid = '625ef291-93c0-40b2-a869-70587f7e8fac'
69 const cuuid = '62c33964-203a-4e6a-b1ff-8a046eeb8912'
70 const file = `${__dirname}/fixtures/.nyc_output/processinfo/${uuid}.json`
71 const child = `${__dirname}/fixtures/.nyc_output/processinfo/${cuuid}.json`
72 const pi = new ProcessInfo(Object.assign(
73 JSON.parse(fs.readFileSync(file, 'utf8')),
74 {nodes: [
75 new ProcessInfo(JSON.parse(fs.readFileSync(child, 'utf8')))
76 ]}))
77 const cm = await pi.getCoverageMap(nyc)
78 t.matchSnapshot(cm)
79 const cm2 = await pi.getCoverageMap(nyc)
80 t.match(cm2, cm)
81
82 t.matchSnapshot(pi.label)
83 })