1'use strict'; 2 3// Tests invalid --heap-prof CLI arguments. 4 5const common = require('../common'); 6 7const fixtures = require('../common/fixtures'); 8common.skipIfInspectorDisabled(); 9 10const assert = require('assert'); 11const { spawnSync } = require('child_process'); 12 13const tmpdir = require('../common/tmpdir'); 14 15const { 16 kHeapProfInterval, 17 env 18} = require('../common/prof'); 19 20// Tests --heap-prof-name without --heap-prof. 21{ 22 tmpdir.refresh(); 23 const output = spawnSync(process.execPath, [ 24 '--heap-prof-name', 25 'test.heapprofile', 26 fixtures.path('workload', 'allocation.js'), 27 ], { 28 cwd: tmpdir.path, 29 env 30 }); 31 const stderr = output.stderr.toString().trim(); 32 if (output.status !== 9) { 33 console.log(stderr); 34 } 35 assert.strictEqual(output.status, 9); 36 assert.strictEqual( 37 stderr, 38 `${process.execPath}: --heap-prof-name must be used with --heap-prof`); 39} 40 41// Tests --heap-prof-dir without --heap-prof. 42{ 43 tmpdir.refresh(); 44 const output = spawnSync(process.execPath, [ 45 '--heap-prof-dir', 46 'prof', 47 fixtures.path('workload', 'allocation.js'), 48 ], { 49 cwd: tmpdir.path, 50 env 51 }); 52 const stderr = output.stderr.toString().trim(); 53 if (output.status !== 9) { 54 console.log(stderr); 55 } 56 assert.strictEqual(output.status, 9); 57 assert.strictEqual( 58 stderr, 59 `${process.execPath}: --heap-prof-dir must be used with --heap-prof`); 60} 61 62// Tests --heap-prof-interval without --heap-prof. 63{ 64 tmpdir.refresh(); 65 const output = spawnSync(process.execPath, [ 66 '--heap-prof-interval', 67 kHeapProfInterval, 68 fixtures.path('workload', 'allocation.js'), 69 ], { 70 cwd: tmpdir.path, 71 env 72 }); 73 const stderr = output.stderr.toString().trim(); 74 if (output.status !== 9) { 75 console.log(stderr); 76 } 77 assert.strictEqual(output.status, 9); 78 assert.strictEqual( 79 stderr, 80 `${process.execPath}: ` + 81 '--heap-prof-interval must be used with --heap-prof'); 82} 83