Skip to content

Commit

Permalink
feat(api): support getting console backup file from SnapshotResultRea…
Browse files Browse the repository at this point in the history
…der (#115)

Summary: Support getting console backup file from SnapshotResultReader

Differential Revision: D54736039

fbshipit-source-id: b3a78742f45834addadefd1db6147134da3b2473
  • Loading branch information
JacksonGL authored and facebook-github-bot committed Mar 11, 2024
1 parent 941843e commit 19ef63a
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 2 deletions.
29 changes: 29 additions & 0 deletions packages/api/src/result-reader/BaseResultReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,35 @@ export default class BaseResultReader {
return this.workDir;
}

/**
* 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., <code>{@link findLeaks}</code>) 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 the absolute path of the backup file
* * **Examples**:
* ```javascript
* 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();
* })();
* ```
*/
public getConsoleBackupFile(): string {
return this.fileManager.getConsoleBackupFile({workDir: this.workDir});
}

/**
* clean up data/files generated from the memlab browser interaction run
* @returns no return value
Expand Down
8 changes: 7 additions & 1 deletion packages/core/src/lib/FileManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ export class FileManager {
return path.join(this.getDataBaseDir(options), 'cur');
}

public getConsoleBackupFile(
options: FileOption = FileManager.defaultFileOption,
): string {
return path.join(this.getCurDataDir(options), 'console-log.txt');
}

public getWebSourceDir(
options: FileOption = FileManager.defaultFileOption,
): string {
Expand Down Expand Up @@ -633,7 +639,7 @@ export class FileManager {
);

// register the default log file
config.consoleLogFile = path.join(config.curDataDir, 'console-log.txt');
config.consoleLogFile = this.getConsoleBackupFile(options);
info.registerLogFile(config.consoleLogFile);

config.runMetaFile = this.getRunMetaFile(options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,38 @@ const {takeSnapshots} = require('@memlab/api');
```

* **Source**:
* api/src/result-reader/BaseResultReader.ts:93
* api/src/result-reader/BaseResultReader.ts:122

___

### <a id="getconsolebackupfile"></a>**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., <code>[findLeaks](../modules/api_src.md#findleaks)</code>) 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**:
```javascript
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();
})();
```

* **Source**:
* api/src/result-reader/BaseResultReader.ts:102

___

Expand Down
31 changes: 31 additions & 0 deletions website/docs/api/classes/api_src.SnapshotResultReader.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,37 @@ const leaks = await findLeaks(reader);

## Methods

### <a id="getconsolebackupfile"></a>**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., <code>[findLeaks](../modules/api_src.md#findleaks)</code>) 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**:
```javascript
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();
})();
```

* **Source**:
* api/src/result-reader/BaseResultReader.ts:102

___

### <a id="getinteractionsteps"></a>**getInteractionSteps**()

browser interaction step sequence
Expand Down

0 comments on commit 19ef63a

Please sign in to comment.