@memlab/api 1.0.10 → 1.0.12
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/LICENSE +21 -0
- package/dist/API.js +1 -1
- package/dist/__tests__/API/E2EInjectLeaksWithSetup.test.d.ts +11 -0
- package/dist/__tests__/API/E2EInjectLeaksWithSetup.test.js +89 -0
- package/dist/__tests__/API/E2EReloadInSetup.test.d.ts +11 -0
- package/dist/__tests__/API/E2EReloadInSetup.test.js +39 -0
- package/package.json +6 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/API.js
CHANGED
|
@@ -250,7 +250,7 @@ function setupPage(page, options = {}) {
|
|
|
250
250
|
if (config.emulateDevice) {
|
|
251
251
|
yield page.emulate(config.emulateDevice);
|
|
252
252
|
}
|
|
253
|
-
if (config.defaultUserAgent) {
|
|
253
|
+
if (config.defaultUserAgent && config.defaultUserAgent !== 'default') {
|
|
254
254
|
yield page.setUserAgent(config.defaultUserAgent);
|
|
255
255
|
}
|
|
256
256
|
// set login session
|
|
@@ -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
|
+
* @format
|
|
8
|
+
* @oncall ws_labs
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=E2EInjectLeaksWithSetup.test.d.ts.map
|
|
@@ -0,0 +1,89 @@
|
|
|
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
|
+
* @format
|
|
9
|
+
* @oncall ws_labs
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
21
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
22
|
+
};
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
const os_1 = __importDefault(require("os"));
|
|
25
|
+
const path_1 = __importDefault(require("path"));
|
|
26
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
27
|
+
const index_1 = require("../../index");
|
|
28
|
+
const E2ETestSettings_1 = require("./lib/E2ETestSettings");
|
|
29
|
+
beforeEach(E2ETestSettings_1.testSetup);
|
|
30
|
+
// This test uses scenario.setup callback
|
|
31
|
+
// to set window.injectHookForLink4
|
|
32
|
+
// which injects memory leaks.
|
|
33
|
+
// The following test cases will check
|
|
34
|
+
// if MemLab can detect the injected memory leaks.
|
|
35
|
+
const setup = (page) => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
+
page.evaluate(() => {
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
window.injectHookForLink4 = () => {
|
|
39
|
+
class TestObject {
|
|
40
|
+
}
|
|
41
|
+
const arr = [];
|
|
42
|
+
for (let i = 0; i < 23; ++i) {
|
|
43
|
+
arr.push(document.createElement('div'));
|
|
44
|
+
}
|
|
45
|
+
// @ts-ignore
|
|
46
|
+
window.__injectedValue = arr;
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
window._path_1 = { x: { y: document.createElement('div') } };
|
|
49
|
+
// @ts-ignore
|
|
50
|
+
window._path_2 = new Set([document.createElement('div')]);
|
|
51
|
+
// @ts-ignore
|
|
52
|
+
window._randomObject = [new TestObject()];
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
test('leak detector can find detached DOM elements', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
57
|
+
const { leaks } = yield (0, index_1.run)({
|
|
58
|
+
scenario: Object.assign(Object.assign({}, E2ETestSettings_1.scenario), { setup }),
|
|
59
|
+
});
|
|
60
|
+
// detected all different leak trace cluster
|
|
61
|
+
expect(leaks.length >= 1).toBe(true);
|
|
62
|
+
// expect all traces are found
|
|
63
|
+
expect(leaks.some(leak => JSON.stringify(leak).includes('__injectedValue')));
|
|
64
|
+
expect(leaks.some(leak => JSON.stringify(leak).includes('_path_1')));
|
|
65
|
+
expect(leaks.some(leak => JSON.stringify(leak).includes('_path_2')));
|
|
66
|
+
}), E2ETestSettings_1.testTimeout);
|
|
67
|
+
test('self-defined leak detector can find TestObject', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
68
|
+
const selfDefinedScenario = {
|
|
69
|
+
app: () => 'test-spa',
|
|
70
|
+
url: () => '',
|
|
71
|
+
action: (page) => __awaiter(void 0, void 0, void 0, function* () { return yield page.click('[data-testid="link-4"]'); }),
|
|
72
|
+
leakFilter: (node) => {
|
|
73
|
+
return node.name === 'TestObject' && node.type === 'object';
|
|
74
|
+
},
|
|
75
|
+
setup,
|
|
76
|
+
};
|
|
77
|
+
const workDir = path_1.default.join(os_1.default.tmpdir(), 'memlab-api-test', `${process.pid}`);
|
|
78
|
+
fs_extra_1.default.mkdirsSync(workDir);
|
|
79
|
+
const result = yield (0, index_1.run)({
|
|
80
|
+
scenario: selfDefinedScenario,
|
|
81
|
+
workDir,
|
|
82
|
+
});
|
|
83
|
+
// detected all different leak trace cluster
|
|
84
|
+
expect(result.leaks.length).toBe(1);
|
|
85
|
+
// expect all traces are found
|
|
86
|
+
expect(result.leaks.some(leak => JSON.stringify(leak).includes('_randomObject')));
|
|
87
|
+
const reader = result.runResult;
|
|
88
|
+
expect(path_1.default.resolve(reader.getRootDirectory())).toBe(path_1.default.resolve(workDir));
|
|
89
|
+
}), E2ETestSettings_1.testTimeout);
|
|
@@ -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
|
+
* @format
|
|
8
|
+
* @oncall ws_labs
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=E2EReloadInSetup.test.d.ts.map
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
* @format
|
|
9
|
+
* @oncall ws_labs
|
|
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 index_1 = require("../../index");
|
|
22
|
+
const E2ETestSettings_1 = require("./lib/E2ETestSettings");
|
|
23
|
+
beforeEach(E2ETestSettings_1.testSetup);
|
|
24
|
+
// clear the page reload check in setup
|
|
25
|
+
// to check that the page reload check should
|
|
26
|
+
// be injected after the setup callback
|
|
27
|
+
const setup = (page) => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
+
yield page.evaluate(() => {
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
delete window.__memlab_check_reload;
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
test('reload in setup is fine', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
const { leaks } = yield (0, index_1.run)({
|
|
35
|
+
scenario: Object.assign(Object.assign({}, E2ETestSettings_1.scenario), { setup }),
|
|
36
|
+
});
|
|
37
|
+
// no memory leaks are detected
|
|
38
|
+
expect(leaks.length).toBe(0);
|
|
39
|
+
}), E2ETestSettings_1.testTimeout);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memlab/api",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "memlab API",
|
|
6
6
|
"author": "Liang Gong <lgong@fb.com>",
|
|
@@ -20,15 +20,16 @@
|
|
|
20
20
|
"main": "dist/index.js",
|
|
21
21
|
"types": "dist/index.d.ts",
|
|
22
22
|
"files": [
|
|
23
|
-
"dist"
|
|
23
|
+
"dist",
|
|
24
|
+
"LICENSE"
|
|
24
25
|
],
|
|
25
26
|
"publishConfig": {
|
|
26
27
|
"access": "public"
|
|
27
28
|
},
|
|
28
29
|
"dependencies": {
|
|
29
|
-
"@memlab/core": "^1.1.
|
|
30
|
-
"@memlab/e2e": "^1.0.
|
|
31
|
-
"@memlab/heap-analysis": "^1.0.
|
|
30
|
+
"@memlab/core": "^1.1.10",
|
|
31
|
+
"@memlab/e2e": "^1.0.9",
|
|
32
|
+
"@memlab/heap-analysis": "^1.0.7",
|
|
32
33
|
"ansi": "^0.3.1",
|
|
33
34
|
"babar": "^0.2.0",
|
|
34
35
|
"chalk": "^4.0.0",
|