@memlab/api 1.0.0 → 1.0.3

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.
Files changed (36) hide show
  1. package/README.md +5 -9
  2. package/dist/API.d.ts +139 -18
  3. package/dist/API.js +146 -17
  4. package/dist/__tests__/API/E2EDetachedDOMAnalysis.test.js +5 -6
  5. package/dist/__tests__/API/E2EDuplicateObjectAnalysis.test.js +5 -6
  6. package/dist/__tests__/API/E2EFindLeaks.example.d.ts +11 -0
  7. package/dist/__tests__/API/E2EFindLeaks.example.js +50 -0
  8. package/dist/__tests__/API/E2EFindMemoryLeaks.test.d.ts +11 -0
  9. package/dist/__tests__/API/E2EFindMemoryLeaks.test.js +72 -0
  10. package/dist/__tests__/API/E2EResultReader.test.d.ts +11 -0
  11. package/dist/__tests__/API/E2EResultReader.test.js +72 -0
  12. package/dist/__tests__/API/E2ERunSingleSnapshot.example.js +11 -12
  13. package/dist/__tests__/API/E2EShapeUnboundGrowthAnalysis.test.js +8 -17
  14. package/dist/__tests__/API/E2EStringAnalysis.test.js +19 -15
  15. package/dist/__tests__/packages/heap-analysis.test.d.ts +11 -0
  16. package/dist/__tests__/packages/heap-analysis.test.js +82 -0
  17. package/dist/index.d.ts +3 -0
  18. package/dist/index.js +11 -2
  19. package/dist/result-reader/BaseResultReader.d.ts +70 -0
  20. package/dist/result-reader/BaseResultReader.js +96 -0
  21. package/dist/result-reader/BrowserInteractionResultReader.d.ts +105 -0
  22. package/dist/result-reader/BrowserInteractionResultReader.js +136 -0
  23. package/package.json +15 -6
  24. package/dist/API.d.ts.map +0 -1
  25. package/dist/__tests__/API/E2EBasicAnalysis.test.d.ts.map +0 -1
  26. package/dist/__tests__/API/E2EDetachedDOMAnalysis.test.d.ts.map +0 -1
  27. package/dist/__tests__/API/E2EDuplicateObjectAnalysis.test.d.ts.map +0 -1
  28. package/dist/__tests__/API/E2ERunMultipleSnapshots.example.d.ts.map +0 -1
  29. package/dist/__tests__/API/E2ERunSingleSnapshot.example.d.ts.map +0 -1
  30. package/dist/__tests__/API/E2EShapeUnboundGrowthAnalysis.test.d.ts.map +0 -1
  31. package/dist/__tests__/API/E2EStringAnalysis.test.d.ts.map +0 -1
  32. package/dist/__tests__/API/lib/E2ETestSettings.d.ts.map +0 -1
  33. package/dist/__tests__/heap/E2EHeapParser.test.d.ts.map +0 -1
  34. package/dist/__tests__/heap/lib/HeapParserTestUtils.d.ts.map +0 -1
  35. package/dist/index.d.ts.map +0 -1
  36. package/dist/lib/APIUtils.d.ts.map +0 -1
@@ -0,0 +1,136 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const core_1 = require("@memlab/core");
16
+ const fs_extra_1 = __importDefault(require("fs-extra"));
17
+ const path_1 = __importDefault(require("path"));
18
+ const BaseResultReader_1 = __importDefault(require("./BaseResultReader"));
19
+ /**
20
+ * A utility entity to read all generated files from
21
+ * the directory holding the data and results from the
22
+ * last browser interaction run
23
+ */
24
+ class BrowserInteractionResultReader extends BaseResultReader_1.default {
25
+ /**
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
+ * @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
+ * ```
39
+ */
40
+ static from(workDir = '') {
41
+ return new BrowserInteractionResultReader(workDir);
42
+ }
43
+ /**
44
+ * get all snapshot files generated from last memlab browser interaction
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
+ * ```
58
+ */
59
+ getSnapshotFiles() {
60
+ this.check();
61
+ const dataDir = this.fileManager.getCurDataDir({ workDir: this.workDir });
62
+ return fs_extra_1.default
63
+ .readdirSync(dataDir)
64
+ .filter(file => file.endsWith('heapsnapshot'))
65
+ .map(file => path_1.default.join(dataDir, file));
66
+ }
67
+ /**
68
+ * get the directory holding all snapshot files
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
+ * ```
82
+ */
83
+ getSnapshotFileDir() {
84
+ this.check();
85
+ return this.fileManager.getCurDataDir({ workDir: this.workDir });
86
+ }
87
+ /**
88
+ * browser interaction step sequence
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
+ * ```
103
+ */
104
+ getInteractionSteps() {
105
+ this.check();
106
+ const metaFile = this.fileManager.getSnapshotSequenceMetaFile({
107
+ workDir: this.workDir,
108
+ });
109
+ return core_1.utils.loadTabsOrder(metaFile);
110
+ }
111
+ /**
112
+ * general meta data of the browser interaction run
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
+ * ```
127
+ */
128
+ getRunMetaInfo() {
129
+ this.check();
130
+ const metaFile = this.fileManager.getRunMetaFile({
131
+ workDir: this.workDir,
132
+ });
133
+ return core_1.utils.loadRunMetaInfo(metaFile);
134
+ }
135
+ }
136
+ exports.default = BrowserInteractionResultReader;
package/package.json CHANGED
@@ -1,13 +1,22 @@
1
1
  {
2
2
  "name": "@memlab/api",
3
- "version": "1.0.0",
4
- "description": "API of memlab",
5
- "keywords": [
6
- "api"
7
- ],
3
+ "version": "1.0.3",
4
+ "license": "MIT",
5
+ "description": "memlab API",
8
6
  "author": "Liang Gong <lgong@fb.com>",
9
7
  "contributors": [],
10
- "license": "MIT",
8
+ "keywords": [
9
+ "memlab",
10
+ "memory",
11
+ "leak",
12
+ "api",
13
+ "e2e",
14
+ "browser",
15
+ "heap",
16
+ "snapshot",
17
+ "analysis",
18
+ "plugin"
19
+ ],
11
20
  "main": "dist/index.js",
12
21
  "types": "dist/index.d.ts",
13
22
  "files": [
package/dist/API.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"API.d.ts","sourceRoot":"","sources":["../src/API.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAC,IAAI,EAAU,MAAM,WAAW,CAAC;AAC7C,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,UAAU,CAAC;AACzC,OA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AAC,OAAO,GAAE,UAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAkD3E"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"E2EBasicAnalysis.test.d.ts","sourceRoot":"","sources":["../../../src/__tests__/API/E2EBasicAnalysis.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"E2EDetachedDOMAnalysis.test.d.ts","sourceRoot":"","sources":["../../../src/__tests__/API/E2EDetachedDOMAnalysis.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"E2EDuplicateObjectAnalysis.test.d.ts","sourceRoot":"","sources":["../../../src/__tests__/API/E2EDuplicateObjectAnalysis.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"E2ERunMultipleSnapshots.example.d.ts","sourceRoot":"","sources":["../../../src/__tests__/API/E2ERunMultipleSnapshots.example.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"E2ERunSingleSnapshot.example.d.ts","sourceRoot":"","sources":["../../../src/__tests__/API/E2ERunSingleSnapshot.example.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"E2EShapeUnboundGrowthAnalysis.test.d.ts","sourceRoot":"","sources":["../../../src/__tests__/API/E2EShapeUnboundGrowthAnalysis.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"E2EStringAnalysis.test.d.ts","sourceRoot":"","sources":["../../../src/__tests__/API/E2EStringAnalysis.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"E2ETestSettings.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/API/lib/E2ETestSettings.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,WAAW,CAAC;AAGpC,eAAO,MAAM,WAAW,QAAgB,CAAC;AAEzC,eAAO,MAAM,mBAAmB;;;;CAAkB,CAAC;AAEnD,eAAO,MAAM,QAAQ;eACV,MAAM;eACN,MAAM;mBACM,IAAI,KAAG,QAAQ,IAAI,CAAC;CAE1C,CAAC;AAEF,eAAO,MAAM,SAAS,QAAO,IAK5B,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"E2EHeapParser.test.d.ts","sourceRoot":"","sources":["../../../src/__tests__/heap/E2EHeapParser.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAC,QAAQ,EAA2B,MAAM,cAAc,CAAC;AAOrE,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,QAAQ,EAAE,QAAQ,CAAC;KACpB;CACF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"HeapParserTestUtils.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/heap/lib/HeapParserTestUtils.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,cAAc,CAAC;AAUhD,wBAAsB,kBAAkB,CACtC,YAAY,EAAE,MAAM,IAAI,EACxB,eAAe,EAAE,CAAC,QAAQ,EAAE,aAAa,KAAK,OAAO,GACpD,OAAO,CAAC,IAAI,CAAC,CAGf"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,cAAc,OAAO,CAAC;AACtB,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAC,MAAM,EAAC,MAAM,cAAc,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"APIUtils.d.ts","sourceRoot":"","sources":["../../src/lib/APIUtils.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AACvC,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,cAAc,CAAC;AAU/C,iBAAe,UAAU,CACvB,OAAO,GAAE;IAAC,MAAM,CAAC,EAAE,YAAY,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAM,GACtD,OAAO,CAAC,OAAO,CAAC,CAmBlB;;;;AAED,wBAEE"}