This repository was archived by the owner on May 13, 2019. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathpatches.diff
131 lines (123 loc) · 3.6 KB
/
patches.diff
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
diff --git a/.gitignore b/.gitignore
index c7361af80c79..e56b7f913845 100644
--- a/.gitignore
+++ b/.gitignore
@@ -21,6 +21,8 @@ node_g
icu_config.gypi
/out
+/coverage
+/lib_
# various stuff that VC++ produces/uses
Debug/
diff --git a/lib/internal/bootstrap_node.js b/lib/internal/bootstrap_node.js
index 27f05a4fcf14..ae0fed9e1c00 100644
--- a/lib/internal/bootstrap_node.js
+++ b/lib/internal/bootstrap_node.js
@@ -42,6 +42,7 @@
NativeModule.require('internal/process/stdio').setup();
_process.setupKillAndExit();
_process.setupSignalHandlers();
+ NativeModule.require('internal/process/write-coverage').setup();
// Do not initialize channel in debugger agent, it deletes env variable
// and the main thread won't see it.
diff --git a/lib/internal/process/write-coverage.js b/lib/internal/process/write-coverage.js
new file mode 100644
index 000000000000..666939bc3389
--- /dev/null
+++ b/lib/internal/process/write-coverage.js
@@ -0,0 +1,46 @@
+'use strict';
+const process = require('process');
+const path = require('path');
+const fs = require('fs');
+const mkdirSync = fs.mkdirSync;
+const writeFileSync = fs.writeFileSync;
+
+var isWritingCoverage = false;
+function writeCoverage() {
+ if (isWritingCoverage || !global.__coverage__) {
+ return;
+ }
+ isWritingCoverage = true;
+
+ 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);
+ }
+}
+
+function setup() {
+ var reallyReallyExit = process.reallyExit;
+
+ process.reallyExit = function(code) {
+ writeCoverage();
+ reallyReallyExit(code);
+ };
+
+ process.on('exit', writeCoverage);
+}
+
+exports.setup = setup;
diff --git a/node.gyp b/node.gyp
index 2254a6e..2e91bd9 100644
--- a/node.gyp
+++ b/node.gyp
@@ -86,6 +86,7 @@
'lib/internal/process/promises.js',
'lib/internal/process/stdio.js',
'lib/internal/process/warning.js',
+ 'lib/internal/process/write-coverage.js',
'lib/internal/process.js',
'lib/internal/readline.js',
'lib/internal/repl.js',
diff --git a/test/common.js b/test/common.js
index 5aefdc3bcee5..750c134d33ab 100644
--- a/test/common.js
+++ b/test/common.js
@@ -258,6 +258,9 @@ exports.platformTimeout = function(ms) {
if (process.config.target_defaults.default_configuration === 'Debug')
ms = 2 * ms;
+ if (global.__coverage__)
+ ms = 4 * ms;
+
if (exports.isAix)
return 2 * ms; // default localhost speed is slower on AIX
@@ -348,7 +351,7 @@ function leakedGlobals() {
if (-1 === knownGlobals.indexOf(global[val]))
leaked.push(val);
- return leaked;
+ return leaked.filter((varname) => !/^__cov/.test(varname));
}
exports.leakedGlobals = leakedGlobals;
diff --git a/test/parallel/test-fs-sync-fd-leak.js b/test/parallel/test-fs-sync-fd-leak.js
index f7cfd25f4b9b..80ad8cf6b705 100644
--- a/test/parallel/test-fs-sync-fd-leak.js
+++ b/test/parallel/test-fs-sync-fd-leak.js
@@ -1,8 +1,13 @@
'use strict';
-require('../common');
+const common = require('../common');
var assert = require('assert');
var fs = require('fs');
+if (global.__coverage__) {
+ common.skip('Not working with coverage');
+ return;
+}
+
// ensure that (read|write|append)FileSync() closes the file descriptor
fs.openSync = function() {
return 42;