-
Notifications
You must be signed in to change notification settings - Fork 30.1k
/
test-heapdump.js
78 lines (67 loc) · 1.95 KB
/
test-heapdump.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
'use strict';
const common = require('../common');
if (!common.isMainThread)
common.skip('process.chdir is not available in Workers');
const { writeHeapSnapshot, getHeapSnapshot } = require('v8');
const assert = require('assert');
const fs = require('fs');
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
process.chdir(tmpdir.path);
{
writeHeapSnapshot('my.heapdump');
fs.accessSync('my.heapdump');
}
{
const heapdump = writeHeapSnapshot();
assert.strictEqual(typeof heapdump, 'string');
fs.accessSync(heapdump);
}
{
const directory = 'directory';
fs.mkdirSync(directory);
assert.throws(() => {
writeHeapSnapshot(directory);
}, (e) => {
assert.ok(e, 'writeHeapSnapshot should error');
assert.strictEqual(e.code, 'EISDIR');
assert.strictEqual(e.syscall, 'open');
return true;
});
}
[1, true, {}, [], null, Infinity, NaN].forEach((i) => {
assert.throws(() => writeHeapSnapshot(i), {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "path" argument must be of type string or an instance of ' +
'Buffer or URL.' +
common.invalidArgTypeHelper(i)
});
});
[1, true, [], null, Infinity, NaN].forEach((i) => {
assert.throws(() => writeHeapSnapshot('test.heapsnapshot', i), {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "options" argument must be of type object.' +
common.invalidArgTypeHelper(i)
});
});
[1, true, [], null, Infinity, NaN].forEach((i) => {
assert.throws(() => getHeapSnapshot(i), {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "options" argument must be of type object.' +
common.invalidArgTypeHelper(i)
});
});
{
let data = '';
const snapshot = getHeapSnapshot();
snapshot.setEncoding('utf-8');
snapshot.on('data', common.mustCallAtLeast((chunk) => {
data += chunk.toString();
}));
snapshot.on('end', common.mustCall(() => {
JSON.parse(data);
}));
}