Skip to main content

Class: BrowserInteractionResultReader

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

Hierarchy

  • default

    BrowserInteractionResultReader

Methods

cleanup()

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();
})();

getConsoleBackupFile()

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();
})();

getInteractionSteps()

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()

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();
})();

getRunMetaInfo()

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()

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()

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();
})();

Static from(workDir?)

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

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
  • Hierarchy
  • Methods
    • cleanup()
    • getConsoleBackupFile()
    • getInteractionSteps()
    • getRootDirectory()
    • getRunMetaInfo()
    • getSnapshotFileDir()
    • getSnapshotFiles()
    • Static from(workDir?)