@vnejs/plugins.vars.counters 0.1.19 → 0.1.21

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.
@@ -36,7 +36,7 @@ export class Counters extends ModuleCore {
36
36
  const name = String(tokens[0] ?? "");
37
37
  const action = String(tokens[1] ?? "");
38
38
  const execValue = Number(tokens[2] ?? 0);
39
- const isGlobal = keywords.includes(this.CONST.SCENARIO.LINE_KEYWORDS.GLOBAL);
39
+ const isGlobal = keywords.includes(this.CONST.VARS.LINE_KEYWORDS.GLOBAL);
40
40
  const result = { name, action, isGlobal, execValue };
41
41
  return withValue ? { ...result, value: Number(await this.emitOne(this.EVENTS.VARS_COUNTERS.GET, { name, isGlobal, state })) } : result;
42
42
  };
package/dist/types.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { ModuleCoreConstants, ModuleCoreEvents, ModuleCoreParams, ModuleCoreSettings } from "@vnejs/module.core";
2
- import type { PluginName as VarsPluginName, SubscribeEvents as VarsSubscribeEvents } from "@vnejs/contracts.vars";
2
+ import type { Constants as VarsConstants, PluginName as VarsPluginName, SubscribeEvents as VarsSubscribeEvents } from "@vnejs/contracts.vars";
3
3
  import type { Constants, PluginName, SubscribeEvents } from "@vnejs/contracts.vars.counters";
4
4
  export type CountersPluginEvents = ModuleCoreEvents & Record<PluginName, SubscribeEvents> & Record<VarsPluginName, VarsSubscribeEvents>;
5
- export type CountersPluginConstants = ModuleCoreConstants & Record<PluginName, Constants>;
5
+ export type CountersPluginConstants = ModuleCoreConstants & Record<PluginName, Constants> & Record<VarsPluginName, VarsConstants>;
6
6
  export type CountersPluginSettings = ModuleCoreSettings;
7
7
  export type CountersPluginParams = ModuleCoreParams;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.vars.counters",
3
- "version": "0.1.19",
3
+ "version": "0.1.21",
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",
@@ -39,6 +39,9 @@
39
39
  "@vnejs/shared": "~0.1.0"
40
40
  },
41
41
  "devDependencies": {
42
- "@vnejs/configs.ts-common": "~0.1.0"
42
+ "@vnejs/configs.ts-common": "~0.1.0",
43
+ "@vnejs/configs.vitest": "~0.1.0",
44
+ "@vnejs/test-utils": "~0.1.0",
45
+ "@vnejs/contracts.vars": "~0.1.0"
43
46
  }
44
47
  }
@@ -63,7 +63,7 @@ export class Counters extends ModuleCore<CountersPluginEvents, CountersPluginCon
63
63
  const name = String(tokens[0] ?? "");
64
64
  const action = String(tokens[1] ?? "");
65
65
  const execValue = Number(tokens[2] ?? 0);
66
- const isGlobal = keywords.includes(this.CONST.SCENARIO.LINE_KEYWORDS.GLOBAL);
66
+ const isGlobal = keywords.includes(this.CONST.VARS.LINE_KEYWORDS.GLOBAL);
67
67
  const result: CountersExecInfoResult = { name, action, isGlobal, execValue };
68
68
 
69
69
  return withValue ? { ...result, value: Number(await this.emitOne(this.EVENTS.VARS_COUNTERS.GET, { name, isGlobal, state })) } : result;
@@ -0,0 +1,46 @@
1
+ import { beforeEach, describe, expect, it } from "vitest";
2
+
3
+ import { SUBSCRIBE_EVENTS as VARS_EVENTS } from "@vnejs/contracts.vars";
4
+ import { spyEvent } from "@vnejs/test-utils";
5
+
6
+ import { Counters } from "../modules/counters.js";
7
+ import { CONSTANTS, createCountersTestModule, registerCountersPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
8
+
9
+ describe("Counters", () => {
10
+ beforeEach(() => {
11
+ registerCountersPluginVne();
12
+ });
13
+
14
+ it("CHANGE applies increment action", async () => {
15
+ const { observer } = createCountersTestModule(Counters);
16
+
17
+ const [result] = await observer.emit(SUBSCRIBE_EVENTS.CHANGE, {
18
+ value: 5,
19
+ execValue: 0,
20
+ action: CONSTANTS.CHANGE_ACTIONS.INC,
21
+ });
22
+
23
+ expect(result).toBe(6);
24
+ });
25
+
26
+ it("COMPARE uses configured comparator", async () => {
27
+ const { observer } = createCountersTestModule(Counters);
28
+
29
+ const [result] = await observer.emit(SUBSCRIBE_EVENTS.COMPARE, {
30
+ value: 10,
31
+ execValue: 5,
32
+ action: CONSTANTS.COMPARE_ACTIONS.MORE,
33
+ });
34
+
35
+ expect(result).toBe(true);
36
+ });
37
+
38
+ it("SET delegates to VARS.SET with counter type", async () => {
39
+ const { observer } = createCountersTestModule(Counters);
40
+ const set = spyEvent(observer, VARS_EVENTS.SET);
41
+
42
+ await observer.emit(SUBSCRIBE_EVENTS.SET, { name: "gold", value: 3 });
43
+
44
+ expect(set).toHaveBeenCalledExactlyOnceWith({ name: "gold", type: CONSTANTS.TYPE, value: 3, isGlobal: false });
45
+ });
46
+ });
@@ -0,0 +1,11 @@
1
+ import { CONSTANTS as VARS_CONST, PLUGIN_NAME as VARS, SUBSCRIBE_EVENTS as VARS_EVENTS } from "@vnejs/contracts.vars";
2
+ import { CONSTANTS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.vars.counters";
3
+ import { createTestModule, registerCoreVne, registerVnePlugin } from "@vnejs/test-utils";
4
+
5
+ export const registerCountersPluginVne = () => {
6
+ registerCoreVne();
7
+ registerVnePlugin(VARS, { events: VARS_EVENTS, constants: VARS_CONST });
8
+ registerVnePlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS });
9
+ };
10
+
11
+ export { createTestModule as createCountersTestModule, SUBSCRIBE_EVENTS, CONSTANTS, VARS_EVENTS, PLUGIN_NAME };
package/src/types.ts CHANGED
@@ -1,10 +1,14 @@
1
1
  import type { ModuleCoreConstants, ModuleCoreEvents, ModuleCoreParams, ModuleCoreSettings } from "@vnejs/module.core";
2
- import type { PluginName as VarsPluginName, SubscribeEvents as VarsSubscribeEvents } from "@vnejs/contracts.vars";
2
+ import type {
3
+ Constants as VarsConstants,
4
+ PluginName as VarsPluginName,
5
+ SubscribeEvents as VarsSubscribeEvents,
6
+ } from "@vnejs/contracts.vars";
3
7
  import type { Constants, PluginName, SubscribeEvents } from "@vnejs/contracts.vars.counters";
4
8
 
5
9
  export type CountersPluginEvents = ModuleCoreEvents & Record<PluginName, SubscribeEvents> & Record<VarsPluginName, VarsSubscribeEvents>;
6
10
 
7
- export type CountersPluginConstants = ModuleCoreConstants & Record<PluginName, Constants>;
11
+ export type CountersPluginConstants = ModuleCoreConstants & Record<PluginName, Constants> & Record<VarsPluginName, VarsConstants>;
8
12
 
9
13
  export type CountersPluginSettings = ModuleCoreSettings;
10
14
 
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
  }