Skip to content

Commit

Permalink
fix(plugin): clear entries on recordHar (#50)
Browse files Browse the repository at this point in the history
fixes #42
  • Loading branch information
derevnjuk authored Apr 4, 2021
1 parent 5613f63 commit 86ca1d6
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/Plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ export class Plugin {
new RetryStrategy(20, 5, 100)
);

this.entries = [];

await this.connection.open();

await this.listenNetworkEvents(options);
Expand All @@ -74,8 +76,11 @@ export class Plugin {

try {
await this.fileManager.createFolder(options.outDir);
const har: string = this.buildHar();
await this.fileManager.writeFile(filePath, har);
const har: string | undefined = this.buildHar();

if (har) {
await this.fileManager.writeFile(filePath, har);
}
} catch (e) {
this.logger.err(`Failed to save HAR: ${e.message}`);
} finally {
Expand All @@ -85,10 +90,12 @@ export class Plugin {
return null;
}

private buildHar(): string {
const har: Har = new HarBuilder(this.entries).build();
private buildHar(): string | undefined {
if (this.entries.length) {
const har: Har = new HarBuilder(this.entries).build();

return JSON.stringify(har, null, 2);
return JSON.stringify(har, null, 2);
}
}

private async listenNetworkEvents(options: RecordOptions): Promise<void> {
Expand Down

0 comments on commit 86ca1d6

Please sign in to comment.