@vnejs/plugins.scenario.fastforward 0.1.17 → 0.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.scenario.fastforward",
3
- "version": "0.1.17",
3
+ "version": "0.2.0",
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",
@@ -30,13 +30,15 @@
30
30
  "author": "",
31
31
  "license": "ISC",
32
32
  "dependencies": {
33
- "@vnejs/contracts.scenario.fastforward": "~0.1.0"
33
+ "@vnejs/contracts.scenario.fastforward": "~0.2.0"
34
34
  },
35
35
  "peerDependencies": {
36
- "@vnejs/module.core": "~0.1.0",
37
- "@vnejs/shared": "~0.1.0"
36
+ "@vnejs/module.core": "~0.2.0",
37
+ "@vnejs/shared": "~0.2.0"
38
38
  },
39
39
  "devDependencies": {
40
- "@vnejs/configs.ts-common": "~0.1.0"
40
+ "@vnejs/configs.ts-common": "~0.2.0",
41
+ "@vnejs/configs.vitest": "~0.2.0",
42
+ "@vnejs/test-utils": "~0.2.0"
41
43
  }
42
44
  }
@@ -0,0 +1,57 @@
1
+ import { beforeEach, describe, expect, it, vi } from "vitest";
2
+
3
+ import { SUBSCRIBE_EVENTS as INTERACT_EVENTS } from "@vnejs/contracts.core.interact";
4
+ import { SUBSCRIBE_EVENTS as SYSTEM_EVENTS } from "@vnejs/contracts.core.system";
5
+ import { spyEvent } from "@vnejs/test-utils";
6
+
7
+ import { Fastforward } from "../modules/fastforward.js";
8
+ import { createFastforwardTestModule, registerFastforwardPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
9
+
10
+ describe("Fastforward", () => {
11
+ beforeEach(() => {
12
+ registerFastforwardPluginVne();
13
+ vi.useFakeTimers();
14
+ });
15
+
16
+ it("START enables fastforward and emits CHANGED", async () => {
17
+ const { observer, shared } = createFastforwardTestModule(Fastforward);
18
+ const changed = spyEvent(observer, SUBSCRIBE_EVENTS.CHANGED);
19
+
20
+ await observer.emit(SUBSCRIBE_EVENTS.START);
21
+
22
+ expect(shared.isFastforwardOn).toBe(true);
23
+ expect(changed).toHaveBeenCalledExactlyOnceWith({ value: true });
24
+ });
25
+
26
+ it("EMIT triggers interact when all checks pass", async () => {
27
+ const { observer } = createFastforwardTestModule(Fastforward);
28
+ const interact = spyEvent(observer, INTERACT_EVENTS.EMIT);
29
+
30
+ observer.subscribe(SUBSCRIBE_EVENTS.CHECK, () => ({ isAllowed: true, source: "test" }));
31
+
32
+ await observer.emit(SUBSCRIBE_EVENTS.EMIT);
33
+
34
+ expect(interact).toHaveBeenCalledOnce();
35
+ });
36
+
37
+ it("EMIT disables fastforward when a check fails", async () => {
38
+ const { observer, shared } = createFastforwardTestModule(Fastforward);
39
+
40
+ shared.isFastforwardOn = true;
41
+ observer.subscribe(SUBSCRIBE_EVENTS.CHECK, () => ({ isAllowed: false, source: "test" }));
42
+
43
+ await observer.emit(SUBSCRIBE_EVENTS.EMIT);
44
+
45
+ expect(shared.isFastforwardOn).toBe(false);
46
+ });
47
+
48
+ it("SYSTEM.STARTED stops fastforward", async () => {
49
+ const { observer, shared } = createFastforwardTestModule(Fastforward);
50
+
51
+ shared.isFastforwardOn = true;
52
+
53
+ await observer.emit(SYSTEM_EVENTS.STARTED);
54
+
55
+ expect(shared.isFastforwardOn).toBe(false);
56
+ });
57
+ });
@@ -0,0 +1,33 @@
1
+ import { PLUGIN_NAME, PARAMS, SETTINGS_KEYS, SUBSCRIBE_EVENTS } from "@vnejs/contracts.scenario.fastforward";
2
+ import { createTestModule as baseCreateTestModule, registerCoreVne, registerVnePlugin, stubSilentEvent } from "@vnejs/test-utils";
3
+ import { SourcesSet } from "@vnejs/sources-set";
4
+
5
+ export const registerFastforwardPluginVne = () => {
6
+ registerCoreVne();
7
+ registerVnePlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, settings: SETTINGS_KEYS, params: PARAMS });
8
+ };
9
+
10
+ export const createFastforwardTestModule = <T extends Parameters<typeof baseCreateTestModule>[0]>(
11
+ ModuleClass: T,
12
+ options: Parameters<typeof baseCreateTestModule>[1] = {},
13
+ ) => {
14
+ const result = baseCreateTestModule(ModuleClass, {
15
+ shared: {
16
+ settings: {
17
+ [SETTINGS_KEYS.ENABLED]: true,
18
+ [SETTINGS_KEYS.DELAY]: PARAMS.DEFAULT_DELAY,
19
+ },
20
+ isFastforwardOn: false,
21
+ mediaNoTimeoutSources: new SourcesSet(),
22
+ viewForceAnimationSources: new SourcesSet(),
23
+ ...(options.shared as Record<string, unknown>),
24
+ },
25
+ ...options,
26
+ });
27
+
28
+ stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.CHANGED);
29
+
30
+ return result;
31
+ };
32
+
33
+ export { SUBSCRIBE_EVENTS, PARAMS, SETTINGS_KEYS, 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
  }