Skip to content

Commit a0b799f

Browse files
cola119targos
authored andcommitted
test: add test for profile command of node inspect
PR-URL: #43058 Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com> Reviewed-By: Akhil Marsonya <akhil.marsonya27@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
1 parent bf62ffd commit a0b799f

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'use strict';
2+
const common = require('../common');
3+
4+
common.skipIfInspectorDisabled();
5+
6+
const fixtures = require('../common/fixtures');
7+
const startCLI = require('../common/debugger');
8+
9+
const assert = require('assert');
10+
const fs = require('fs');
11+
const path = require('path');
12+
13+
const cli = startCLI([fixtures.path('debugger/empty.js')]);
14+
15+
const rootDir = path.resolve(__dirname, '..', '..');
16+
17+
(async () => {
18+
await cli.waitForInitialBreak();
19+
await cli.waitForPrompt();
20+
await cli.command('profile');
21+
await cli.command('profileEnd');
22+
assert.match(cli.output, /\[Profile \d+μs\]/);
23+
await cli.command('profiles');
24+
assert.match(cli.output, /\[ \[Profile \d+μs\] \]/);
25+
await cli.command('profiles[0].save()');
26+
assert.match(cli.output, /Saved profile to .*node\.cpuprofile/);
27+
28+
const cpuprofile = path.resolve(rootDir, 'node.cpuprofile');
29+
const data = JSON.parse(fs.readFileSync(cpuprofile, 'utf8'));
30+
assert.strictEqual(Array.isArray(data.nodes), true);
31+
32+
fs.rmSync(cpuprofile);
33+
})()
34+
.then(common.mustCall())
35+
.finally(() => cli.quit());

0 commit comments

Comments
 (0)