Skip to main content

Class: BrowserInteractionResultReader

Defined in: api/src/result-reader/BrowserInteractionResultReader.ts:23

A utility entity to read all generated files from the directory holding the data and results from the last MemLab browser interaction run

Extends

  • default

Methods

cleanup()

cleanup(): void

Defined in: api/src/result-reader/BaseResultReader.ts:122

clean up data/files generated from the memlab browser interaction run

Returns

void

no return value

  • Examples:
const {takeSnapshots} = require('@memlab/api');

(async function () {
const scenario = { url: () => 'https://www.npmjs.com'};
const result = await takeSnapshots({scenario});

// delete all data/files generated by takeSnapshots
result.cleanup();
})();

Inherited from

BaseResultReader.cleanup


getConsoleBackupFile()

getConsoleBackupFile(): string

Defined in: api/src/result-reader/BaseResultReader.ts:102

This method gets the backup file of the console output.

The memlab CLI commands (e.g., memlab find-leaks) outputs a non-structured string representation for easy reading, while the APIs (e.g., findLeaks) return structured leaks representation that is handy for post-processing. If you need to obtain all the string output from the CLI in the current working directory, you can read them from the CLI output backup file returned by this method.

Returns

string

the absolute path of the backup file

  • Examples:
const {takeSnapshots, findLeaks} = require('@memlab/api');

(async function () {
const scenario = { url: () => 'https://www.npmjs.com'};
const result = await takeSnapshots({scenario});
const leaks = await findLeaks(result);

// get the console output backup file
const consoleBackupFile = result.getConsoleBackupFile();
})();

Inherited from

BaseResultReader.getConsoleBackupFile


getInteractionSteps()

getInteractionSteps(): E2EStepInfo[]

Defined in: api/src/result-reader/BrowserInteractionResultReader.ts:106

browser interaction step sequence

Returns

E2EStepInfo[]

an array of browser interaction step information

  • Examples:
const {takeSnapshots} = require('@memlab/api');

(async function () {
const scenario = { url: () => 'https://www.npmjs.com'};
const result = await takeSnapshots({scenario});

const steps = result.getInteractionSteps();
// print each browser interaction's name and JavaScript heap size (in bytes)
steps.forEach(step => console.log(step.name, step.JSHeapUsedSize))
})();

getRootDirectory()

getRootDirectory(): string

Defined in: api/src/result-reader/BaseResultReader.ts:72

get the directory where the data and generated files of the memlab run were stored

Returns

string

absolute path of the directory

  • Examples:
const {takeSnapshots} = require('@memlab/api');

(async function () {
const scenario = { url: () => 'https://www.npmjs.com'};
const result = await takeSnapshots({scenario});

// get the directory that stores all the files
// generated from the takeSnapshots call
const dataDir = result.getRootDirectory();
})();

Inherited from

BaseResultReader.getRootDirectory


getRunMetaInfo()

getRunMetaInfo(): RunMetaInfo

Defined in: api/src/result-reader/BrowserInteractionResultReader.ts:131

general meta data of the browser interaction run

Returns

RunMetaInfo

meta data about the entire browser interaction

  • Examples:
const {takeSnapshots} = require('@memlab/api');

(async function () {
const scenario = { url: () => 'https://www.npmjs.com'};
const result = await takeSnapshots({scenario});

const metaInfo = result.getRunMetaInfo();
// print all browser web console output
console.log(metaInfo.browserInfo._consoleMessages.join('\n'));
})();

getSnapshotFileDir()

getSnapshotFileDir(): string

Defined in: api/src/result-reader/BrowserInteractionResultReader.ts:84

get the directory holding all snapshot files

Returns

string

the absolute path of the directory

  • Examples:
const {takeSnapshots} = require('@memlab/api');

(async function () {
const scenario = { url: () => 'https://www.npmjs.com'};
const result = await takeSnapshots({scenario});

// get the absolute path the directory holding all snapshot files
const files = result.getSnapshotFileDir();
})();

getSnapshotFiles()

getSnapshotFiles(): string[]

Defined in: api/src/result-reader/BrowserInteractionResultReader.ts:59

get all snapshot files generated from last memlab browser interaction

Returns

string[]

an array of snapshot file's absolute path

  • Examples:
const {takeSnapshots} = require('@memlab/api');

(async function () {
const scenario = { url: () => 'https://www.npmjs.com'};
const result = await takeSnapshots({scenario});

// get absolute paths of all snapshot files
const files = result.getSnapshotFiles();
})();

from()

static from(workDir?): BrowserInteractionResultReader

Defined in: api/src/result-reader/BrowserInteractionResultReader.ts:39

build a result reader from a data directory where the data and generated files of a memlab run were stored

Parameters

workDir?

string = ''

absolute path of the data directory

Returns

BrowserInteractionResultReader

the ResultReader instance

  • Examples:
const {BrowserInteractionResultReader} = require('@memlab/api');

const dataDir = '/tmp/memlab'; // where the last memlab run stores results
const reader = BrowserInteractionResultReader.from(dataDir);
reader.cleanup(); // clean up the results

Overrides

BaseResultReader.from