@lunatest/core 0.1.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.
- package/LICENSE +21 -0
- package/dist/config/lua-config.d.ts +4 -0
- package/dist/config/lua-config.js +71 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +5 -0
- package/dist/mocks/provider.d.ts +56 -0
- package/dist/mocks/provider.js +166 -0
- package/dist/provider/luna-provider.d.ts +27 -0
- package/dist/provider/luna-provider.js +117 -0
- package/dist/runner/assert.d.ts +11 -0
- package/dist/runner/assert.js +58 -0
- package/dist/runner/execute-scenario.d.ts +38 -0
- package/dist/runner/execute-scenario.js +70 -0
- package/dist/runner/performance.d.ts +14 -0
- package/dist/runner/performance.js +31 -0
- package/dist/runner/reporter.d.ts +5 -0
- package/dist/runner/reporter.js +70 -0
- package/dist/runner/runner.d.ts +42 -0
- package/dist/runner/runner.js +74 -0
- package/dist/runtime/bridge.d.ts +2 -0
- package/dist/runtime/bridge.js +48 -0
- package/dist/runtime/engine.d.ts +2 -0
- package/dist/runtime/engine.js +85 -0
- package/dist/runtime/sandbox.d.ts +3 -0
- package/dist/runtime/sandbox.js +54 -0
- package/dist/runtime/scenario-runtime.d.ts +70 -0
- package/dist/runtime/scenario-runtime.js +156 -0
- package/dist/runtime/types.d.ts +17 -0
- package/dist/runtime/types.js +9 -0
- package/dist/scenario/index.d.ts +43 -0
- package/dist/scenario/index.js +85 -0
- package/package.json +36 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
declare const StageSchema: z.ZodObject<{
|
|
3
|
+
name: z.ZodString;
|
|
4
|
+
on: z.ZodOptional<z.ZodString>;
|
|
5
|
+
}, z.core.$strip>;
|
|
6
|
+
declare const ScenarioSchema: z.ZodObject<{
|
|
7
|
+
name: z.ZodString;
|
|
8
|
+
given: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
9
|
+
when: z.ZodObject<{
|
|
10
|
+
action: z.ZodString;
|
|
11
|
+
}, z.core.$loose>;
|
|
12
|
+
then_ui: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
13
|
+
then_state: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
14
|
+
stages: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
15
|
+
name: z.ZodString;
|
|
16
|
+
on: z.ZodOptional<z.ZodString>;
|
|
17
|
+
}, z.core.$strip>>>;
|
|
18
|
+
not_present: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
19
|
+
timing_ms: z.ZodOptional<z.ZodNumber>;
|
|
20
|
+
}, z.core.$loose>;
|
|
21
|
+
export type ScenarioStage = z.infer<typeof StageSchema>;
|
|
22
|
+
export type ParsedScenario = z.infer<typeof ScenarioSchema>;
|
|
23
|
+
export type StageMachine = {
|
|
24
|
+
current: () => ScenarioStage;
|
|
25
|
+
next: () => ScenarioStage;
|
|
26
|
+
done: () => boolean;
|
|
27
|
+
index: () => number;
|
|
28
|
+
path: () => string[];
|
|
29
|
+
};
|
|
30
|
+
export type VirtualClockEvent = {
|
|
31
|
+
atMs: number;
|
|
32
|
+
payload: Record<string, unknown>;
|
|
33
|
+
};
|
|
34
|
+
export type VirtualClock = {
|
|
35
|
+
now: () => number;
|
|
36
|
+
advance: (deltaMs: number) => number;
|
|
37
|
+
schedule: (afterMs: number, payload: Record<string, unknown>) => void;
|
|
38
|
+
drainDue: () => Record<string, unknown>[];
|
|
39
|
+
};
|
|
40
|
+
export declare function parseScenario(input: unknown): ParsedScenario;
|
|
41
|
+
export declare function createStageMachine(stages: ScenarioStage[]): StageMachine;
|
|
42
|
+
export declare function createVirtualClock(initialMs?: number): VirtualClock;
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const RecordValueSchema = z.record(z.string(), z.unknown());
|
|
3
|
+
const StageSchema = z.object({
|
|
4
|
+
name: z.string().min(1),
|
|
5
|
+
on: z.string().min(1).optional(),
|
|
6
|
+
});
|
|
7
|
+
const ScenarioSchema = z
|
|
8
|
+
.object({
|
|
9
|
+
name: z.string().min(1),
|
|
10
|
+
given: RecordValueSchema,
|
|
11
|
+
when: z
|
|
12
|
+
.object({
|
|
13
|
+
action: z.string().min(1),
|
|
14
|
+
})
|
|
15
|
+
.passthrough(),
|
|
16
|
+
then_ui: RecordValueSchema,
|
|
17
|
+
then_state: RecordValueSchema.optional(),
|
|
18
|
+
stages: z.array(StageSchema).optional(),
|
|
19
|
+
not_present: z.array(z.string().min(1)).optional(),
|
|
20
|
+
timing_ms: z.number().int().nonnegative().optional(),
|
|
21
|
+
})
|
|
22
|
+
.passthrough();
|
|
23
|
+
export function parseScenario(input) {
|
|
24
|
+
if (!input || typeof input !== "object" || !("given" in input)) {
|
|
25
|
+
throw new Error("given is required");
|
|
26
|
+
}
|
|
27
|
+
return ScenarioSchema.parse(input);
|
|
28
|
+
}
|
|
29
|
+
export function createStageMachine(stages) {
|
|
30
|
+
if (stages.length === 0) {
|
|
31
|
+
throw new Error("stages must contain at least one stage");
|
|
32
|
+
}
|
|
33
|
+
let cursor = 0;
|
|
34
|
+
const path = [stages[0].name];
|
|
35
|
+
return {
|
|
36
|
+
current() {
|
|
37
|
+
return stages[cursor];
|
|
38
|
+
},
|
|
39
|
+
next() {
|
|
40
|
+
if (cursor >= stages.length - 1) {
|
|
41
|
+
return stages[cursor];
|
|
42
|
+
}
|
|
43
|
+
cursor += 1;
|
|
44
|
+
path.push(stages[cursor].name);
|
|
45
|
+
return stages[cursor];
|
|
46
|
+
},
|
|
47
|
+
done() {
|
|
48
|
+
return cursor >= stages.length - 1;
|
|
49
|
+
},
|
|
50
|
+
index() {
|
|
51
|
+
return cursor;
|
|
52
|
+
},
|
|
53
|
+
path() {
|
|
54
|
+
return [...path];
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export function createVirtualClock(initialMs = 0) {
|
|
59
|
+
let current = Math.max(0, Math.trunc(initialMs));
|
|
60
|
+
let queue = [];
|
|
61
|
+
const sortQueue = () => {
|
|
62
|
+
queue.sort((left, right) => left.atMs - right.atMs);
|
|
63
|
+
};
|
|
64
|
+
return {
|
|
65
|
+
now() {
|
|
66
|
+
return current;
|
|
67
|
+
},
|
|
68
|
+
advance(deltaMs) {
|
|
69
|
+
current += Math.max(0, Math.trunc(deltaMs));
|
|
70
|
+
return current;
|
|
71
|
+
},
|
|
72
|
+
schedule(afterMs, payload) {
|
|
73
|
+
queue.push({
|
|
74
|
+
atMs: current + Math.max(0, Math.trunc(afterMs)),
|
|
75
|
+
payload: { ...payload },
|
|
76
|
+
});
|
|
77
|
+
sortQueue();
|
|
78
|
+
},
|
|
79
|
+
drainDue() {
|
|
80
|
+
const due = queue.filter((event) => event.atMs <= current);
|
|
81
|
+
queue = queue.filter((event) => event.atMs > current);
|
|
82
|
+
return due.map((event) => ({ ...event.payload }));
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lunatest/core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./package.json": "./package.json"
|
|
15
|
+
},
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public",
|
|
18
|
+
"tag": "latest"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"wasmoon": "^1.16.0",
|
|
22
|
+
"zod": "^4.1.5",
|
|
23
|
+
"@lunatest/contracts": "0.1.0"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"fast-check": "^4.5.3"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsc -p tsconfig.json",
|
|
33
|
+
"test": "vitest run",
|
|
34
|
+
"lint": "tsc -p tsconfig.json --noEmit"
|
|
35
|
+
}
|
|
36
|
+
}
|