From 95abbe111ec447daa97e2dc8ac90296906c515a1 Mon Sep 17 00:00:00 2001 From: Kohei Ueno Date: Sun, 10 Jul 2022 05:14:27 +0900 Subject: [PATCH] test: add test for profile command of node inspect MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/43058 Reviewed-By: Darshan Sen Reviewed-By: Colin Ihrig Reviewed-By: Anto Aravinth Reviewed-By: Akhil Marsonya Reviewed-By: James M Snell Reviewed-By: Juan José Arboleda --- .../test-debugger-profile-command.js | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 test/sequential/test-debugger-profile-command.js diff --git a/test/sequential/test-debugger-profile-command.js b/test/sequential/test-debugger-profile-command.js new file mode 100644 index 00000000000..06818c2132d --- /dev/null +++ b/test/sequential/test-debugger-profile-command.js @@ -0,0 +1,35 @@ +'use strict'; +const common = require('../common'); + +common.skipIfInspectorDisabled(); + +const fixtures = require('../common/fixtures'); +const startCLI = require('../common/debugger'); + +const assert = require('assert'); +const fs = require('fs'); +const path = require('path'); + +const cli = startCLI([fixtures.path('debugger/empty.js')]); + +const rootDir = path.resolve(__dirname, '..', '..'); + +(async () => { + await cli.waitForInitialBreak(); + await cli.waitForPrompt(); + await cli.command('profile'); + await cli.command('profileEnd'); + assert.match(cli.output, /\[Profile \d+μs\]/); + await cli.command('profiles'); + assert.match(cli.output, /\[ \[Profile \d+μs\] \]/); + await cli.command('profiles[0].save()'); + assert.match(cli.output, /Saved profile to .*node\.cpuprofile/); + + const cpuprofile = path.resolve(rootDir, 'node.cpuprofile'); + const data = JSON.parse(fs.readFileSync(cpuprofile, 'utf8')); + assert.strictEqual(Array.isArray(data.nodes), true); + + fs.rmSync(cpuprofile); +})() +.then(common.mustCall()) +.finally(() => cli.quit());