1'use strict'; 2 3// This test is to ensure that --diagnostic-dir does not change the directory 4// for --cpu-prof when --cpu-prof-dir is specified 5 6const common = require('../common'); 7const fixtures = require('../common/fixtures'); 8common.skipIfInspectorDisabled(); 9 10const assert = require('assert'); 11const fs = require('fs'); 12const path = require('path'); 13const { spawnSync } = require('child_process'); 14 15const tmpdir = require('../common/tmpdir'); 16const { 17 getCpuProfiles, 18 kCpuProfInterval, 19 env, 20 verifyFrames 21} = require('../common/cpu-prof'); 22 23// Test --diagnostic-dir changes the default for --cpu-prof 24 25{ 26 tmpdir.refresh(); 27 const dir = path.join(tmpdir.path, 'prof'); 28 const output = spawnSync(process.execPath, [ 29 '--cpu-prof', 30 '--cpu-prof-interval', 31 kCpuProfInterval, 32 '--diagnostic-dir', 33 dir, 34 fixtures.path('workload', 'fibonacci.js'), 35 ], { 36 cwd: tmpdir.path, 37 env 38 }); 39 if (output.status !== 0) { 40 console.log(output.stderr.toString()); 41 } 42 assert.strictEqual(output.status, 0); 43 assert(fs.existsSync(dir)); 44 const profiles = getCpuProfiles(dir); 45 assert.strictEqual(profiles.length, 1); 46 verifyFrames(output, profiles[0], 'fibonacci.js'); 47} 48 49// Test --cpu-prof-dir overwrites --diagnostic-dir 50 51{ 52 tmpdir.refresh(); 53 const dir = path.join(tmpdir.path, 'diag'); 54 const dir2 = path.join(tmpdir.path, 'prof'); 55 const output = spawnSync(process.execPath, [ 56 '--cpu-prof', 57 '--cpu-prof-interval', 58 kCpuProfInterval, 59 '--diagnostic-dir', 60 dir, 61 '--cpu-prof-dir', 62 dir2, 63 fixtures.path('workload', 'fibonacci.js'), 64 ], { 65 cwd: tmpdir.path, 66 env 67 }); 68 if (output.status !== 0) { 69 console.log(output.stderr.toString()); 70 } 71 assert.strictEqual(output.status, 0); 72 assert(fs.existsSync(dir2)); 73 const profiles = getCpuProfiles(dir2); 74 assert.strictEqual(profiles.length, 1); 75 verifyFrames(output, profiles[0], 'fibonacci.js'); 76} 77