• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const assert = require('assert');
4const common = require('./');
5
6// The formats could change when V8 is updated, then the tests should be
7// updated accordingly.
8function assertResultShape(result) {
9  assert.strictEqual(typeof result.jsMemoryEstimate, 'number');
10  assert.strictEqual(typeof result.jsMemoryRange[0], 'number');
11  assert.strictEqual(typeof result.jsMemoryRange[1], 'number');
12}
13
14function assertSummaryShape(result) {
15  assert.strictEqual(typeof result, 'object');
16  assert.strictEqual(typeof result.total, 'object');
17  assertResultShape(result.total);
18}
19
20function assertDetailedShape(result, contexts = 0) {
21  assert.strictEqual(typeof result, 'object');
22  assert.strictEqual(typeof result.total, 'object');
23  assert.strictEqual(typeof result.current, 'object');
24  assertResultShape(result.total);
25  assertResultShape(result.current);
26  if (contexts === 0) {
27    assert.deepStrictEqual(result.other, []);
28  } else {
29    assert.strictEqual(result.other.length, contexts);
30    for (const item of result.other) {
31      assertResultShape(item);
32    }
33  }
34}
35
36function assertSingleDetailedShape(result) {
37  assert.strictEqual(typeof result, 'object');
38  assert.strictEqual(typeof result.total, 'object');
39  assert.strictEqual(typeof result.current, 'object');
40  assert.deepStrictEqual(result.other, []);
41  assertResultShape(result.total);
42  assertResultShape(result.current);
43}
44
45function expectExperimentalWarning() {
46  common.expectWarning('ExperimentalWarning',
47                       'vm.measureMemory is an experimental feature. ' +
48                       'This feature could change at any time');
49}
50
51module.exports = {
52  assertSummaryShape,
53  assertDetailedShape,
54  assertSingleDetailedShape,
55  expectExperimentalWarning
56};
57