@avi2dg/checks 0.45.1 → 0.47.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env bun
2
- import { Config, Console, Effect, FileSystem, Path, Schema } from "effect";
2
+ import { Config, Console, Effect, FileSystem, Option, Path, Schema } from "effect";
3
3
  import { ChildProcess, ChildProcessSpawner } from "effect/process";
4
4
  import { TEST_ENTRY_POINT } from "../core/gates.ts";
5
5
  import { runMain, Usage } from "../core/main.ts";
@@ -26,7 +26,7 @@ export type TestOptions = {
26
26
  };
27
27
 
28
28
  const NAME = TEST_ENTRY_POINT.bin;
29
- const USAGE = `usage: ${NAME} [--tier=live | --tier=pixel | --tier=unit | --tier=e2e] [--parallel=<workers>], and it refuses test filters`;
29
+ const USAGE = `usage: ${NAME} [--tier=live | --tier=pixel | --tier=unit | --tier=e2e] [--parallel=<workers>] [--junit=<file>], and it refuses test filters`;
30
30
  const TIERS = new Map<string, TestTier>([
31
31
  ["--tier=live", "live"],
32
32
  ["--tier=pixel", "pixel"],
@@ -34,6 +34,7 @@ const TIERS = new Map<string, TestTier>([
34
34
  ["--tier=e2e", "e2e"],
35
35
  ]);
36
36
  const PARALLEL = /^--parallel=([1-9][0-9]*)$/;
37
+ const JUNIT = /^--junit=(.+)$/;
37
38
 
38
39
  function optionOf(arg: string): TestOptions | undefined {
39
40
  const tier = TIERS.get(arg);
@@ -52,6 +53,16 @@ export function testOptions(args: readonly string[]): TestOptions | undefined {
52
53
  return options;
53
54
  }
54
55
 
56
+ export type EntryOptions = { readonly options: TestOptions; readonly junit: Option.Option<string> };
57
+
58
+ // Kept out of testOptions, so checks-test-layout still holds a package.json test script to --parallel alone.
59
+ export function entryOptions(args: readonly string[]): EntryOptions | undefined {
60
+ const junit = args.flatMap((arg) => JUNIT.exec(arg)?.[1] ?? []);
61
+ const options = testOptions(args.filter((arg) => !JUNIT.test(arg)));
62
+ if (options === undefined || junit.length > 1) return undefined;
63
+ return { options, junit: Option.fromNullishOr(junit[0]) };
64
+ }
65
+
55
66
  const TEST_SCRIPTS: readonly string[] = [NAME, `bun src/${TEST_ENTRY_POINT.script}`];
56
67
 
57
68
  export function scriptOptions(script: unknown): TestOptions | undefined {
@@ -169,15 +180,22 @@ const runSuite = Effect.fn("runSuite")(function* (outfile: string, { tier, worke
169
180
  });
170
181
 
171
182
  const testEntry = Effect.gen(function* () {
172
- const options = testOptions(process.argv.slice(2));
173
- if (options === undefined) return yield* new Usage({ message: USAGE });
183
+ const entry = entryOptions(process.argv.slice(2));
184
+ if (entry === undefined) return yield* new Usage({ message: USAGE });
185
+ const { options, junit } = entry;
174
186
  const fs = yield* FileSystem.FileSystem;
187
+ const path = yield* Path.Path;
175
188
  const declarations = yield* readSkipDeclarations(process.cwd(), options.tier);
176
189
  const environment = yield* environmentOf;
177
190
 
178
- const outfile = (yield* Path.Path).join(yield* fs.makeTempDirectoryScoped({ prefix: "checks-test-" }), "junit.xml");
191
+ const outfile = path.join(yield* fs.makeTempDirectoryScoped({ prefix: "checks-test-" }), "junit.xml");
179
192
  const suitePassed = (yield* runSuite(outfile, options)) === ChildProcessSpawner.ExitCode(0);
180
- if (!(yield* fs.exists(outfile))) {
193
+ const written = yield* fs.exists(outfile);
194
+ if (written && Option.isSome(junit)) {
195
+ yield* fs.makeDirectory(path.dirname(junit.value), { recursive: true });
196
+ yield* fs.copyFile(outfile, junit.value);
197
+ }
198
+ if (!written) {
181
199
  if (!suitePassed) {
182
200
  yield* Console.error(`${NAME}: bun test failed before it wrote a report, so no skip was judged`);
183
201
  return false;