diff --git a/packages/api/src/result-reader/BaseResultReader.ts b/packages/api/src/result-reader/BaseResultReader.ts
index 126bf3ac8..77bc24177 100644
--- a/packages/api/src/result-reader/BaseResultReader.ts
+++ b/packages/api/src/result-reader/BaseResultReader.ts
@@ -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., {@link 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 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
diff --git a/packages/core/src/lib/FileManager.ts b/packages/core/src/lib/FileManager.ts
index 04f091b17..ea397ccf7 100644
--- a/packages/core/src/lib/FileManager.ts
+++ b/packages/core/src/lib/FileManager.ts
@@ -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 {
@@ -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);
diff --git a/website/docs/api/classes/api_src.BrowserInteractionResultReader.md b/website/docs/api/classes/api_src.BrowserInteractionResultReader.md
index 096e0ac87..4000944c3 100644
--- a/website/docs/api/classes/api_src.BrowserInteractionResultReader.md
+++ b/website/docs/api/classes/api_src.BrowserInteractionResultReader.md
@@ -36,7 +36,38 @@ const {takeSnapshots} = require('@memlab/api');
```
* **Source**:
- * api/src/result-reader/BaseResultReader.ts:93
+ * api/src/result-reader/BaseResultReader.ts:122
+
+___
+
+### **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](../modules/api_src.md#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**:
+```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
___
diff --git a/website/docs/api/classes/api_src.SnapshotResultReader.md b/website/docs/api/classes/api_src.SnapshotResultReader.md
index 06a3558af..f21ba22b7 100644
--- a/website/docs/api/classes/api_src.SnapshotResultReader.md
+++ b/website/docs/api/classes/api_src.SnapshotResultReader.md
@@ -29,6 +29,37 @@ const leaks = await findLeaks(reader);
## Methods
+### **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](../modules/api_src.md#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**:
+```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
+
+___
+
### **getInteractionSteps**()
browser interaction step sequence