-
-
Notifications
You must be signed in to change notification settings - Fork 350
/
run-nyc.js
44 lines (37 loc) · 1.07 KB
/
run-nyc.js
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
35
36
37
38
39
40
41
42
43
44
'use strict'
const { nycBin, fixturesCLI } = require('./paths')
const spawn = require('./spawn')
const envPath = {
PATH: process.env.PATH
}
function sanitizeString (str, cwd, leavePathSep) {
/*
* File paths are different on different systems:
* - make everything relative to cwd
* - replace full node path with 'node'
* - replace all Windows path separators ('\\') with POSIX path separators
*/
str = str
.split(cwd).join('.')
.split(process.execPath).join('node')
if (!leavePathSep) {
str = str.replace(/\\/g, '/')
}
return str
}
function runNYC ({ args, tempDir, leavePathSep, cwd = fixturesCLI, env = {} }) {
const runArgs = [nycBin].concat(tempDir ? ['--temp-dir', tempDir] : [], args)
return spawn(process.execPath, runArgs, {
cwd: cwd,
env: Object.assign({}, envPath, env)
}).then(({ status, stderr, stdout }) => ({
status,
originalText: {
stderr,
stdout
},
stderr: sanitizeString(stderr, cwd, leavePathSep),
stdout: sanitizeString(stdout, cwd, leavePathSep)
}))
}
module.exports = runNYC