@vnejs/compatibility.platform.electron-with-views.achievement 0.1.9 → 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/compatibility.platform.electron-with-views.achievement",
3
- "version": "0.1.9",
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,11 +30,13 @@
30
30
  "author": "",
31
31
  "license": "ISC",
32
32
  "peerDependencies": {
33
- "@vnejs/module.core": "~0.1.0",
34
- "@vnejs/contracts.views.achievement": "~0.1.0",
35
- "@vnejs/shared": "~0.1.0"
33
+ "@vnejs/module.core": "~0.2.0",
34
+ "@vnejs/contracts.views.achievement": "~0.2.0",
35
+ "@vnejs/shared": "~0.2.0"
36
36
  },
37
37
  "devDependencies": {
38
- "@vnejs/configs.ts-common": "~0.1.0"
38
+ "@vnejs/configs.ts-common": "~0.2.0",
39
+ "@vnejs/configs.vitest": "~0.2.0",
40
+ "@vnejs/test-utils": "~0.2.0"
39
41
  }
40
42
  }
@@ -0,0 +1,30 @@
1
+ import { beforeEach, describe, expect, it, vi } from "vitest";
2
+
3
+ import { spyEvent } from "@vnejs/test-utils";
4
+
5
+ import { CompatibilityElectronAchievement } from "../index.js";
6
+ import { ACHIEVEMENT_EVENTS, createCompatibilityTestModule, registerCompatibilityVne } from "./setup.js";
7
+
8
+ describe("CompatibilityElectronAchievement", () => {
9
+ beforeEach(() => {
10
+ registerCompatibilityVne();
11
+ vi.stubGlobal("fetch", vi.fn());
12
+ });
13
+
14
+ it("ACHIEVEMENT.UNLOCKED posts to electron host for known id", async () => {
15
+ const { observer } = createCompatibilityTestModule(CompatibilityElectronAchievement);
16
+
17
+ await observer.emit(ACHIEVEMENT_EVENTS.UNLOCKED, { id: "kekw" });
18
+
19
+ expect(fetch).toHaveBeenCalledOnce();
20
+ expect(String((fetch as ReturnType<typeof vi.fn>).mock.calls[0]?.[0])).toContain("achievement/unlock");
21
+ });
22
+
23
+ it("ACHIEVEMENT.LOCKED ignores unknown id", async () => {
24
+ const { observer } = createCompatibilityTestModule(CompatibilityElectronAchievement);
25
+
26
+ await observer.emit(ACHIEVEMENT_EVENTS.LOCKED, { id: "missing" });
27
+
28
+ expect(fetch).not.toHaveBeenCalled();
29
+ });
30
+ });
@@ -0,0 +1,18 @@
1
+ import { CONSTANTS as PLATFORMS_CONST, PARAMS as PLATFORMS_PARAMS, PLUGIN_NAME as PLATFORMS } from "@vnejs/contracts.core.platforms";
2
+ import { PARAMS as ACHIEVEMENT_PARAMS, SUBSCRIBE_EVENTS as ACHIEVEMENT_EVENTS, PLUGIN_NAME as ACHIEVEMENT } from "@vnejs/contracts.views.achievement";
3
+ import { createTestModule as baseCreateTestModule, registerCoreVne, registerVnePlugin } from "@vnejs/test-utils";
4
+ import { VNE } from "@vnejs/shared";
5
+
6
+ export const registerCompatibilityVne = () => {
7
+ registerCoreVne();
8
+ registerVnePlugin(PLATFORMS, { constants: PLATFORMS_CONST, params: { ...PLATFORMS_PARAMS, CURRENT_PLATFORM: PLATFORMS_CONST.ELECTRON } });
9
+ registerVnePlugin(ACHIEVEMENT, { events: ACHIEVEMENT_EVENTS, params: ACHIEVEMENT_PARAMS });
10
+ (VNE.PARAMS as Record<string, { CURRENT_PLATFORM?: string }>).PLATFORMS!.CURRENT_PLATFORM = PLATFORMS_CONST.ELECTRON;
11
+ };
12
+
13
+ export const createCompatibilityTestModule = <T extends Parameters<typeof baseCreateTestModule>[0]>(
14
+ ModuleClass: T,
15
+ options: Parameters<typeof baseCreateTestModule>[1] = {},
16
+ ) => baseCreateTestModule(ModuleClass, options);
17
+
18
+ export { ACHIEVEMENT_EVENTS };
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
  }