Skip to content

Commit 7efe226

Browse files
committed
Confirm test output
1 parent 100fa76 commit 7efe226

File tree

7 files changed

+652
-16
lines changed

7 files changed

+652
-16
lines changed

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
node_modules/
22
build/
3-
yarn.lock
4-
package-lock.json

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
"license": "MIT",
77
"scripts": {
88
"install": "node-gyp configure && node-gyp build",
9-
"test": "node test/test.js"
9+
"test": "vitest run ./test/*.test.js --silent=false --disable-console-intercept"
10+
},
11+
"devDependencies": {
12+
"vitest": "^3.1.4"
1013
},
1114
"volta": {
1215
"node": "22.15.1"

test/basic.test.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { describe, test, expect } from 'vitest';
2+
import { spawnSync } from 'node:child_process';
3+
import { join } from 'node:path';
4+
5+
const __dirname = import.meta.dirname || new URL('.', import.meta.url).pathname;
6+
7+
describe("Basic", () => {
8+
const testFile = join(__dirname, 'test.js');
9+
test("Should capture stack trace from multiple threads", () => {
10+
const result = spawnSync('node', [testFile])
11+
expect(result.status).toBe(0);
12+
13+
const stacks = JSON.parse(result.stdout.toString());
14+
15+
expect(stacks.main).toEqual(expect.arrayContaining([
16+
{
17+
function: 'pbkdf2Sync',
18+
filename: expect.any(String),
19+
lineno: expect.any(Number),
20+
colno: expect.any(Number),
21+
},
22+
{
23+
function: 'longWork',
24+
filename: expect.stringMatching(/test.js$/),
25+
lineno: 18,
26+
colno: 29
27+
},
28+
{
29+
function: '?',
30+
filename: expect.stringMatching(/test.js$/),
31+
lineno: 22,
32+
colno: 1
33+
},
34+
]));
35+
36+
expect(stacks['worker-2']).toEqual(expect.arrayContaining([
37+
{
38+
function: 'pbkdf2Sync',
39+
filename: expect.any(String),
40+
lineno: expect.any(Number),
41+
colno: expect.any(Number),
42+
},
43+
{
44+
function: 'longWork',
45+
filename: expect.stringMatching(/worker.js$/),
46+
lineno: 10,
47+
colno: 29
48+
},
49+
{
50+
function: '?',
51+
filename: expect.stringMatching(/worker.js$/),
52+
lineno: 14,
53+
colno: 1
54+
},
55+
]));
56+
});
57+
});

test/test.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
const { Worker } = require('node:worker_threads');
22
const crypto = require('node:crypto');
33

4-
const { registerThread } = require('../index.js');
4+
const { registerThread } = require('..');
55

6-
registerThread(true);
6+
registerThread();
77

88
const watchdog = new Worker('./test/watchdog.js');
9-
watchdog.on('exit', (code) => console.log(`watchdog stopped with exit code ${code}`));
10-
watchdog.on('error', (error) => console.error('watchdog error:', error));
11-
9+
watchdog.on('message', (message) => console.log(message));
1210

1311
const worker = new Worker('./test/worker.js');
14-
worker.on('exit', (code) => console.log(`Worker stopped with exit code ${code}`));
15-
worker.on('error', (error) => console.error('Worker error:', error));
1612

1713
function longWork() {
1814
for (let i = 0; i < 100; i++) {

test/watchdog.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
const { captureStackTrace } = require('..');
2-
const { inspect } = require('util');
32

43
setTimeout(() => {
5-
console.time('captureStackTrace');
6-
const result = captureStackTrace();
7-
console.timeEnd('captureStackTrace');
8-
console.log(inspect(result, false, null, true));
4+
console.log(JSON.stringify(captureStackTrace()));
95
}, 2000);
106

test/worker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const crypto = require('node:crypto');
22

3-
const { registerThread } = require('../index.js');
3+
const { registerThread } = require('..');
44

55
registerThread();
66

0 commit comments

Comments
 (0)