forked from nodejs/node
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest-runner-inspect.mjs
84 lines (67 loc) · 3.03 KB
/
test-runner-inspect.mjs
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
import * as common from '../common/index.mjs';
import * as tmpdir from '../common/tmpdir.js';
import * as fixtures from '../common/fixtures.mjs';
import assert from 'node:assert';
import path from 'node:path';
import fs from 'node:fs/promises';
import { NodeInstance } from '../common/inspector-helper.js';
common.skipIfInspectorDisabled();
tmpdir.refresh();
{
const child = new NodeInstance(['--test', '--inspect-brk=0'], undefined, fixtures.path('test-runner/index.test.js'));
let stdout = '';
let stderr = '';
child.on('stdout', (line) => stdout += line);
child.on('stderr', (line) => stderr += line);
const session = await child.connectInspectorSession();
await session.send([
{ method: 'Runtime.enable' },
{ method: 'Runtime.runIfWaitingForDebugger' }]);
session.disconnect();
assert.match(stderr,
/Warning: Using the inspector with --test forces running at a concurrency of 1\. Use the inspectPort option to run with concurrency/);
}
{
const args = ['--test', '--inspect=0', fixtures.path('test-runner/index.js')];
const { stderr, stdout, code, signal } = await common.spawnPromisified(process.execPath, args);
assert.match(stderr,
/Warning: Using the inspector with --test forces running at a concurrency of 1\. Use the inspectPort option to run with concurrency/);
assert.match(stdout, /not ok 1 - .+index\.js/);
assert.match(stdout, /stderr: \|-\r?\n\s+Debugger listening on/);
assert.strictEqual(code, 1);
assert.strictEqual(signal, null);
}
{
// File not found.
const args = ['--test', '--inspect=0', 'a-random-file-that-does-not-exist.js'];
const { stderr, stdout, code, signal } = await common.spawnPromisified(process.execPath, args);
assert.strictEqual(stdout, '');
assert.match(stderr, /^Could not find/);
assert.doesNotMatch(stderr, /Warning: Using the inspector with --test forces running at a concurrency of 1\. Use the inspectPort option to run with concurrency/);
assert.strictEqual(code, 1);
assert.strictEqual(signal, null);
}
// Outputs coverage when event loop is drained, with no async logic.
{
const coverageDirectory = path.join(tmpdir.path, 'coverage');
async function getCoveredFiles() {
const coverageFiles = await fs.readdir(coverageDirectory);
const files = new Set();
for (const coverageFile of coverageFiles) {
const coverage = JSON.parse(await fs.readFile(path.join(coverageDirectory, coverageFile)));
for (const { url } of coverage.result) {
if (!url.startsWith('node:')) files.add(url);
}
}
return files;
}
const { stderr, code, signal } = await common
.spawnPromisified(process.execPath,
['--test', fixtures.path('v8-coverage/basic.js')],
{ env: { ...process.env, NODE_V8_COVERAGE: coverageDirectory } });
assert.strictEqual(stderr, '');
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
const files = await getCoveredFiles(coverageDirectory);
assert.ok(files.has(fixtures.fileURL('v8-coverage/basic.js').href));
}