Skip to content

Commit

Permalink
test: removed wtf-node
Browse files Browse the repository at this point in the history
  • Loading branch information
mgordel committed Sep 6, 2024
1 parent 2862647 commit 5b2a67d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 46 deletions.
19 changes: 1 addition & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@
"@types/tmp": "^0.2.6",
"@types/uuid": "^10.0.0",
"@types/ws": "^8.5.10",
"@types/wtfnode": "^0.7.3",
"@typescript-eslint/eslint-plugin": "^7.1.0",
"@typescript-eslint/parser": "^7.1.0",
"buffer": "^6.0.3",
Expand Down Expand Up @@ -136,8 +135,7 @@
"typedoc-plugin-markdown": "^3.17.1",
"typedoc-plugin-merge-modules": "^5.1.0",
"typedoc-theme-hierarchy": "4.1.2",
"typescript": "^5.3.3",
"wtfnode": "^0.9.3"
"typescript": "^5.3.3"
},
"optionalDependencies": {
"@rollup/rollup-darwin-x64": "^4",
Expand Down
4 changes: 0 additions & 4 deletions src/golem-network/golem-network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import { DataTransferProtocol } from "../shared/types";
import { NetworkApiAdapter } from "../shared/yagna/adapters/network-api-adapter";
import { IProposalRepository } from "../market/proposal";
import { Subscription } from "rxjs";
import * as wtf from "wtfnode";

/**
* Instance of an object or a factory function that you can call `new` on.
Expand Down Expand Up @@ -354,9 +353,6 @@ export class GolemNetwork {
} finally {
this.events.emit("disconnected");
this.hasConnection = false;
setTimeout(() => {
wtf.dump();
}, 20_000);
}
}

Expand Down
37 changes: 16 additions & 21 deletions tests/examples/examples.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { spawn } from "child_process";
import { dirname, basename, resolve } from "path";
import chalk from "chalk";
import testExamples from "./examples.json";
import * as wtf from "wtfnode";
const criticalLogsRegExp = [
/GolemInternalError/,
/GolemPlatformError/,
Expand All @@ -25,7 +24,7 @@ async function test(cmd: string, path: string, args: string[] = [], timeout = 36
const file = basename(path);
const cwd = dirname(path);
const env = { ...process.env, DEBUG: "golem-js:*" };
const spawnedExample = spawn(cmd, [file, ...args], { cwd, env });
const spawnedExample = spawn(cmd, [file, ...args], { cwd, env, stdio: ["ignore", "pipe", "pipe"] });
spawnedExample.stdout?.setEncoding("utf-8");
spawnedExample.stderr?.setEncoding("utf-8");
let error = "";
Expand All @@ -34,43 +33,39 @@ async function test(cmd: string, path: string, args: string[] = [], timeout = 36
spawnedExample.kill();
}, timeout * 1000);
return new Promise((res, rej) => {
const assertLogs = (data: string) => {
console.log(data.trim());
const logWithoutColors = data.replace(
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,
"",
);
if (criticalLogsRegExp.some((regexp) => logWithoutColors.match(regexp))) {
error = `A critical error occurred during the test. ${logWithoutColors}`;
spawnedExample.kill();
}
};
spawnedExample.stdout?.on("data", assertLogs);
spawnedExample.stderr?.on("data", assertLogs);
let isFinishing = false;
const finishTest = (code?: number, signal?: string) => {
console.log("FINISH TEST", { isFinishing, code, signal, error });
if (isFinishing) {
console.log("Test finishing has already been triggered by another event");
return;
}
console.log(`Subprocess with test ${file} exited with code ${code} by signal ${signal}`);
isFinishing = true;
spawnedExample.removeAllListeners();
spawnedExample.stdout.removeAllListeners();
spawnedExample.stderr.removeAllListeners();
clearTimeout(timeoutId);
setTimeout(() => {
wtf.dump();
}, 20_000);
if (!error && !code) return res(true);
rej(`Test example "${file}" failed. Exited with code ${code} by signal ${signal}. ${error}`);
rej(`Test example "${file}" failed. ${error}`);
};
spawnedExample.on("close", finishTest);
spawnedExample.on("exit", finishTest);
spawnedExample.on("error", (err) => {
error = `The test ended with an error: ${err}`;
spawnedExample.kill();
});
const assertLogs = (data: string) => {
console.log(data.trim());
const logWithoutColors = data.replace(
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,
"",
);
if (criticalLogsRegExp.some((regexp) => logWithoutColors.match(regexp))) {
error = `A critical error occurred during the test. ${logWithoutColors}`;
spawnedExample.kill();
}
};
spawnedExample.stdout?.on("data", assertLogs);
spawnedExample.stderr?.on("data", assertLogs);
}).finally(() => {
clearTimeout(timeoutId);
spawnedExample.kill("SIGKILL");
Expand Down

0 comments on commit 5b2a67d

Please sign in to comment.