Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
chore: Convert some tap tests to run parallel and use snapshots. (#1075)
- Loading branch information
1 parent
56591fa
commit 600c867
Showing
14 changed files
with
2,314 additions
and
1,966 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
var a = 0 | ||
|
||
throw new Error | ||
process.exit(1) | ||
|
||
if (a === 0) { | ||
a++; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use strict' | ||
|
||
const { fixturesCLI, nycBin } = require('./paths') | ||
|
||
module.exports = { | ||
fixturesCLI, | ||
nycBin, | ||
testSuccess: require('./test-success'), | ||
testFailure: require('./test-failure'), | ||
runNYC: require('./run-nyc'), | ||
tempDirSetup: require('./temp-dir-setup') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use strict' | ||
|
||
const path = require('path') | ||
|
||
module.exports = { | ||
nycBin: require.resolve('../../self-coverage/bin/nyc'), | ||
fixturesCLI: path.resolve(__dirname, '../fixtures/cli') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use strict' | ||
|
||
const { nycBin, fixturesCLI } = require('./paths') | ||
const spawn = require('./spawn') | ||
|
||
const env = { | ||
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 }) { | ||
const runArgs = [nycBin].concat(tempDir ? ['--temp-dir', tempDir] : [], args) | ||
return spawn(process.execPath, runArgs, { | ||
cwd: cwd, | ||
env | ||
}).then(({ status, stderr, stdout }) => ({ | ||
status, | ||
stderr: sanitizeString(stderr, cwd, leavePathSep), | ||
stdout: sanitizeString(stdout, cwd, leavePathSep) | ||
})) | ||
} | ||
|
||
module.exports = runNYC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const cp = require('child_process') | ||
|
||
function spawn (exe, args, opts) { | ||
return new Promise((resolve, reject) => { | ||
const proc = cp.spawn(exe, args, opts) | ||
const stdout = [] | ||
const stderr = [] | ||
|
||
proc.stdout.on('data', buf => stdout.push(buf)) | ||
proc.stderr.on('data', buf => stderr.push(buf)) | ||
|
||
proc.on('error', reject) | ||
proc.on('close', status => { | ||
resolve({ | ||
status, | ||
stdout: Buffer.concat(stdout).toString(), | ||
stderr: Buffer.concat(stderr).toString() | ||
}) | ||
}) | ||
}) | ||
} | ||
|
||
module.exports = spawn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict' | ||
|
||
const path = require('path') | ||
const fs = require('fs') | ||
const makeDir = require('make-dir') | ||
const _rimraf = require('rimraf') | ||
const pify = require('pify') | ||
|
||
const rimraf = pify(_rimraf) | ||
const mkdtemp = pify(fs.mkdtemp) | ||
|
||
function tempDirSetup (t, testFile) { | ||
const { dir, name } = path.parse(testFile) | ||
const tempDirBase = path.resolve(dir, 'temp-dir-' + name) | ||
|
||
makeDir.sync(tempDirBase) | ||
|
||
// Do not use arrow function for beforeEach | ||
// or afterEach, they need this from tap. | ||
t.beforeEach(function () { | ||
return mkdtemp(tempDirBase + '/').then(tempDir => { | ||
this.tempDir = tempDir | ||
}) | ||
}) | ||
|
||
t.afterEach(function () { | ||
return rimraf(this.tempDir) | ||
}) | ||
|
||
t.tearDown(() => rimraf(tempDirBase)) | ||
} | ||
|
||
module.exports = tempDirSetup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict' | ||
|
||
const runNYC = require('./run-nyc') | ||
|
||
function testFailure (t, opts) { | ||
opts.tempDir = t.tempDir | ||
return runNYC(opts).then(({ status, stderr, stdout }) => { | ||
t.equal(status, 1) | ||
t.matchSnapshot(stderr, 'stderr') | ||
t.matchSnapshot(stdout, 'stdout') | ||
}) | ||
} | ||
|
||
module.exports = testFailure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict' | ||
|
||
const runNYC = require('./run-nyc') | ||
|
||
function testSuccess (t, opts) { | ||
opts.tempDir = t.tempDir | ||
return runNYC(opts).then(({ status, stderr, stdout }) => { | ||
t.equal(status, 0) | ||
t.equal(stderr, '') | ||
t.matchSnapshot(stdout, 'stdout') | ||
}) | ||
} | ||
|
||
module.exports = testSuccess |
Oops, something went wrong.