Skip to content

Commit

Permalink
test(examples): added chalk for logging
Browse files Browse the repository at this point in the history
  • Loading branch information
mgordel committed Sep 20, 2023
1 parent 9098abb commit a8d0632
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions tests/examples/examples.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ChildProcess, spawn } from "child_process";
import { dirname, basename, resolve } from "path";
import { Goth } from "../goth/goth";
import chalk from "chalk";

const gothConfig = resolve("../goth/assets/goth-config.yml");
const goth = new Goth(gothConfig);
Expand Down Expand Up @@ -38,7 +39,7 @@ async function examplesTest(cmd: string, path: string, args: string[] = [], time
spawnedExample.stdout?.setEncoding("utf-8");
const testPromise = new Promise((res, rej) => {
spawnedExample.stdout?.on("data", (data: string) => {
console.log(data.replace("\n", ""));
console.log(chalk.cyanBright("[test]"), data.trim());
if (criticalLogsRegexp.some((regexp) => data.match(regexp))) {
return rej(`Example test "${file}" failed.`);
}
Expand All @@ -56,17 +57,20 @@ async function testAll(examples: Example[]) {
await Promise.race([goth.start(), timeoutPromise(180)]);
for (const example of examples) {
try {
console.log(`\n---- Starting test for example: "${example.path}" ----\n`);
console.log(chalk.yellow(`\n\tStarting test for example: "${example.path}"\n`));
await examplesTest(example.cmd, example.path, example.args);
} catch (error) {
console.error(error);
console.error(chalk.red(error));
failedTests.set(example.path, false);
}
}
await goth.end().catch((error) => console.error(error));
spawnedExamples.forEach((example) => example?.kill());
console.log(
`\n\nTESTS: ${examples.length - failedTests.size} passed, ${failedTests.size} failed, ${examples.length} total`,
chalk.cyan("\n\nTESTS RESULTS: "),
chalk.bgGreen(`${examples.length - failedTests.size} passed`),
chalk.bgRed(`${failedTests.size} failed`),
chalk.bgYellow(`${examples.length} total`),
);
process.exit(failedTests.size > 0 ? 1 : 0);
}
Expand Down

0 comments on commit a8d0632

Please sign in to comment.