Skip to content

Commit

Permalink
fixed test reporting logic
Browse files Browse the repository at this point in the history
  • Loading branch information
timbrinded committed Nov 16, 2023
1 parent bead373 commit 38842bc
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 29 deletions.
56 changes: 29 additions & 27 deletions packages/cli/src/cmds/entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { runNetworkCmd } from "./runNetwork";
import { generateConfig } from "../internal/cmdFunctions/initialisation";
import { fetchArtifact } from "../internal/cmdFunctions/fetchArtifact";
import dotenv from "dotenv";
import { Effect, Console, pipe } from "effect";
import { Effect, pipe } from "effect";
import { main } from "./main";
dotenv.config();

Expand Down Expand Up @@ -38,13 +38,19 @@ const parseConfigFile = Effect.sync(() =>
.parseSync()
);

const setEnvVar = (key: string, value: string) => Effect.sync(() => (process.env[key] = value));
const setEnvVar = (key: string, value: string) =>
Effect.sync(() => {
process.env[key] = value;
});

const setupConfigFileEnv = pipe(
parseConfigFile,
Effect.flatMap((parsed) => setEnvVar("MOON_CONFIG_PATH", parsed.configFile))
);

// TODO: REMOVE THIS HACK ONCE YARGS REPLACED
let failedTests: number | false;

const cliStart = Effect.try(() => {
const argv = yargs(hideBin(process.argv))
.usage("Usage: $0")
Expand Down Expand Up @@ -131,27 +137,27 @@ const cliStart = Effect.try(() => {
async ({ envName, GrepTest }) => {
process.env.MOON_RUN_SCRIPTS = "true";
const effect = Effect.gen(function* (_) {
if (envName) {
yield* _(
testEffect(envName, { testNamePattern: GrepTest }).pipe(
Effect.catchTag("TestsFailedError", (error) =>
Effect.succeed(
console.log(`❌ ${error.fails} test${error.fails !== 1 && "s"} failed`)
)
)
)
);
} else {
console.error("👉 Run 'pnpm moonwall --help' for more information");
yield* _(Effect.fail("❌ No environment specified"));
}
yield* _(
testEffect(envName, { testNamePattern: GrepTest }).pipe(
Effect.catchTag("TestsFailedError", (error) => {
failedTests = error.fails;
return Effect.succeed(
console.log(`❌ ${error.fails} test file${error.fails !== 1 ? "s" : ""} failed`)
);
})
)
);
});

await Effect.runPromise(effect);

if (failedTests) {
process.exitCode = 1;
}
const timeout = 5;
setTimeout(function () {
log(); // logs out active handles that are keeping node running
}, 10000);
log();
}, timeout * 1000);
}
)
.command(
Expand All @@ -170,7 +176,7 @@ const cliStart = Effect.try(() => {
process.env.MOON_RUN_SCRIPTS = "true";
const effect = Effect.tryPromise(() => runNetworkCmd(argv as any));

await Effect.runPromise(effect);
await Effect.runPromiseExit(effect);
}
)
.help("h")
Expand All @@ -180,16 +186,12 @@ const cliStart = Effect.try(() => {

const cli = pipe(
setupConfigFileEnv,
Effect.flatMap(() => cliStart),
Effect.catchAll((error: any) => Effect.logError(`Error: ${error.message}`))
Effect.flatMap(() => cliStart)
);

Effect.runPromise(cli)
.then(() => {
console.log("🏁 Moonwall Test Run finished");
process.exit(0);
console.log("🏁 Moonwall Test Run finished");
process.exit();
})
.catch((defect) => {
console.error(defect);
process.exit(1);
});
.catch(console.error);
3 changes: 1 addition & 2 deletions packages/cli/src/cmds/runTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ export const testEffect = (envName: string, additionalArgs?: object) => {
);

if (failed.length === 0) {
yield* _(Effect.sync(() => console.log("✅ All tests passed")));
return;
yield* _(Effect.succeed(() => console.log("✅ All tests passed")));
} else {
yield* _(Effect.fail(new Err.TestsFailedError(failed.length)));
}
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/errors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from "./generalErrors";
export * from "./providerErrors";
export * from "./zombieErrors";
export * from "./MoonwallContextErrors";
export * from "./nonErrors";
4 changes: 4 additions & 0 deletions packages/cli/src/errors/nonErrors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export class ForceQuitFibre {
readonly _tag = "ForceQuitFibre";
constructor(readonly seconds?: number) {}
}

0 comments on commit 38842bc

Please sign in to comment.