Danish Arora 4eb06c64eb
feat(filter)!: return error codes instead of throwing errors (#1971)
* move protocol result type to interfaces

* chore: update type names for verbosity

* feat(filter-core): convert error throws to return types

* chore: update types & imports

* update Filter API

* chore: update createSubscription

* chore: update imports & rename

* chore: update all tests

* chore: resolve conflicts & merge (2/n)

* chore: resolve conflicts & merge (3/n)

* chore: resolve conflicts & merge (4/n)

* chore: resolve conflicts & merge (5/n)

* chore: resolve conflicts & merge (6/n)

* chore: use idiomatic approach

* chore: fix tests

* chore: address comments

* chore: fix test

* rm: only
2024-05-09 16:51:08 +05:30

67 lines
1.4 KiB
TypeScript

/**
* Utilities to make it help check nwaku logs.
*
* @hidden
* @module
*/
import { Context } from "mocha";
import pTimeout from "p-timeout";
import { Tail } from "tail";
import { waitForFile } from "./async_fs.js";
export default async function waitForLine(
filepath: string,
logLine: string,
timeout: number
): Promise<void> {
await pTimeout(waitForFile(filepath), { milliseconds: timeout });
const options = {
fromBeginning: true,
follow: true
};
const tail = new Tail(filepath, options);
await pTimeout(find(tail, logLine), {
milliseconds: 60000,
message: `could not to find '${logLine}' in file '${filepath}'`
});
tail.unwatch();
}
async function find(tail: Tail, line: string): Promise<string> {
return new Promise((resolve, reject) => {
tail.on("line", (data: string) => {
if (data.includes(line)) {
resolve(data);
}
});
tail.on("error", (err) => {
reject(err);
});
});
}
function clean(str: string): string {
return str.replace(/ /g, "_").replace(/[':()/]/g, "");
}
export function makeLogFileName(ctx: Context | undefined): string {
if (!ctx) {
return "unknown";
}
const unitTest = ctx.currentTest ? ctx.currentTest : ctx.test;
let name = clean(unitTest!.title);
let suite = unitTest?.parent;
while (suite && suite.title) {
name = clean(suite.title) + "_" + name;
suite = suite.parent;
}
return name;
}