1'use strict'; 2 3const common = require('../common'); 4 5if (!common.isMainThread) 6 common.skip('process.chdir is not available in Workers'); 7 8const { writeHeapSnapshot, getHeapSnapshot } = require('v8'); 9const assert = require('assert'); 10const fs = require('fs'); 11const tmpdir = require('../common/tmpdir'); 12 13tmpdir.refresh(); 14process.chdir(tmpdir.path); 15 16{ 17 writeHeapSnapshot('my.heapdump'); 18 fs.accessSync('my.heapdump'); 19} 20 21{ 22 const heapdump = writeHeapSnapshot(); 23 assert.strictEqual(typeof heapdump, 'string'); 24 fs.accessSync(heapdump); 25} 26 27[1, true, {}, [], null, Infinity, NaN].forEach((i) => { 28 assert.throws(() => writeHeapSnapshot(i), { 29 code: 'ERR_INVALID_ARG_TYPE', 30 name: 'TypeError', 31 message: 'The "path" argument must be of type string or an instance of ' + 32 'Buffer or URL.' + 33 common.invalidArgTypeHelper(i) 34 }); 35}); 36 37{ 38 let data = ''; 39 const snapshot = getHeapSnapshot(); 40 snapshot.setEncoding('utf-8'); 41 snapshot.on('data', common.mustCallAtLeast((chunk) => { 42 data += chunk.toString(); 43 })); 44 snapshot.on('end', common.mustCall(() => { 45 JSON.parse(data); 46 })); 47} 48