forked from Agoric/agoric-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathava+5.3.1.patch
More file actions
205 lines (187 loc) · 7.37 KB
/
ava+5.3.1.patch
File metadata and controls
205 lines (187 loc) · 7.37 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
diff --git a/node_modules/ava/index.js b/node_modules/ava/index.js
new file mode 100644
index 0000000..bee62d8
--- /dev/null
+++ b/node_modules/ava/index.js
@@ -0,0 +1,2 @@
+// XXX work around https://github.com/import-js/eslint-plugin-import/issues/1810
+export {default} from './lib/worker/main.cjs';
diff --git a/node_modules/ava/lib/cli.js b/node_modules/ava/lib/cli.js
index b613666..fbed443 100644
--- a/node_modules/ava/lib/cli.js
+++ b/node_modules/ava/lib/cli.js
@@ -448,6 +448,10 @@ export default async function loadCli() { // eslint-disable-line complexity
workerArgv: argv['--'],
});
+ if (process.env.AGORIC_AVA_USE_TAP){
+ combined.tap = true;
+ }
+
const reporter = combined.tap && !combined.watch && debug === null ? new TapReporter({
extensions: globs.extensions,
projectDir,
diff --git a/node_modules/ava/lib/fork.js b/node_modules/ava/lib/fork.js
index 7630baa..78ced77 100644
--- a/node_modules/ava/lib/fork.js
+++ b/node_modules/ava/lib/fork.js
@@ -7,6 +7,7 @@ import Emittery from 'emittery';
import {pEvent} from 'p-event';
import {controlFlow} from './ipc-flow-control.cjs';
+import {setCappedTimeout} from './now-and-timers.cjs';
import serializeError from './serialize-error.js';
let workerPath = new URL('worker/base.js', import.meta.url);
@@ -91,6 +92,11 @@ export default function loadFork(file, options, execArgv = process.execArgv) {
});
let forcedExit = false;
+ let exitCode = null;
+ const exit = () => {
+ forcedExit = true;
+ close();
+ };
const send = evt => {
if (!finished && !forcedExit) {
postMessage({ava: evt});
@@ -132,6 +138,12 @@ export default function loadFork(file, options, execArgv = process.execArgv) {
break;
}
+ case 'exiting': {
+ exitCode = message.ava.code;
+ setCappedTimeout(() => finished || exit(), 10_000).unref();
+ break;
+ }
+
default: {
emitStateChange(message.ava);
}
@@ -145,9 +157,20 @@ export default function loadFork(file, options, execArgv = process.execArgv) {
worker.on('exit', (code, signal) => {
if (forcedExit) {
- emitStateChange({type: 'worker-finished', forcedExit});
- } else if (code > 0) {
- emitStateChange({type: 'worker-failed', nonZeroExitCode: code});
+ if (exitCode === null) {
+ emitStateChange({type: 'worker-finished', forcedExit});
+ } else if (!exitCode) {
+ if (!process.env.NODE_V8_COVERAGE) {
+ emitStateChange({type: 'worker-failed', err: Error('Test did not cleanup'), signal: 'exit timeout'});
+ } else {
+ emitStateChange({type: 'worker-stderr', chunk: `Test did not cleanup, ignoring because NODE_V8_COVERAGE is set.\n`});
+ emitStateChange({type: 'worker-finished', forcedExit: false});
+ }
+ } else {
+ emitStateChange({type: 'worker-failed', nonZeroExitCode: exitCode});
+ }
+ } else if (code > 0 || exitCode > 0) {
+ emitStateChange({type: 'worker-failed', nonZeroExitCode: code || exitCode});
} else if (code === null && signal) {
emitStateChange({type: 'worker-failed', signal});
} else {
@@ -163,10 +186,7 @@ export default function loadFork(file, options, execArgv = process.execArgv) {
threadId: worker.threadId,
promise,
- exit() {
- forcedExit = true;
- close();
- },
+ exit,
notifyOfPeerFailure() {
send({type: 'peer-failed'});
diff --git a/node_modules/ava/lib/reporters/default.js b/node_modules/ava/lib/reporters/default.js
index 804e285..8daf5ee 100644
--- a/node_modules/ava/lib/reporters/default.js
+++ b/node_modules/ava/lib/reporters/default.js
@@ -678,8 +678,11 @@ export default class Reporter {
this.lineWriter.writeLine(colors.todo(`${this.stats.todoTests} ${plur('test', this.stats.todoTests)} todo`));
}
- if (this.stats.unhandledRejections > 0) {
- this.lineWriter.writeLine(colors.error(`${this.stats.unhandledRejections} unhandled ${plur('rejection', this.stats.unhandledRejections)}`));
+ // AGORIC: TODO(#11028): unhandled exceptions patch should be accomplished in userspace.
+ if (this.stats.unhandledRejections > 0 || process.env.AGORIC_AVA_EXPECT_UNHANDLED_REJECTIONS) {
+ const expected = Number(process.env.AGORIC_AVA_EXPECT_UNHANDLED_REJECTIONS || 0)
+ const color = this.stats.unhandledRejections === expected ? 'skip' : 'error';
+ this.lineWriter.writeLine(colors[color](`${this.stats.unhandledRejections} unhandled ${plur('rejection', this.stats.unhandledRejections)} (AGORIC_AVA_EXPECT_UNHANDLED_REJECTIONS=${expected})`));
}
if (this.stats.uncaughtExceptions > 0) {
diff --git a/node_modules/ava/lib/reporters/tap.js b/node_modules/ava/lib/reporters/tap.js
index b1989a4..fa1617f 100644
--- a/node_modules/ava/lib/reporters/tap.js
+++ b/node_modules/ava/lib/reporters/tap.js
@@ -45,6 +45,10 @@ function dumpError(error) {
return object;
}
+function durationOut(dur) {
+ return dur ? ` %ava-dur=${dur}ms` : '';
+}
+
export default class TapReporter {
constructor(options) {
this.i = 0;
@@ -96,6 +100,7 @@ export default class TapReporter {
}
writeTest(evt, flags) {
+ evt.title += durationOut(evt.duration);
this.reportStream.write(supertap.test(this.prefixTitle(evt.testFile, evt.title), {
comment: evt.logs,
error: evt.err ? dumpError(evt.err) : null,
@@ -108,7 +113,7 @@ export default class TapReporter {
writeCrash(evt, title) {
this.crashCount++;
- this.reportStream.write(supertap.test(title || evt.err.summary || evt.type, {
+ this.reportStream.write(supertap.test((title || evt.err.summary || evt.type) + durationOut(evt.duration), {
comment: evt.logs,
error: evt.err ? dumpError(evt.err) : null,
index: ++this.i,
diff --git a/node_modules/ava/lib/run-status.js b/node_modules/ava/lib/run-status.js
index 8471345..7433712 100644
--- a/node_modules/ava/lib/run-status.js
+++ b/node_modules/ava/lib/run-status.js
@@ -228,7 +228,7 @@ export default class RunStatus extends Emittery {
|| this.stats.sharedWorkerErrors > 0
|| this.stats.timeouts > 0
|| this.stats.uncaughtExceptions > 0
- || this.stats.unhandledRejections > 0
+ // AGORIC: `unhandledRejections` are processed below.
) {
return 1;
}
@@ -237,6 +237,14 @@ export default class RunStatus extends Emittery {
return 1;
}
+ // AGORIC: TODO(#11028): unhandled exceptions patch should be accomplished in userspace.
+ if (this.stats.unhandledRejections > 0 || process.env.AGORIC_AVA_EXPECT_UNHANDLED_REJECTIONS) {
+ const expected = Number(process.env.AGORIC_AVA_EXPECT_UNHANDLED_REJECTIONS || 0);
+ if (this.stats.unhandledRejections !== expected) {
+ return 1;
+ }
+ }
+
return 0;
}
diff --git a/node_modules/ava/lib/worker/base.js b/node_modules/ava/lib/worker/base.js
index cdd3c4a..4302a4a 100644
--- a/node_modules/ava/lib/worker/base.js
+++ b/node_modules/ava/lib/worker/base.js
@@ -1,5 +1,6 @@
import {createRequire} from 'node:module';
import process from 'node:process';
+import v8 from 'node:v8';
import {pathToFileURL} from 'node:url';
import {workerData} from 'node:worker_threads';
@@ -28,12 +29,17 @@ const realExit = process.exit;
async function exit(code, forceSync = false) {
dependencyTracking.flush();
+ if (process.env.NODE_V8_COVERAGE) try {
+ v8.takeCoverage();
+ } catch(err) {}
+ channel.send({type: 'exiting', code});
const flushing = channel.flush();
if (!forceSync) {
await flushing;
+ process.exitCode ||= code;
+ } else {
+ apply(realExit, process, [code]);
}
-
- apply(realExit, process, [code]);
}
const handleProcessExit = (fn, receiver, args) => {