Skip to content

Commit ef2ed71

Browse files
jasnelladuh95
authored andcommittedJan 30, 2025
test: rely less on duplicative common test harness utilities
There are several cleanups here that are not just style nits... 1. The `common.isMainThread` was just a passthrough to the `isMainThread` export on the worker_thread module. It's use was inconsistent and just obfuscated the fact that the test file depend on the `worker_threads` built-in. By eliminating it we simplify the test harness a bit and make it clearer which tests depend on the worker_threads check. 2. The `common.isDumbTerminal` is fairly unnecesary since that just wraps a public API check. 3. Several of the `common.skipIf....` checks were inconsistently used and really don't need to be separate utility functions. A key part of the motivation here is to work towards making more of the tests more self-contained and less reliant on the common test harness where possible. PR-URL: #56712 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent e654c8b commit ef2ed71

File tree

148 files changed

+672
-290
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

148 files changed

+672
-290
lines changed
 

‎test/abort/test-abort-backtrace.js

+42-3
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,63 @@
11
'use strict';
2-
const common = require('../common');
2+
require('../common');
33
const assert = require('assert');
44
const cp = require('child_process');
55

6+
function getPrintedStackTrace(stderr) {
7+
const lines = stderr.split('\n');
8+
9+
let state = 'initial';
10+
const result = {
11+
message: [],
12+
nativeStack: [],
13+
jsStack: [],
14+
};
15+
for (let i = 0; i < lines.length; ++i) {
16+
const line = lines[i].trim();
17+
if (line.length === 0) {
18+
continue; // Skip empty lines.
19+
}
20+
21+
switch (state) {
22+
case 'initial':
23+
result.message.push(line);
24+
if (line.includes('Native stack trace')) {
25+
state = 'native-stack';
26+
} else {
27+
result.message.push(line);
28+
}
29+
break;
30+
case 'native-stack':
31+
if (line.includes('JavaScript stack trace')) {
32+
state = 'js-stack';
33+
} else {
34+
result.nativeStack.push(line);
35+
}
36+
break;
37+
case 'js-stack':
38+
result.jsStack.push(line);
39+
break;
40+
}
41+
}
42+
return result;
43+
}
44+
645
if (process.argv[2] === 'child') {
746
process.abort();
847
} else {
948
const child = cp.spawnSync(`${process.execPath}`, [`${__filename}`, 'child']);
1049
const stderr = child.stderr.toString();
1150

1251
assert.strictEqual(child.stdout.toString(), '');
13-
const { nativeStack, jsStack } = common.getPrintedStackTrace(stderr);
52+
const { nativeStack, jsStack } = getPrintedStackTrace(stderr);
1453

1554
if (!nativeStack.every((frame, index) => frame.startsWith(`${index + 1}:`))) {
1655
assert.fail(`Each frame should start with a frame number:\n${stderr}`);
1756
}
1857

1958
// For systems that don't support backtraces, the native stack is
2059
// going to be empty.
21-
if (!common.isWindows && nativeStack.length > 0) {
60+
if (process.platform !== 'win32' && nativeStack.length > 0) {
2261
const { getBinaryPath } = require('../common/shared-lib-util');
2362
if (!nativeStack.some((frame) => frame.includes(`[${getBinaryPath()}]`))) {
2463
assert.fail(`Some native stack frame include the binary name:\n${stderr}`);

‎test/async-hooks/init-hooks.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
'use strict';
22
// Flags: --expose-gc
33

4-
const common = require('../common');
4+
require('../common');
55
const assert = require('assert');
66
const async_hooks = require('async_hooks');
7+
const { isMainThread } = require('worker_threads');
78
const util = require('util');
89
const print = process._rawDebug;
910

@@ -161,7 +162,7 @@ class ActivityCollector {
161162
const stub = { uid, type: 'Unknown', handleIsObject: true, handle: {} };
162163
this._activities.set(uid, stub);
163164
return stub;
164-
} else if (!common.isMainThread) {
165+
} else if (!isMainThread) {
165166
// Worker threads start main script execution inside of an AsyncWrap
166167
// callback, so we don't yield errors for these.
167168
return null;

0 commit comments

Comments
 (0)