@vnejs/plugins.vars.counters 0.1.19 → 0.1.20
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 +6 -3
- package/src/tests/counters.test.ts +46 -0
- package/src/tests/setup.ts +11 -0
- package/tsconfig.json +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vnejs/plugins.vars.counters",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.20",
|
|
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": "
|
|
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
|
}
|
|
@@ -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 });
|
|
8
|
+
registerVnePlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS });
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { createTestModule as createCountersTestModule, SUBSCRIBE_EVENTS, CONSTANTS, VARS_EVENTS, PLUGIN_NAME };
|
package/tsconfig.json
CHANGED