@vnejs/compatibility.entities.units-with-scales 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/compatibility.entities.units-with-scales",
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,30 @@
1
+ import "@vnejs/contracts.entities.units";
2
+ import "@vnejs/contracts.scales.health";
3
+
4
+ import { PARAMS as ENTITIES_PARAMS, PLUGIN_NAME as ENTITIES } from "@vnejs/contracts.entities";
5
+ import { PARAMS as SCALES_PARAMS, SUBSCRIBE_EVENTS as SCALES_EVENTS, PLUGIN_NAME as SCALES } from "@vnejs/contracts.scales";
6
+ import { SUBSCRIBE_EVENTS as UNITS_EVENTS, PLUGIN_NAME as UNITS } from "@vnejs/contracts.entities.units";
7
+ import { createTestModule as baseCreateTestModule, registerCoreVne, registerVnePlugin, stubSilentEvent } from "@vnejs/test-utils";
8
+
9
+ export const registerCompatibilityVne = () => {
10
+ registerCoreVne();
11
+ registerVnePlugin(ENTITIES, { params: ENTITIES_PARAMS });
12
+ registerVnePlugin(UNITS, { events: UNITS_EVENTS });
13
+ registerVnePlugin(SCALES, { events: SCALES_EVENTS, params: SCALES_PARAMS });
14
+ };
15
+
16
+ export const createCompatibilityTestModule = <T extends Parameters<typeof baseCreateTestModule>[0]>(
17
+ ModuleClass: T,
18
+ options: Parameters<typeof baseCreateTestModule>[1] = {},
19
+ ) => {
20
+ const result = baseCreateTestModule(ModuleClass, {
21
+ state: {},
22
+ ...options,
23
+ });
24
+
25
+ stubSilentEvent(result.observer, SCALES_EVENTS.SPAWN);
26
+
27
+ return result;
28
+ };
29
+
30
+ export { SCALES_EVENTS, UNITS_EVENTS };
@@ -0,0 +1,33 @@
1
+ import { beforeEach, describe, expect, it, vi } from "vitest";
2
+
3
+ import { spyEvent } from "@vnejs/test-utils";
4
+
5
+ import { UnitsScales } from "../index.js";
6
+ import { createCompatibilityTestModule, registerCompatibilityVne, SCALES_EVENTS, UNITS_EVENTS } from "./setup.js";
7
+
8
+ describe("UnitsScales", () => {
9
+ beforeEach(() => registerCompatibilityVne());
10
+
11
+ it("UNITS.SPAWNED with scales emits SCALES.SPAWN and stores keys", async () => {
12
+ const { module, observer } = createCompatibilityTestModule(UnitsScales);
13
+ const spawn = spyEvent(observer, SCALES_EVENTS.SPAWN);
14
+
15
+ await observer.emit(UNITS_EVENTS.SPAWNED, { key: "hero", unit: { scales: { health: { current: 50, max: 100 } } } });
16
+
17
+ expect(spawn).toHaveBeenCalledOnce();
18
+ expect(spawn).toHaveBeenCalledWith({ key: "unit:hero:health", type: "health", current: 50, max: 100 });
19
+ expect((module as UnitsScales).state.hero).toEqual(["unit:hero:health"]);
20
+ });
21
+
22
+ it("UNITS.DESTROYED emits SCALES.DESTROY for tracked keys", async () => {
23
+ const { module, observer } = createCompatibilityTestModule(UnitsScales);
24
+ const destroy = spyEvent(observer, SCALES_EVENTS.DESTROY);
25
+
26
+ await observer.emit(UNITS_EVENTS.SPAWNED, { key: "hero", unit: { scales: { health: { current: 50, max: 100 } } } });
27
+ await observer.emit(UNITS_EVENTS.DESTROYED, { key: "hero" });
28
+
29
+ expect(destroy).toHaveBeenCalledOnce();
30
+ expect(destroy).toHaveBeenCalledWith({ key: "unit:hero:health" });
31
+ expect((module as UnitsScales).state.hero).toBeUndefined();
32
+ });
33
+ });
package/tsconfig.json CHANGED
@@ -4,6 +4,12 @@
4
4
  "rootDir": "src",
5
5
  "outDir": "dist"
6
6
  },
7
- "include": ["src/**/*.ts"],
8
- "exclude": ["dist", "node_modules"]
7
+ "include": [
8
+ "src/**/*.ts"
9
+ ],
10
+ "exclude": [
11
+ "dist",
12
+ "node_modules",
13
+ "src/tests"
14
+ ]
9
15
  }