aboutsummaryrefslogtreecommitdiff
path: root/lib/internal/coverage-gen/with_instrumentation.js
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2018-12-29 18:44:11 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2019-01-16 13:49:36 +0800
commitb367ab2a6624b41bd59b751c61cf64ad91a9e2d6 (patch)
tree60e2e85a2f60bb773a642d6c948855072ff3e3d6 /lib/internal/coverage-gen/with_instrumentation.js
parent2b401e33de81428dc5f6dfc60343e65ee5167886 (diff)
downloadandroid-node-v8-b367ab2a6624b41bd59b751c61cf64ad91a9e2d6.tar.gz
android-node-v8-b367ab2a6624b41bd59b751c61cf64ad91a9e2d6.tar.bz2
android-node-v8-b367ab2a6624b41bd59b751c61cf64ad91a9e2d6.zip
process: refactor coverage setup during bootstrap
- Renamed `internal/process/write-coverage.js` to `internal/coverage-gen/with_instrumentation.js`, `internal/process/coverage.js` to `internal/coverage-gen/with_profiler.js` to distinguish the two better and added comments. - Separate the coverage directory setup and the connection setup, moves the directory setup into `node.js` and closer to the exit hooks because that's where it's used. - Moves the `process.reallyExit` overwrite and `process.on('exit')` hooks setup into bootstrap/node.js for clarity, and move them to a later stage of bootstrap since they do not have to happen that early. PR-URL: https://github.com/nodejs/node/pull/25398 Reviewed-By: Ben Coe <bencoe@gmail.com>
Diffstat (limited to 'lib/internal/coverage-gen/with_instrumentation.js')
-rw-r--r--lib/internal/coverage-gen/with_instrumentation.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/internal/coverage-gen/with_instrumentation.js b/lib/internal/coverage-gen/with_instrumentation.js
new file mode 100644
index 0000000000..711a3c3f12
--- /dev/null
+++ b/lib/internal/coverage-gen/with_instrumentation.js
@@ -0,0 +1,36 @@
+'use strict';
+
+// This file contains hooks for nyc instrumented lib/ files to collect
+// JS coverage for core.
+// See `make coverage-build`.
+function writeCoverage() {
+ if (!global.__coverage__) {
+ return;
+ }
+
+ const path = require('path');
+ const { mkdirSync, writeFileSync } = require('fs');
+
+ const dirname = path.join(path.dirname(process.execPath), '.coverage');
+ const filename = `coverage-${process.pid}-${Date.now()}.json`;
+ try {
+ mkdirSync(dirname);
+ } catch (err) {
+ if (err.code !== 'EEXIST') {
+ console.error(err);
+ return;
+ }
+ }
+
+ const target = path.join(dirname, filename);
+ const coverageInfo = JSON.stringify(global.__coverage__);
+ try {
+ writeFileSync(target, coverageInfo);
+ } catch (err) {
+ console.error(err);
+ }
+}
+
+module.exports = {
+ writeCoverage
+};