Package: @memlab/api
Enumerations
Classes
Type Aliases
RunOptions: Object
Options for configuring browser interaction run, all fields are optional
Name | Type | Description |
---|---|---|
chromiumBinary? | string | if not specified, memlab will use the Chromium binary installed by Puppeteer. Use this option to specify a different binary if Puppeteer does not install the Chromium binary correctly (e.g., in a environtment Docker) or when you may want to use a different version of Chromium binary. |
consoleMode? | ConsoleMode | specifying the terminal output mode, default is default . For more details. please check out ConsoleMode |
cookiesFile? | string | the absolute path of cookies file |
evalInBrowserAfterInitLoad? | AnyFunction | function to be evaluated in browser context after the web page initial load. Note that this function is defined in node.js context but it will be evaluated in browser context so the function should not use any closure variables outside of the browser context. |
scenario? | IScenario | test scenario specifying how to interact with browser (for more details view IScenario) |
skipWarmup? | boolean | skip the initial page loading warmup for the web application being tested |
snapshotForEachStep? | boolean | if true, take heap snapshot for each interaction step, by default this is false, which means memlab will decide which steps it will take heap snapshots |
webWorker? | Optional <string > | if this field is provided, it specifies the web worker as the target for heap analysis. For example {webWorker: null} means analyzing the heap of the first web worker found. {webWorker: 'workerTitle'} means analyzing the heap of the web worker with name: 'workerTitle' . |
workDir? | string | specify the working directory where you want memlab to dump heap snapshots and other meta data of the test run. If no working directory is provided, memlab will generate a random temp directory under the operating system's default directory for temporary files. Note: It's the caller's responsibility to make sure the specified working directory exists. |
- Source:
RunResult: Object
A data structure holding the result of the run API call.
Name | Type | Description |
---|---|---|
leaks | ISerializedInfo [] | leak traces detected and clustered from the browser interaction |
runResult | BrowserInteractionResultReader | a utility for reading browser interaction results from disk |
- Source:
Functions
analyze(runResult
, heapAnalyzer
, args?
)
This API analyzes heap snapshot(s) with a specified heap analysis.
This is equivalent to memlab analyze
in CLI.
- Parameters:
runResult
:default
| return value of a browser interaction runheapAnalyzer
:BaseAnalysis
| instance of a heap analysisargs
:ParsedArgs
| other CLI arguments that needs to be passed to the heap analysis
- Returns:
Promise
<void
> | each analysis may have a different return type, please check out the type definition or the documentation for theprocess
method of the analysis class you are using forheapAnalyzer
. - Examples:
const {analyze, takeSnapshots, StringAnalysis} = require('@memlab/api');
(async function () {
const scenario = {
url: () => 'https://www.facebook.com',
};
const result = await takeSnapshots({scenario});
const analysis = new StringAnalysis();
await analyze(result, analysis);
})();
- Source:
findLeaks(runResult
, options?
)
This API finds memory leaks by analyzing heap snapshot(s).
This is equivalent to memlab find-leaks
in CLI.
- Parameters:
runResult
:default
| return value of a browser interaction runoptions
:Object
| configure memory leak detection runoptions.consoleMode?
:ConsoleMode
| specify the terminal output mode (see ConsoleMode)
- Returns:
Promise
<ISerializedInfo
[]> | leak traces detected and clustered from the browser interaction - Examples:
const {findLeaks, takeSnapshots} = require('@memlab/api');
(async function () {
const scenario = {
url: () => 'https://www.facebook.com',
};
const result = await takeSnapshots({scenario, consoleMode: 'SILENT'});
const leaks = findLeaks(result, {consoleMode: 'CONTINUOUS_TEST'});
})();
- Source:
findLeaksBySnapshotFilePaths(baselineSnapshot
, targetSnapshot
, finalSnapshot
, options?
)
This API finds memory leaks by analyzing specified heap snapshots.
This is equivalent to memlab find-leaks
with
the --baseline
, --target
, and --final
flags in CLI.
Parameters:
baselineSnapshot
:string
| the file path of the baseline heap snapshottargetSnapshot
:string
| the file path of the target heap snapshotfinalSnapshot
:string
| the file path of the final heap snapshotoptions
:Object
| optionally, you can specify a mode for heap analysisoptions.consoleMode?
:ConsoleMode
| specify the terminal output mode (see ConsoleMode)options.workDir?
:string
| specify a working directory (other than the default one)
Returns:
Promise
<ISerializedInfo
[]> | leak traces detected and clustered from the browser interactionSource:
run(options?
)
This API runs browser interaction and find memory leaks triggered in browser
This is equivalent to running memlab run
in CLI.
This is also equivalent to warm up, and call takeSnapshots
and findLeaks.
- Parameters:
options
:RunOptions
- Returns:
Promise
<RunResult
> | memory leaks detected and a utility reading browser interaction results from disk - Examples:
const {run} = require('@memlab/api');
(async function () {
const scenario = {
url: () => 'https://www.facebook.com',
};
const {leaks} = await run({scenario});
})();
- Source:
takeSnapshots(options?
)
This API runs E2E interaction and takes heap snapshots.
This is equivalent to running memlab snapshot
in CLI.
- Parameters:
options
:RunOptions
| configure browser interaction run
- Returns:
Promise
<BrowserInteractionResultReader
> | a utility reading browser interaction results from disk - Examples:
const {takeSnapshots} = require('@memlab/api');
(async function () {
const scenario = {
url: () => 'https://www.facebook.com',
};
const result = await takeSnapshots({scenario});
})();
- Source:
warmupAndTakeSnapshots(options?
)
This API warms up web server, runs E2E interaction, and takes heap snapshots.
This is equivalent to running memlab warmup-and-snapshot
in CLI.
This is also equivalent to warm up and call takeSnapshots.
- Parameters:
options
:RunOptions
| configure browser interaction run
- Returns:
Promise
<BrowserInteractionResultReader
> | browser interaction results - Examples:
const {warmupAndTakeSnapshots} = require('@memlab/api');
(async function () {
const scenario = {
url: () => 'https://www.facebook.com',
};
const result = await warmupAndTakeSnapshots({scenario});
})();
- Source: