1tube 0.4.0 → 0.5.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/cli/test.ts +16 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "1tube",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "private": false,
5
5
  "description": "Self-hosted Supabase Edge Functions gateway on Bun, plus an ESLint plugin for consumers",
6
6
  "license": "MIT",
package/src/cli/test.ts CHANGED
@@ -9,6 +9,10 @@
9
9
  * the import map, `npm:` / `jsr:` specifiers and the managed dependency
10
10
  * store apply to function code under test. Without explicit paths it runs
11
11
  * every test under the functions dir.
12
+ *
13
+ * Each test file runs isolated (fresh globals and module registry), like
14
+ * each function on the gateway: by default in parallel worker processes,
15
+ * so `mock.module` and other module state cannot leak between files.
12
16
  */
13
17
 
14
18
  import { existsSync } from "node:fs";
@@ -34,6 +38,8 @@ const BUN_TEST_VALUE_FLAGS = new Set([
34
38
 
35
39
  export interface TestArgs {
36
40
  functionsDir: string;
41
+ /** `--no-parallel`: isolate files in one process instead of workers. */
42
+ parallel: boolean;
37
43
  config?: string;
38
44
  depsDir?: string;
39
45
  envFiles: string[];
@@ -42,7 +48,7 @@ export interface TestArgs {
42
48
  }
43
49
 
44
50
  export function parseTestArgs(argv: readonly string[]): TestArgs {
45
- const out: TestArgs = { functionsDir: "", envFiles: [], forwarded: [], hasPaths: false };
51
+ const out: TestArgs = { functionsDir: "", parallel: true, envFiles: [], forwarded: [], hasPaths: false };
46
52
  let functionsDir: string | undefined;
47
53
  for (let i = 0; i < argv.length; i++) {
48
54
  const tok = argv[i];
@@ -71,6 +77,9 @@ export function parseTestArgs(argv: readonly string[]): TestArgs {
71
77
  case "--env-file":
72
78
  out.envFiles.push(value());
73
79
  continue;
80
+ case "--no-parallel":
81
+ out.parallel = false;
82
+ continue;
74
83
  }
75
84
  out.forwarded.push(tok);
76
85
  if (BUN_TEST_VALUE_FLAGS.has(flag) && eq === -1 && i + 1 < argv.length) {
@@ -90,12 +99,14 @@ export async function runTest(argv: readonly string[]): Promise<number> {
90
99
 
91
100
  Runs edge function tests (files importing \`1tube/test\`) with the gateway's
92
101
  module resolution. Without paths, runs every test under the functions dir.
102
+ Each file runs isolated, in parallel workers by default.
93
103
 
94
104
  Options:
95
105
  --functions, -f <dir> Functions dir (default: supabase/functions, else functions)
96
106
  --config <path> Import map (import_map.json, or a deno.json[c] with "imports")
97
107
  --deps-dir <path> Managed npm:/jsr: store (default <cwd>/.1tube/deps)
98
108
  --env-file <path> Env file loaded into the test process (repeatable)
109
+ --no-parallel Run files one after another in one process (still isolated)
99
110
  -- Pass everything after it to the runner verbatim
100
111
  `);
101
112
  return 0;
@@ -134,6 +145,10 @@ Options:
134
145
  "test",
135
146
  "--preload",
136
147
  preload,
148
+ // Isolation unless the caller chose a mode themselves.
149
+ ...(args.forwarded.some((a) => /^--(parallel|isolate|no-isolate)(=|$)/.test(a))
150
+ ? []
151
+ : [args.parallel ? "--parallel" : "--isolate"]),
137
152
  ...args.forwarded,
138
153
  ...(args.hasPaths ? [] : [defaultPath]),
139
154
  ];