Skip to content

Commit

Permalink
add c8 for coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabian Wiles committed Feb 20, 2019
1 parent 0a71195 commit 06c819f
Show file tree
Hide file tree
Showing 5 changed files with 746 additions and 12 deletions.
1 change: 1 addition & 0 deletions packages/jasmine/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package(default_visibility = ["//visibility:public"])

exports_files([
"src/jasmine_runner.js",
"src/jasmine_runner_host.js",
# Exported to be consumed for generating skydoc.
"src/jasmine_node_test.bzl",
])
Expand Down
4 changes: 3 additions & 1 deletion packages/jasmine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"license": "Apache 2.0",
"version": "0.0.0-PLACEHOLDER",
"dependencies": {
"c8": "^3.4.0",
"foreground-child": "^1.5.6",
"jasmine": "~3.3.1"
},
"bazelWorkspaces": {
Expand All @@ -16,4 +18,4 @@
"build": "bazel run :package.pack --workspace_status_command=../../tools/current_version.sh",
"test": "bazel test //..."
}
}
}
3 changes: 2 additions & 1 deletion packages/jasmine/src/jasmine_node_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ def jasmine_node_test(
)

all_data = data + srcs + deps + [jasmine]
all_data += ["@npm//c8", "@npm//foreground-child"]
all_data += [Label("//:src/jasmine_runner.js"), Label("//:src/jasmine_runner_host.js")]
all_data += [":%s_devmode_srcs.MF" % name]
all_data += [Label("@bazel_tools//tools/bash/runfiles")]
entry_point = "npm_bazel_jasmine/src/jasmine_runner.js"
entry_point = "npm_bazel_jasmine/src/jasmine_runner_host.js"

nodejs_test(
name = name,
Expand Down
43 changes: 35 additions & 8 deletions packages/jasmine/src/jasmine_runner_host.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,40 @@
const { spawnSync } = require('child_process');

var crypto = require('crypto');
const { join } = require('path');
const fs = require('fs');
const cild_process = require('child_process');
const foreground = require('foreground-child');
const Report = require('c8/lib/report')

function main(args) {
const output = spawnSync(process.execPath, [
require.resolve('./jasmine_runner.js'),
...args
], { env: { ...process.env, NODE_V8_COVERAGE: '/tmp/cov'}})
assert.strictEqual(output.status, 0);
assert.strictEqual(output.stderr.toString(), '');
// do this here since this require.resolve fails in the child process
const manifestFile = require.resolve(args[0]);
const covDir = join(process.env['TEST_TMPDIR'], `${crypto.randomBytes(4).readUInt32LE(0)}`);

process.env.NODE_V8_COVERAGE = covDir
// foreground(require.resolve('./jasmine_runner.js'), () => {
// outputReport(argv)
// })

const runner = cild_process.fork(require.resolve('./jasmine_runner.js'), [manifestFile]
, { env: { ...process.env, NODE_V8_COVERAGE: covDir, }});
runner.on('close', (code) => {
const covDirFiles = fs.readdirSync(covDir);
if(covDirFiles.length === 1) {
const report = Report({
include: undefined,
exclude: undefined,
reporter: ['text-summary'],
tempDirectory: covDir,
watermarks: undefined,
resolve: process.cwd(),
omitRelative: undefined,
wrapperLength: undefined
})
report.run()
}
console.log(`child process exited with code ${code}`);
process.exit(code);
});
}

if (require.main === module) {
Expand Down
Loading

0 comments on commit 06c819f

Please sign in to comment.