@memlab/api 1.0.19 → 1.0.20

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/dist/API.d.ts CHANGED
@@ -8,7 +8,7 @@
8
8
  * @oncall web_perf_infra
9
9
  */
10
10
  import type { ParsedArgs } from 'minimist';
11
- import type { AnyFunction, ISerializedInfo, IScenario } from '@memlab/core';
11
+ import type { AnyFunction, ISerializedInfo, IScenario, Optional } from '@memlab/core';
12
12
  import { MemLabConfig } from '@memlab/core';
13
13
  import { TestPlanner } from '@memlab/e2e';
14
14
  import { BaseAnalysis } from '@memlab/heap-analysis';
@@ -45,6 +45,13 @@ export declare type RunOptions = {
45
45
  * specified working directory exists.
46
46
  */
47
47
  workDir?: string;
48
+ /**
49
+ * if this field is provided, it specifies the web worker as the target
50
+ * for heap analysis. For example `{webWorker: null}` means analyzing
51
+ * the heap of the first web worker found. `{webWorker: 'workerTitle'}`
52
+ * means analyzing the heap of the web worker with name: `'workerTitle'`.
53
+ */
54
+ webWorker?: Optional<string>;
48
55
  };
49
56
  /**
50
57
  * A data structure holding the result of the {@link run} API call.
package/dist/API.js CHANGED
@@ -215,7 +215,7 @@ function warmup(options = {}) {
215
215
  core_1.info.beginSection('warmup');
216
216
  yield Promise.all(pages.map((page) => __awaiter(this, void 0, void 0, function* () {
217
217
  yield setupPage(page, { cache: false });
218
- const interactionManager = new e2e_1.E2EInteractionManager(page);
218
+ const interactionManager = new e2e_1.E2EInteractionManager(page, browser);
219
219
  yield interactionManager.warmupInPage();
220
220
  }))).catch(err => {
221
221
  core_1.info.error(err.message);
@@ -239,6 +239,16 @@ function getConfigFromRunOptions(options) {
239
239
  else {
240
240
  config = core_1.MemLabConfig.resetConfigWithTransientDir();
241
241
  }
242
+ if ('webWorker' in options) {
243
+ config.isAnalyzingMainThread = false;
244
+ const value = options.webWorker;
245
+ if (typeof value === 'string') {
246
+ config.targetWorkerTitle = value;
247
+ }
248
+ }
249
+ else {
250
+ config.isAnalyzingMainThread = true;
251
+ }
242
252
  config.isFullRun = !!options.snapshotForEachStep;
243
253
  return config;
244
254
  }
@@ -304,7 +314,7 @@ function testInBrowser(options = {}) {
304
314
  const browser = yield APIUtils_1.default.getBrowser();
305
315
  const pages = yield browser.pages();
306
316
  const page = pages.length > 0 ? pages[0] : yield browser.newPage();
307
- interactionManager = new e2e_1.E2EInteractionManager(page);
317
+ interactionManager = new e2e_1.E2EInteractionManager(page, browser);
308
318
  if (options.evalInBrowserAfterInitLoad) {
309
319
  interactionManager.setEvalFuncAfterInitLoad(options.evalInBrowserAfterInitLoad);
310
320
  }
@@ -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 web_perf_infra
9
+ */
10
+ export {};
11
+ //# sourceMappingURL=E2EFindWebWorkerLeaks.test.d.ts.map
@@ -0,0 +1,69 @@
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 web_perf_infra
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
+ test('self-defined leak detector can find Web Worker TestObject (in initial load)', () => __awaiter(void 0, void 0, void 0, function* () {
25
+ const selfDefinedScenario = {
26
+ app: () => 'test-spa',
27
+ url: () => '',
28
+ leakFilter: (node) => {
29
+ return node.name === 'WorkerTestObject' && node.type === 'object';
30
+ },
31
+ };
32
+ const result = yield (0, index_1.run)({
33
+ scenario: selfDefinedScenario,
34
+ webWorker: null,
35
+ });
36
+ // detected all different leak trace cluster
37
+ expect(result.leaks.length).toBe(1);
38
+ }), E2ETestSettings_1.testTimeout);
39
+ test('self-defined leak detector can find Web Worker TestObject with specified worker name (in initial load)', () => __awaiter(void 0, void 0, void 0, function* () {
40
+ const selfDefinedScenario = {
41
+ app: () => 'test-spa',
42
+ url: () => '',
43
+ leakFilter: (node) => {
44
+ return node.name === 'WorkerTestObject' && node.type === 'object';
45
+ },
46
+ };
47
+ const result = yield (0, index_1.run)({
48
+ scenario: selfDefinedScenario,
49
+ webWorker: 'test-worker',
50
+ });
51
+ // detected all different leak trace cluster
52
+ expect(result.leaks.length).toBe(1);
53
+ }), E2ETestSettings_1.testTimeout);
54
+ test('self-defined leak detector can find Web Worker TestObject (during interaction)', () => __awaiter(void 0, void 0, void 0, function* () {
55
+ const selfDefinedScenario = {
56
+ app: () => 'test-spa',
57
+ url: () => '',
58
+ action: (page) => __awaiter(void 0, void 0, void 0, function* () { return yield page.click('[data-testid="link-4"]'); }),
59
+ leakFilter: (node) => {
60
+ return node.name === 'WorkerTestObject' && node.type === 'object';
61
+ },
62
+ };
63
+ const result = yield (0, index_1.run)({
64
+ scenario: selfDefinedScenario,
65
+ webWorker: null,
66
+ });
67
+ // detected all different leak trace cluster
68
+ expect(result.leaks.length).toBe(1);
69
+ }), E2ETestSettings_1.testTimeout);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@memlab/api",
3
- "version": "1.0.19",
3
+ "version": "1.0.20",
4
4
  "license": "MIT",
5
5
  "description": "memlab API",
6
6
  "author": "Liang Gong <lgong@fb.com>",