1tube 0.4.0 → 0.5.1
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.
- package/dist/test/api.d.ts +2 -1
- package/dist/test/node.js +4 -4
- package/package.json +1 -1
- package/src/cli/deno-config.ts +2 -2
- package/src/cli/test.ts +16 -1
- package/src/test/api.ts +2 -1
- package/src/test/bun.ts +4 -4
- package/src/test/node.ts +4 -4
package/dist/test/api.d.ts
CHANGED
|
@@ -44,7 +44,8 @@ export interface DescribeFunction extends RegisterSuite {
|
|
|
44
44
|
skipIf(condition: unknown): RegisterSuite;
|
|
45
45
|
each<Row>(table: readonly Row[]): (name: string, fn: (...args: EachArgs<Row>) => void) => void;
|
|
46
46
|
}
|
|
47
|
-
|
|
47
|
+
/** A setup/teardown hook; `timeout` in milliseconds (runner default when omitted). */
|
|
48
|
+
export type Hook = (fn: HookFn, timeout?: number) => void;
|
|
48
49
|
type AnyFn = (...args: any[]) => any;
|
|
49
50
|
export interface MockFunction {
|
|
50
51
|
/** A mock function (records calls; optional implementation). */
|
package/dist/test/node.js
CHANGED
|
@@ -17,10 +17,10 @@ export const { test, it, describe, beforeAll, afterAll, beforeEach, afterEach, m
|
|
|
17
17
|
test: (name, fn, { timeout, skip, only }) => void node.test(name, { timeout, skip, only }, wrap(fn)),
|
|
18
18
|
todo: (name) => void node.test(name, { todo: true }),
|
|
19
19
|
describe: (name, fn, mode) => void node.describe(name, { skip: mode === "skip", only: mode === "only" }, fn),
|
|
20
|
-
beforeAll: (fn) => node.before(wrap(fn)),
|
|
21
|
-
afterAll: (fn) => node.after(wrap(fn)),
|
|
22
|
-
beforeEach: (fn) => node.beforeEach(wrap(fn)),
|
|
23
|
-
afterEach: (fn) => node.afterEach(wrap(fn)),
|
|
20
|
+
beforeAll: (fn, timeout) => node.before(wrap(fn), { timeout }),
|
|
21
|
+
afterAll: (fn, timeout) => node.after(wrap(fn), { timeout }),
|
|
22
|
+
beforeEach: (fn, timeout) => node.beforeEach(wrap(fn), { timeout }),
|
|
23
|
+
afterEach: (fn, timeout) => node.afterEach(wrap(fn), { timeout }),
|
|
24
24
|
mockModule: (specifier, factory) => {
|
|
25
25
|
const moduleMock = node.mock.module;
|
|
26
26
|
if (typeof moduleMock !== "function") {
|
package/package.json
CHANGED
package/src/cli/deno-config.ts
CHANGED
|
@@ -67,8 +67,8 @@ export async function resolveDenoConfigPath(
|
|
|
67
67
|
return { configPath: found };
|
|
68
68
|
}
|
|
69
69
|
onMessage?.(
|
|
70
|
-
`no
|
|
71
|
-
`
|
|
70
|
+
`no import map at ${cwd} or ${fnDirAbs}; bare imports resolve from ` +
|
|
71
|
+
`node_modules (package.json is the version source).`,
|
|
72
72
|
);
|
|
73
73
|
return {};
|
|
74
74
|
}
|
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
|
];
|
package/src/test/api.ts
CHANGED
|
@@ -55,7 +55,8 @@ export interface DescribeFunction extends RegisterSuite {
|
|
|
55
55
|
each<Row>(table: readonly Row[]): (name: string, fn: (...args: EachArgs<Row>) => void) => void;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
/** A setup/teardown hook; `timeout` in milliseconds (runner default when omitted). */
|
|
59
|
+
export type Hook = (fn: HookFn, timeout?: number) => void;
|
|
59
60
|
|
|
60
61
|
// `any` is unavoidable for generic function shapes.
|
|
61
62
|
type AnyFn = (...args: any[]) => any;
|
package/src/test/bun.ts
CHANGED
|
@@ -24,10 +24,10 @@ export const { test, it, describe, beforeAll, afterAll, beforeEach, afterEach, m
|
|
|
24
24
|
todo: (name) => bun.test.todo(name, () => {}),
|
|
25
25
|
describe: (name, fn, mode) =>
|
|
26
26
|
mode === "skip" ? bun.describe.skip(name, fn) : mode === "only" ? bun.describe.only(name, fn) : bun.describe(name, fn),
|
|
27
|
-
beforeAll: (fn) => bun.beforeAll(fn),
|
|
28
|
-
afterAll: (fn) => bun.afterAll(fn),
|
|
29
|
-
beforeEach: (fn) => bun.beforeEach(fn),
|
|
30
|
-
afterEach: (fn) => bun.afterEach(fn),
|
|
27
|
+
beforeAll: (fn, timeout) => bun.beforeAll(fn, timeout),
|
|
28
|
+
afterAll: (fn, timeout) => bun.afterAll(fn, timeout),
|
|
29
|
+
beforeEach: (fn, timeout) => bun.beforeEach(fn, timeout),
|
|
30
|
+
afterEach: (fn, timeout) => bun.afterEach(fn, timeout),
|
|
31
31
|
mockModule: (specifier, factory) => {
|
|
32
32
|
void bun.mock.module(specifier.startsWith("file:") ? fileURLToPath(specifier) : specifier, factory);
|
|
33
33
|
},
|
package/src/test/node.ts
CHANGED
|
@@ -25,10 +25,10 @@ export const { test, it, describe, beforeAll, afterAll, beforeEach, afterEach, m
|
|
|
25
25
|
test: (name, fn, { timeout, skip, only }) => void node.test(name, { timeout, skip, only }, wrap(fn)),
|
|
26
26
|
todo: (name) => void node.test(name, { todo: true }),
|
|
27
27
|
describe: (name, fn, mode) => void node.describe(name, { skip: mode === "skip", only: mode === "only" }, fn),
|
|
28
|
-
beforeAll: (fn) => node.before(wrap(fn)),
|
|
29
|
-
afterAll: (fn) => node.after(wrap(fn)),
|
|
30
|
-
beforeEach: (fn) => node.beforeEach(wrap(fn)),
|
|
31
|
-
afterEach: (fn) => node.afterEach(wrap(fn)),
|
|
28
|
+
beforeAll: (fn, timeout) => node.before(wrap(fn), { timeout }),
|
|
29
|
+
afterAll: (fn, timeout) => node.after(wrap(fn), { timeout }),
|
|
30
|
+
beforeEach: (fn, timeout) => node.beforeEach(wrap(fn), { timeout }),
|
|
31
|
+
afterEach: (fn, timeout) => node.afterEach(wrap(fn), { timeout }),
|
|
32
32
|
mockModule: (specifier, factory) => {
|
|
33
33
|
const moduleMock = (node.mock as { module?: (s: string, o: object) => unknown }).module;
|
|
34
34
|
if (typeof moduleMock !== "function") {
|