@memlab/api 1.0.2 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/dist/API.d.ts +108 -19
- package/dist/API.js +89 -23
- package/dist/__tests__/API/E2EFindLeaks.example.js +1 -1
- package/dist/__tests__/API/E2EFindMemoryLeaks.test.js +35 -3
- package/dist/__tests__/API/E2EShapeUnboundGrowthAnalysis.test.js +4 -2
- package/dist/__tests__/heap/examples/example-1.d.ts +11 -0
- package/dist/__tests__/heap/examples/example-1.js +37 -0
- package/dist/__tests__/heap/examples/example-2.d.ts +11 -0
- package/dist/__tests__/heap/examples/example-2.js +33 -0
- package/dist/__tests__/heap/examples/example-3.d.ts +11 -0
- package/dist/__tests__/heap/examples/example-3.js +33 -0
- package/dist/__tests__/heap/examples/example-4.d.ts +11 -0
- package/dist/__tests__/heap/examples/example-4.js +32 -0
- package/dist/__tests__/heap/examples/example-5.test.d.ts +11 -0
- package/dist/__tests__/heap/examples/example-5.test.js +41 -0
- package/dist/__tests__/heap/examples/example-6.d.ts +11 -0
- package/dist/__tests__/heap/examples/example-6.js +32 -0
- package/dist/__tests__/heap/examples/example-7.test.d.ts +11 -0
- package/dist/__tests__/heap/examples/example-7.test.js +36 -0
- package/dist/__tests__/packages/heap-analysis.test.d.ts +11 -0
- package/dist/__tests__/packages/heap-analysis.test.js +82 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.js +25 -3
- package/dist/result-reader/BaseResultReader.d.ts +30 -9
- package/dist/result-reader/BaseResultReader.js +30 -6
- package/dist/result-reader/BrowserInteractionResultReader.d.ts +64 -5
- package/dist/result-reader/BrowserInteractionResultReader.js +64 -5
- package/package.json +3 -2
- package/dist/API.d.ts.map +0 -1
- package/dist/__tests__/API/E2EBasicAnalysis.test.d.ts.map +0 -1
- package/dist/__tests__/API/E2EDetachedDOMAnalysis.test.d.ts.map +0 -1
- package/dist/__tests__/API/E2EDuplicateObjectAnalysis.test.d.ts.map +0 -1
- package/dist/__tests__/API/E2EFindLeaks.example.d.ts.map +0 -1
- package/dist/__tests__/API/E2EFindMemoryLeaks.test.d.ts.map +0 -1
- package/dist/__tests__/API/E2EResultReader.test.d.ts.map +0 -1
- package/dist/__tests__/API/E2ERunMultipleSnapshots.example.d.ts.map +0 -1
- package/dist/__tests__/API/E2ERunSingleSnapshot.example.d.ts.map +0 -1
- package/dist/__tests__/API/E2EShapeUnboundGrowthAnalysis.test.d.ts.map +0 -1
- package/dist/__tests__/API/E2EStringAnalysis.test.d.ts.map +0 -1
- package/dist/__tests__/API/lib/E2ETestSettings.d.ts.map +0 -1
- package/dist/__tests__/heap/E2EHeapParser.test.d.ts.map +0 -1
- package/dist/__tests__/heap/lib/HeapParserTestUtils.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/lib/APIUtils.d.ts.map +0 -1
- package/dist/result-reader/BaseResultReader.d.ts.map +0 -1
- package/dist/result-reader/BrowserInteractionResultReader.d.ts.map +0 -1
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*
|
|
8
|
+
* @emails oncall+ws_labs
|
|
9
|
+
* @format
|
|
10
|
+
*/
|
|
11
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
12
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
13
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
14
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
15
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
16
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
17
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
const core_1 = require("@memlab/core");
|
|
22
|
+
const heap_analysis_1 = require("@memlab/heap-analysis");
|
|
23
|
+
(function () {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const heapFile = (0, core_1.dumpNodeHeapSnapshot)();
|
|
26
|
+
const heap = yield (0, heap_analysis_1.getHeapFromFile)(heapFile);
|
|
27
|
+
const node = heap.getNodeById(1);
|
|
28
|
+
if (node) {
|
|
29
|
+
console.log(node.id);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
})();
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @emails oncall+ws_labs
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=example-5.test.d.ts.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*
|
|
8
|
+
* @emails oncall+ws_labs
|
|
9
|
+
* @format
|
|
10
|
+
*/
|
|
11
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
12
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
13
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
14
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
15
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
16
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
17
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
const core_1 = require("@memlab/core");
|
|
22
|
+
class TestObject {
|
|
23
|
+
constructor() {
|
|
24
|
+
this.arr1 = [1, 2, 3];
|
|
25
|
+
this.arr2 = ['1', '2', '3'];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
test('memory test', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
|
+
core_1.config.muteConsole = true;
|
|
30
|
+
let obj = new TestObject();
|
|
31
|
+
// get a heap snapshot of the current program state
|
|
32
|
+
let heap = yield (0, core_1.getNodeInnocentHeap)();
|
|
33
|
+
// call some function that may add references to obj
|
|
34
|
+
// rabbitHole()
|
|
35
|
+
expect(heap.hasObjectWithClassName('TestObject')).toBe(true);
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
37
|
+
obj = null;
|
|
38
|
+
heap = yield (0, core_1.getNodeInnocentHeap)();
|
|
39
|
+
// if rabbitHole does not add new references, the obj can be GCed
|
|
40
|
+
expect(heap.hasObjectWithClassName('TestObject')).toBe(false);
|
|
41
|
+
}), 30000);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @emails oncall+ws_labs
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=example-6.d.ts.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*
|
|
8
|
+
* @emails oncall+ws_labs
|
|
9
|
+
* @format
|
|
10
|
+
*/
|
|
11
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
12
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
13
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
14
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
15
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
16
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
17
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
const core_1 = require("@memlab/core");
|
|
22
|
+
const heap_analysis_1 = require("@memlab/heap-analysis");
|
|
23
|
+
(function () {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
26
|
+
const object = { 'memlab-test-heap-property': 'memlab-test-heap-value' };
|
|
27
|
+
const heapFile = (0, core_1.dumpNodeHeapSnapshot)();
|
|
28
|
+
const heap = yield (0, heap_analysis_1.getHeapFromFile)(heapFile);
|
|
29
|
+
// should be true
|
|
30
|
+
console.log(heap.hasObjectWithPropertyName('memlab-test-heap-property'));
|
|
31
|
+
});
|
|
32
|
+
})();
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @emails oncall+ws_labs
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=example-7.test.d.ts.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*
|
|
8
|
+
* @emails oncall+ws_labs
|
|
9
|
+
* @format
|
|
10
|
+
*/
|
|
11
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
12
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
13
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
14
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
15
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
16
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
17
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
const core_1 = require("@memlab/core");
|
|
22
|
+
test('memory test', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
+
core_1.config.muteConsole = true;
|
|
24
|
+
const o1 = {};
|
|
25
|
+
let o2 = {};
|
|
26
|
+
// tag o1 with marker: "memlab-mark-1"
|
|
27
|
+
(0, core_1.tagObject)(o1, 'memlab-mark-1');
|
|
28
|
+
// tag o2 with marker: "memlab-mark-2"
|
|
29
|
+
(0, core_1.tagObject)(o2, 'memlab-mark-2');
|
|
30
|
+
o2 = null;
|
|
31
|
+
const heap = yield (0, core_1.getNodeInnocentHeap)();
|
|
32
|
+
// expect object with marker "memlab-mark-1" exists
|
|
33
|
+
expect(heap.hasObjectWithTag('memlab-mark-1')).toBe(true);
|
|
34
|
+
// expect object with marker "memlab-mark-2" can be GCed
|
|
35
|
+
expect(heap.hasObjectWithTag('memlab-mark-2')).toBe(false);
|
|
36
|
+
}), 30000);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @emails oncall+ws_labs
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=heap-analysis.test.d.ts.map
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*
|
|
8
|
+
* @emails oncall+ws_labs
|
|
9
|
+
* @format
|
|
10
|
+
*/
|
|
11
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
12
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
13
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
14
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
15
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
16
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
17
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
const heap_analysis_1 = require("@memlab/heap-analysis");
|
|
22
|
+
const index_1 = require("../../index");
|
|
23
|
+
const E2ETestSettings_1 = require("../API/lib/E2ETestSettings");
|
|
24
|
+
const API_1 = require("../../API");
|
|
25
|
+
beforeEach(E2ETestSettings_1.testSetup);
|
|
26
|
+
function injectTestObject() {
|
|
27
|
+
class TestObject {
|
|
28
|
+
}
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
window.injectHookForLink4 = () => {
|
|
31
|
+
// @ts-ignore
|
|
32
|
+
const arr = (window.__injectedValue = window.__injectedValue || []);
|
|
33
|
+
arr.push(new TestObject());
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const selfDefinedScenario = {
|
|
37
|
+
app: () => 'test-spa',
|
|
38
|
+
url: () => '',
|
|
39
|
+
action: (page) => __awaiter(void 0, void 0, void 0, function* () { return yield page.click('[data-testid="link-4"]'); }),
|
|
40
|
+
repeat: () => 3,
|
|
41
|
+
};
|
|
42
|
+
class ExampleAnalysis extends heap_analysis_1.BaseAnalysis {
|
|
43
|
+
constructor() {
|
|
44
|
+
super(...arguments);
|
|
45
|
+
this.isMonotonicIncreasing = false;
|
|
46
|
+
}
|
|
47
|
+
getCommandName() {
|
|
48
|
+
return 'example-analysis';
|
|
49
|
+
}
|
|
50
|
+
getDescription() {
|
|
51
|
+
return 'an example analysis for demo';
|
|
52
|
+
}
|
|
53
|
+
process(options) {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
// check if the number of TestObject keeps growing overtime
|
|
56
|
+
this.isMonotonicIncreasing = yield (0, heap_analysis_1.snapshotMapReduce)(heap => {
|
|
57
|
+
let cnt = 0;
|
|
58
|
+
heap.nodes.forEach(node => {
|
|
59
|
+
if (node.name === 'TestObject' && node.type === 'object') {
|
|
60
|
+
++cnt;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
return cnt;
|
|
64
|
+
}, nodeCounts => nodeCounts[0] === 0 &&
|
|
65
|
+
nodeCounts[nodeCounts.length - 1] === 4 &&
|
|
66
|
+
nodeCounts.every((count, i) => i === 0 || count >= nodeCounts[i - 1]), options);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
test('snapshotMapReduce works as expected', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
71
|
+
const results = yield (0, API_1.takeSnapshots)({
|
|
72
|
+
scenario: selfDefinedScenario,
|
|
73
|
+
evalInBrowserAfterInitLoad: injectTestObject,
|
|
74
|
+
snapshotForEachStep: true,
|
|
75
|
+
});
|
|
76
|
+
let analysis = new ExampleAnalysis();
|
|
77
|
+
yield (0, index_1.analyze)(results, analysis);
|
|
78
|
+
expect(analysis.isMonotonicIncreasing).toBe(true);
|
|
79
|
+
analysis = new ExampleAnalysis();
|
|
80
|
+
yield analysis.analyzeSnapshotsInDirectory(results.getSnapshotFileDir());
|
|
81
|
+
expect(analysis.isMonotonicIncreasing).toBe(true);
|
|
82
|
+
}), E2ETestSettings_1.testTimeout);
|
package/dist/index.d.ts
CHANGED
|
@@ -7,8 +7,12 @@
|
|
|
7
7
|
* @emails oncall+ws_labs
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
|
+
/** @internal */
|
|
11
|
+
export declare function registerPackage(): Promise<void>;
|
|
10
12
|
export * from './API';
|
|
11
13
|
export * from '@memlab/heap-analysis';
|
|
12
|
-
export { config } from '@memlab/core';
|
|
13
14
|
export { default as BrowserInteractionResultReader } from './result-reader/BrowserInteractionResultReader';
|
|
15
|
+
export { dumpNodeHeapSnapshot, getNodeInnocentHeap } from '@memlab/core';
|
|
16
|
+
/** @internal */
|
|
17
|
+
export { config } from '@memlab/core';
|
|
14
18
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -22,14 +22,36 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
22
22
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
23
23
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
24
24
|
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
25
34
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
36
|
};
|
|
28
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.BrowserInteractionResultReader = exports.
|
|
38
|
+
exports.config = exports.getNodeInnocentHeap = exports.dumpNodeHeapSnapshot = exports.BrowserInteractionResultReader = exports.registerPackage = void 0;
|
|
39
|
+
const path_1 = __importDefault(require("path"));
|
|
40
|
+
const core_1 = require("@memlab/core");
|
|
41
|
+
/** @internal */
|
|
42
|
+
function registerPackage() {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
return core_1.PackageInfoLoader.registerPackage(path_1.default.join(__dirname, '..'));
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
exports.registerPackage = registerPackage;
|
|
30
48
|
__exportStar(require("./API"), exports);
|
|
31
49
|
__exportStar(require("@memlab/heap-analysis"), exports);
|
|
32
|
-
var core_1 = require("@memlab/core");
|
|
33
|
-
Object.defineProperty(exports, "config", { enumerable: true, get: function () { return core_1.config; } });
|
|
34
50
|
var BrowserInteractionResultReader_1 = require("./result-reader/BrowserInteractionResultReader");
|
|
35
51
|
Object.defineProperty(exports, "BrowserInteractionResultReader", { enumerable: true, get: function () { return __importDefault(BrowserInteractionResultReader_1).default; } });
|
|
52
|
+
var core_2 = require("@memlab/core");
|
|
53
|
+
Object.defineProperty(exports, "dumpNodeHeapSnapshot", { enumerable: true, get: function () { return core_2.dumpNodeHeapSnapshot; } });
|
|
54
|
+
Object.defineProperty(exports, "getNodeInnocentHeap", { enumerable: true, get: function () { return core_2.getNodeInnocentHeap; } });
|
|
55
|
+
/** @internal */
|
|
56
|
+
var core_3 = require("@memlab/core");
|
|
57
|
+
Object.defineProperty(exports, "config", { enumerable: true, get: function () { return core_3.config; } });
|
|
@@ -14,11 +14,8 @@ import { FileManager } from '@memlab/core';
|
|
|
14
14
|
* a memlab run
|
|
15
15
|
*/
|
|
16
16
|
export default class BaseResultReader {
|
|
17
|
-
/** @ignore */
|
|
18
17
|
protected workDir: string;
|
|
19
|
-
/** @ignore */
|
|
20
18
|
protected fileManager: FileManager;
|
|
21
|
-
/** @ignore */
|
|
22
19
|
private isValid;
|
|
23
20
|
/**
|
|
24
21
|
* build a result reader
|
|
@@ -26,23 +23,47 @@ export default class BaseResultReader {
|
|
|
26
23
|
* and generated files of the memlab run were stored
|
|
27
24
|
*/
|
|
28
25
|
protected constructor(workDir?: string);
|
|
29
|
-
/** @ignore */
|
|
30
26
|
protected check(): void;
|
|
31
27
|
/**
|
|
32
|
-
*
|
|
33
|
-
* @param workDir
|
|
34
|
-
*
|
|
35
|
-
* @returns the ResultReader instance
|
|
28
|
+
* internal
|
|
29
|
+
* @param workDir
|
|
30
|
+
* @returns
|
|
36
31
|
*/
|
|
37
32
|
static from(workDir?: string): BaseResultReader;
|
|
38
33
|
/**
|
|
39
34
|
* get the directory where the data and generated files of
|
|
40
35
|
* the memlab run were stored
|
|
41
36
|
* @returns absolute path of the directory
|
|
37
|
+
* * **Examples**:
|
|
38
|
+
* ```javascript
|
|
39
|
+
* const {takeSnapshots} = require('@memlab/api');
|
|
40
|
+
*
|
|
41
|
+
* (async function () {
|
|
42
|
+
* const scenario = { url: () => 'https://www.npmjs.com'};
|
|
43
|
+
* const result = await takeSnapshots({scenario});
|
|
44
|
+
*
|
|
45
|
+
* // get the directory that stores all the files
|
|
46
|
+
* // generated from the takeSnapshots call
|
|
47
|
+
* const dataDir = result.getRootDirectory();
|
|
48
|
+
* })();
|
|
49
|
+
* ```
|
|
42
50
|
*/
|
|
43
51
|
getRootDirectory(): string;
|
|
44
52
|
/**
|
|
45
|
-
* clean up data/files generated from the memlab run
|
|
53
|
+
* clean up data/files generated from the memlab browser interaction run
|
|
54
|
+
* @returns no return value
|
|
55
|
+
* * **Examples**:
|
|
56
|
+
* ```javascript
|
|
57
|
+
* const {takeSnapshots} = require('@memlab/api');
|
|
58
|
+
*
|
|
59
|
+
* (async function () {
|
|
60
|
+
* const scenario = { url: () => 'https://www.npmjs.com'};
|
|
61
|
+
* const result = await takeSnapshots({scenario});
|
|
62
|
+
*
|
|
63
|
+
* // delete all data/files generated by takeSnapshots
|
|
64
|
+
* result.cleanup();
|
|
65
|
+
* })();
|
|
66
|
+
* ```
|
|
46
67
|
*/
|
|
47
68
|
cleanup(): void;
|
|
48
69
|
}
|
|
@@ -33,7 +33,6 @@ class BaseResultReader {
|
|
|
33
33
|
this.workDir = workDir;
|
|
34
34
|
this.check();
|
|
35
35
|
}
|
|
36
|
-
/** @ignore */
|
|
37
36
|
check() {
|
|
38
37
|
this.isValid = fs_extra_1.default.existsSync(this.workDir);
|
|
39
38
|
if (!this.isValid) {
|
|
@@ -41,10 +40,9 @@ class BaseResultReader {
|
|
|
41
40
|
}
|
|
42
41
|
}
|
|
43
42
|
/**
|
|
44
|
-
*
|
|
45
|
-
* @param workDir
|
|
46
|
-
*
|
|
47
|
-
* @returns the ResultReader instance
|
|
43
|
+
* internal
|
|
44
|
+
* @param workDir
|
|
45
|
+
* @returns
|
|
48
46
|
*/
|
|
49
47
|
static from(workDir = '') {
|
|
50
48
|
return new BaseResultReader(workDir);
|
|
@@ -53,13 +51,39 @@ class BaseResultReader {
|
|
|
53
51
|
* get the directory where the data and generated files of
|
|
54
52
|
* the memlab run were stored
|
|
55
53
|
* @returns absolute path of the directory
|
|
54
|
+
* * **Examples**:
|
|
55
|
+
* ```javascript
|
|
56
|
+
* const {takeSnapshots} = require('@memlab/api');
|
|
57
|
+
*
|
|
58
|
+
* (async function () {
|
|
59
|
+
* const scenario = { url: () => 'https://www.npmjs.com'};
|
|
60
|
+
* const result = await takeSnapshots({scenario});
|
|
61
|
+
*
|
|
62
|
+
* // get the directory that stores all the files
|
|
63
|
+
* // generated from the takeSnapshots call
|
|
64
|
+
* const dataDir = result.getRootDirectory();
|
|
65
|
+
* })();
|
|
66
|
+
* ```
|
|
56
67
|
*/
|
|
57
68
|
getRootDirectory() {
|
|
58
69
|
this.check();
|
|
59
70
|
return this.workDir;
|
|
60
71
|
}
|
|
61
72
|
/**
|
|
62
|
-
* clean up data/files generated from the memlab run
|
|
73
|
+
* clean up data/files generated from the memlab browser interaction run
|
|
74
|
+
* @returns no return value
|
|
75
|
+
* * **Examples**:
|
|
76
|
+
* ```javascript
|
|
77
|
+
* const {takeSnapshots} = require('@memlab/api');
|
|
78
|
+
*
|
|
79
|
+
* (async function () {
|
|
80
|
+
* const scenario = { url: () => 'https://www.npmjs.com'};
|
|
81
|
+
* const result = await takeSnapshots({scenario});
|
|
82
|
+
*
|
|
83
|
+
* // delete all data/files generated by takeSnapshots
|
|
84
|
+
* result.cleanup();
|
|
85
|
+
* })();
|
|
86
|
+
* ```
|
|
63
87
|
*/
|
|
64
88
|
cleanup() {
|
|
65
89
|
if (!this.isValid) {
|
|
@@ -16,30 +16,89 @@ import BaseResultReader from './BaseResultReader';
|
|
|
16
16
|
*/
|
|
17
17
|
export default class BrowserInteractionResultReader extends BaseResultReader {
|
|
18
18
|
/**
|
|
19
|
-
* build a result reader
|
|
20
|
-
*
|
|
21
|
-
*
|
|
19
|
+
* build a result reader from a data directory where the data
|
|
20
|
+
* and generated files of a memlab run were stored
|
|
21
|
+
* @param workDir absolute path of the data directory
|
|
22
22
|
* @returns the ResultReader instance
|
|
23
|
+
*
|
|
24
|
+
* * **Examples**:
|
|
25
|
+
* ```javascript
|
|
26
|
+
* const {BrowserInteractionResultReader} = require('@memlab/api');
|
|
27
|
+
*
|
|
28
|
+
* const dataDir = '/tmp/memlab'; // where the last memlab run stores results
|
|
29
|
+
* const reader = BrowserInteractionResultReader.from(dataDir);
|
|
30
|
+
* reader.cleanup(); // clean up the results
|
|
31
|
+
* ```
|
|
23
32
|
*/
|
|
24
33
|
static from(workDir?: string): BrowserInteractionResultReader;
|
|
25
34
|
/**
|
|
26
|
-
* get all snapshot files
|
|
35
|
+
* get all snapshot files generated from last memlab browser interaction
|
|
27
36
|
* @returns an array of snapshot file's absolute path
|
|
37
|
+
* * **Examples**:
|
|
38
|
+
* ```javascript
|
|
39
|
+
* const {takeSnapshots} = require('@memlab/api');
|
|
40
|
+
*
|
|
41
|
+
* (async function () {
|
|
42
|
+
* const scenario = { url: () => 'https://www.npmjs.com'};
|
|
43
|
+
* const result = await takeSnapshots({scenario});
|
|
44
|
+
*
|
|
45
|
+
* // get absolute paths of all snapshot files
|
|
46
|
+
* const files = result.getSnapshotFiles();
|
|
47
|
+
* })();
|
|
48
|
+
* ```
|
|
28
49
|
*/
|
|
29
50
|
getSnapshotFiles(): string[];
|
|
30
51
|
/**
|
|
31
52
|
* get the directory holding all snapshot files
|
|
32
53
|
* @returns the absolute path of the directory
|
|
54
|
+
* * **Examples**:
|
|
55
|
+
* ```javascript
|
|
56
|
+
* const {takeSnapshots} = require('@memlab/api');
|
|
57
|
+
*
|
|
58
|
+
* (async function () {
|
|
59
|
+
* const scenario = { url: () => 'https://www.npmjs.com'};
|
|
60
|
+
* const result = await takeSnapshots({scenario});
|
|
61
|
+
*
|
|
62
|
+
* // get the absolute path the directory holding all snapshot files
|
|
63
|
+
* const files = result.getSnapshotFileDir();
|
|
64
|
+
* })();
|
|
65
|
+
* ```
|
|
33
66
|
*/
|
|
34
67
|
getSnapshotFileDir(): string;
|
|
35
68
|
/**
|
|
36
69
|
* browser interaction step sequence
|
|
37
|
-
* @returns an array of browser interaction step
|
|
70
|
+
* @returns an array of browser interaction step information
|
|
71
|
+
* * **Examples**:
|
|
72
|
+
* ```javascript
|
|
73
|
+
* const {takeSnapshots} = require('@memlab/api');
|
|
74
|
+
*
|
|
75
|
+
* (async function () {
|
|
76
|
+
* const scenario = { url: () => 'https://www.npmjs.com'};
|
|
77
|
+
* const result = await takeSnapshots({scenario});
|
|
78
|
+
*
|
|
79
|
+
* const steps = result.getInteractionSteps();
|
|
80
|
+
* // print each browser interaction's name and JavaScript heap size (in bytes)
|
|
81
|
+
* steps.forEach(step => console.log(step.name, step.JSHeapUsedSize))
|
|
82
|
+
* })();
|
|
83
|
+
* ```
|
|
38
84
|
*/
|
|
39
85
|
getInteractionSteps(): E2EStepInfo[];
|
|
40
86
|
/**
|
|
41
87
|
* general meta data of the browser interaction run
|
|
42
88
|
* @returns meta data about the entire browser interaction
|
|
89
|
+
* * **Examples**:
|
|
90
|
+
* ```javascript
|
|
91
|
+
* const {takeSnapshots} = require('@memlab/api');
|
|
92
|
+
*
|
|
93
|
+
* (async function () {
|
|
94
|
+
* const scenario = { url: () => 'https://www.npmjs.com'};
|
|
95
|
+
* const result = await takeSnapshots({scenario});
|
|
96
|
+
*
|
|
97
|
+
* const metaInfo = result.getRunMetaInfo();
|
|
98
|
+
* // print all browser web console output
|
|
99
|
+
* console.log(metaInfo.browserInfo._consoleMessages.join('\n'));
|
|
100
|
+
* })();
|
|
101
|
+
* ```
|
|
43
102
|
*/
|
|
44
103
|
getRunMetaInfo(): RunMetaInfo;
|
|
45
104
|
}
|
|
@@ -23,17 +23,38 @@ const BaseResultReader_1 = __importDefault(require("./BaseResultReader"));
|
|
|
23
23
|
*/
|
|
24
24
|
class BrowserInteractionResultReader extends BaseResultReader_1.default {
|
|
25
25
|
/**
|
|
26
|
-
* build a result reader
|
|
27
|
-
*
|
|
28
|
-
*
|
|
26
|
+
* build a result reader from a data directory where the data
|
|
27
|
+
* and generated files of a memlab run were stored
|
|
28
|
+
* @param workDir absolute path of the data directory
|
|
29
29
|
* @returns the ResultReader instance
|
|
30
|
+
*
|
|
31
|
+
* * **Examples**:
|
|
32
|
+
* ```javascript
|
|
33
|
+
* const {BrowserInteractionResultReader} = require('@memlab/api');
|
|
34
|
+
*
|
|
35
|
+
* const dataDir = '/tmp/memlab'; // where the last memlab run stores results
|
|
36
|
+
* const reader = BrowserInteractionResultReader.from(dataDir);
|
|
37
|
+
* reader.cleanup(); // clean up the results
|
|
38
|
+
* ```
|
|
30
39
|
*/
|
|
31
40
|
static from(workDir = '') {
|
|
32
41
|
return new BrowserInteractionResultReader(workDir);
|
|
33
42
|
}
|
|
34
43
|
/**
|
|
35
|
-
* get all snapshot files
|
|
44
|
+
* get all snapshot files generated from last memlab browser interaction
|
|
36
45
|
* @returns an array of snapshot file's absolute path
|
|
46
|
+
* * **Examples**:
|
|
47
|
+
* ```javascript
|
|
48
|
+
* const {takeSnapshots} = require('@memlab/api');
|
|
49
|
+
*
|
|
50
|
+
* (async function () {
|
|
51
|
+
* const scenario = { url: () => 'https://www.npmjs.com'};
|
|
52
|
+
* const result = await takeSnapshots({scenario});
|
|
53
|
+
*
|
|
54
|
+
* // get absolute paths of all snapshot files
|
|
55
|
+
* const files = result.getSnapshotFiles();
|
|
56
|
+
* })();
|
|
57
|
+
* ```
|
|
37
58
|
*/
|
|
38
59
|
getSnapshotFiles() {
|
|
39
60
|
this.check();
|
|
@@ -46,6 +67,18 @@ class BrowserInteractionResultReader extends BaseResultReader_1.default {
|
|
|
46
67
|
/**
|
|
47
68
|
* get the directory holding all snapshot files
|
|
48
69
|
* @returns the absolute path of the directory
|
|
70
|
+
* * **Examples**:
|
|
71
|
+
* ```javascript
|
|
72
|
+
* const {takeSnapshots} = require('@memlab/api');
|
|
73
|
+
*
|
|
74
|
+
* (async function () {
|
|
75
|
+
* const scenario = { url: () => 'https://www.npmjs.com'};
|
|
76
|
+
* const result = await takeSnapshots({scenario});
|
|
77
|
+
*
|
|
78
|
+
* // get the absolute path the directory holding all snapshot files
|
|
79
|
+
* const files = result.getSnapshotFileDir();
|
|
80
|
+
* })();
|
|
81
|
+
* ```
|
|
49
82
|
*/
|
|
50
83
|
getSnapshotFileDir() {
|
|
51
84
|
this.check();
|
|
@@ -53,7 +86,20 @@ class BrowserInteractionResultReader extends BaseResultReader_1.default {
|
|
|
53
86
|
}
|
|
54
87
|
/**
|
|
55
88
|
* browser interaction step sequence
|
|
56
|
-
* @returns an array of browser interaction step
|
|
89
|
+
* @returns an array of browser interaction step information
|
|
90
|
+
* * **Examples**:
|
|
91
|
+
* ```javascript
|
|
92
|
+
* const {takeSnapshots} = require('@memlab/api');
|
|
93
|
+
*
|
|
94
|
+
* (async function () {
|
|
95
|
+
* const scenario = { url: () => 'https://www.npmjs.com'};
|
|
96
|
+
* const result = await takeSnapshots({scenario});
|
|
97
|
+
*
|
|
98
|
+
* const steps = result.getInteractionSteps();
|
|
99
|
+
* // print each browser interaction's name and JavaScript heap size (in bytes)
|
|
100
|
+
* steps.forEach(step => console.log(step.name, step.JSHeapUsedSize))
|
|
101
|
+
* })();
|
|
102
|
+
* ```
|
|
57
103
|
*/
|
|
58
104
|
getInteractionSteps() {
|
|
59
105
|
this.check();
|
|
@@ -65,6 +111,19 @@ class BrowserInteractionResultReader extends BaseResultReader_1.default {
|
|
|
65
111
|
/**
|
|
66
112
|
* general meta data of the browser interaction run
|
|
67
113
|
* @returns meta data about the entire browser interaction
|
|
114
|
+
* * **Examples**:
|
|
115
|
+
* ```javascript
|
|
116
|
+
* const {takeSnapshots} = require('@memlab/api');
|
|
117
|
+
*
|
|
118
|
+
* (async function () {
|
|
119
|
+
* const scenario = { url: () => 'https://www.npmjs.com'};
|
|
120
|
+
* const result = await takeSnapshots({scenario});
|
|
121
|
+
*
|
|
122
|
+
* const metaInfo = result.getRunMetaInfo();
|
|
123
|
+
* // print all browser web console output
|
|
124
|
+
* console.log(metaInfo.browserInfo._consoleMessages.join('\n'));
|
|
125
|
+
* })();
|
|
126
|
+
* ```
|
|
68
127
|
*/
|
|
69
128
|
getRunMetaInfo() {
|
|
70
129
|
this.check();
|