@vnejs/plugins.scenario.random 0.1.15 → 0.1.16

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.scenario.random",
3
- "version": "0.1.15",
3
+ "version": "0.1.16",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -18,7 +18,7 @@
18
18
  "tsconfig.json"
19
19
  ],
20
20
  "scripts": {
21
- "test": "echo \"Error: no test specified\" && exit 1",
21
+ "test": "npx @vnejs/monorepo test",
22
22
  "build": "npx @vnejs/monorepo package",
23
23
  "publish:major:plugin": "npm run publish:major",
24
24
  "publish:minor:plugin": "npm run publish:minor",
@@ -37,6 +37,8 @@
37
37
  "@vnejs/shared": "~0.1.0"
38
38
  },
39
39
  "devDependencies": {
40
- "@vnejs/configs.ts-common": "~0.1.0"
40
+ "@vnejs/configs.ts-common": "~0.1.0",
41
+ "@vnejs/configs.vitest": "~0.1.0",
42
+ "@vnejs/test-utils": "~0.1.0"
41
43
  }
42
44
  }
@@ -0,0 +1,31 @@
1
+ import { beforeEach, describe, expect, it, vi } from "vitest";
2
+
3
+ import { SUBSCRIBE_EVENTS as SCENARIO_EVENTS } from "@vnejs/contracts.core.scenario";
4
+ import { spyEvent, stubEvent } from "@vnejs/test-utils";
5
+
6
+ import { Random } from "../modules/random.js";
7
+ import { createRandomTestModule, registerRandomPluginVne } from "./setup.js";
8
+
9
+ describe("Random", () => {
10
+ beforeEach(() => {
11
+ registerRandomPluginVne();
12
+ vi.spyOn(Math, "random").mockReturnValue(0);
13
+ });
14
+
15
+ it("onLineExec picks random option and advances scenario", async () => {
16
+ const { module, observer, state } = createRandomTestModule(Random, { subscribe: false });
17
+ const next = spyEvent(observer, SCENARIO_EVENTS.NEXT);
18
+
19
+ stubEvent(observer, SCENARIO_EVENTS.LINES_GET, () => [
20
+ { line: "% random", indent: 0 },
21
+ { line: "% option A", indent: 2 },
22
+ { line: "% option B", indent: 2 },
23
+ { line: "next", indent: 0 },
24
+ ]);
25
+
26
+ await (module as Random).onLineExec();
27
+
28
+ expect(state.scenario.curLine).toBe(2);
29
+ expect(next).toHaveBeenCalledOnce();
30
+ });
31
+ });
@@ -0,0 +1,17 @@
1
+ import { PLUGIN_NAME } from "@vnejs/contracts.scenario.random";
2
+ import { createCoreGlobalState, createTestModule, registerCoreVne } from "@vnejs/test-utils";
3
+
4
+ export const registerRandomPluginVne = () => {
5
+ registerCoreVne();
6
+ };
7
+
8
+ export const createRandomTestModule = <T extends Parameters<typeof createTestModule>[0]>(
9
+ ModuleClass: T,
10
+ options: Parameters<typeof createTestModule>[1] = {},
11
+ ) =>
12
+ createTestModule(ModuleClass, {
13
+ state: createCoreGlobalState({ scenario: { label: "main", curLine: 0 } }),
14
+ ...options,
15
+ });
16
+
17
+ export { PLUGIN_NAME };
package/tsconfig.json CHANGED
@@ -5,5 +5,5 @@
5
5
  "outDir": "dist"
6
6
  },
7
7
  "include": ["src/**/*.ts"],
8
- "exclude": ["dist", "node_modules"]
8
+ "exclude": ["dist", "node_modules", "src/tests"]
9
9
  }