@vnejs/test-utils 0.1.1

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.
@@ -0,0 +1,4 @@
1
+ export declare const createCoreGlobalState: (overrides?: Record<string, unknown>) => {
2
+ stack: import("@vnejs/contracts.core.stack").ModuleGlobalStateStack;
3
+ scenario: import("@vnejs/contracts.core.scenario").ModuleGlobalStateScenario;
4
+ };
@@ -0,0 +1,7 @@
1
+ import { DEFAULT_MODULE_GLOBAL_STATE_SCENARIO } from "@vnejs/contracts.core.scenario";
2
+ import { DEFAULT_MODULE_GLOBAL_STATE_STACK } from "@vnejs/contracts.core.stack";
3
+ export const createCoreGlobalState = (overrides = {}) => ({
4
+ stack: structuredClone(DEFAULT_MODULE_GLOBAL_STATE_STACK),
5
+ scenario: structuredClone(DEFAULT_MODULE_GLOBAL_STATE_SCENARIO),
6
+ ...overrides,
7
+ });
@@ -0,0 +1,16 @@
1
+ import type { ModuleGlobalStateRegistry, ModuleInject } from "@vnejs/module";
2
+ import { Observer } from "@vnejs/observer";
3
+ export type TestModuleInstance = {
4
+ name: string;
5
+ inject: (arg?: ModuleInject) => void;
6
+ subscribe: () => void;
7
+ observer?: Observer;
8
+ };
9
+ export type CreateTestModuleOptions = Partial<ModuleInject> & {
10
+ subscribe?: boolean;
11
+ };
12
+ export declare const createTestModule: <T extends TestModuleInstance>(ModuleClass: new () => T, { subscribe, ...injectArg }?: CreateTestModuleOptions) => {
13
+ module: T;
14
+ observer: Observer;
15
+ state: ModuleGlobalStateRegistry;
16
+ };
@@ -0,0 +1,16 @@
1
+ import { Observer } from "@vnejs/observer";
2
+ export const createTestModule = (ModuleClass, { subscribe = true, ...injectArg } = {}) => {
3
+ const observer = new Observer();
4
+ const state = (injectArg.state ?? {});
5
+ const module = new ModuleClass();
6
+ module.inject({
7
+ observer,
8
+ state,
9
+ shared: (injectArg.shared ?? {}),
10
+ media: injectArg.media ?? {},
11
+ ...injectArg,
12
+ });
13
+ if (subscribe)
14
+ module.subscribe();
15
+ return { module, observer, state };
16
+ };
@@ -0,0 +1,9 @@
1
+ export { createCoreGlobalState } from "./create-core-global-state.js";
2
+ export { createTestModule, type CreateTestModuleOptions, type TestModuleInstance } from "./harness.js";
3
+ export { registerCoreVne } from "./register-core-vne.js";
4
+ export { registerVnePlugin } from "./register-vne.js";
5
+ export { resetDom } from "./reset-dom.js";
6
+ export { spyEvent } from "./spy-event.js";
7
+ export { stubEvent, stubLogsEmit, stubVendorEvents } from "./stub-event.js";
8
+ export { mockFullscreen } from "./mocks/dom.js";
9
+ export { createLocalforageMock } from "./mocks/localforage.js";
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ export { createCoreGlobalState } from "./create-core-global-state.js";
2
+ export { createTestModule } from "./harness.js";
3
+ export { registerCoreVne } from "./register-core-vne.js";
4
+ export { registerVnePlugin } from "./register-vne.js";
5
+ export { resetDom } from "./reset-dom.js";
6
+ export { spyEvent } from "./spy-event.js";
7
+ export { stubEvent, stubLogsEmit, stubVendorEvents } from "./stub-event.js";
8
+ export { mockFullscreen } from "./mocks/dom.js";
9
+ export { createLocalforageMock } from "./mocks/localforage.js";
@@ -0,0 +1,9 @@
1
+ export type MockFullscreenOptions = {
2
+ fullscreenElement?: Element | null;
3
+ };
4
+ export declare const mockFullscreen: ({ fullscreenElement }?: MockFullscreenOptions) => {
5
+ requestFullscreen: () => Promise<undefined>;
6
+ exitFullscreen: () => Promise<undefined>;
7
+ getRequestCount: () => number;
8
+ getExitCount: () => number;
9
+ };
@@ -0,0 +1,21 @@
1
+ export const mockFullscreen = ({ fullscreenElement = null } = {}) => {
2
+ Object.defineProperty(document, "fullscreenElement", { value: fullscreenElement, configurable: true });
3
+ let requestCount = 0;
4
+ let exitCount = 0;
5
+ const requestFullscreen = () => {
6
+ requestCount += 1;
7
+ return Promise.resolve(undefined);
8
+ };
9
+ const exitFullscreen = () => {
10
+ exitCount += 1;
11
+ return Promise.resolve(undefined);
12
+ };
13
+ document.body.requestFullscreen = requestFullscreen;
14
+ document.exitFullscreen = exitFullscreen;
15
+ return {
16
+ requestFullscreen,
17
+ exitFullscreen,
18
+ getRequestCount: () => requestCount,
19
+ getExitCount: () => exitCount,
20
+ };
21
+ };
@@ -0,0 +1,11 @@
1
+ export declare const createLocalforageMock: (store?: Record<string, unknown>) => {
2
+ default: {
3
+ INDEXEDDB: number;
4
+ ready: (callback: () => void) => Promise<void>;
5
+ config: () => undefined;
6
+ getItem: (key: string) => Promise<{} | null>;
7
+ setItem: (key: string, value: unknown) => Promise<unknown>;
8
+ removeItem: (key: string) => Promise<void>;
9
+ keys: () => Promise<string[]>;
10
+ };
11
+ };
@@ -0,0 +1,20 @@
1
+ export const createLocalforageMock = (store = {}) => ({
2
+ default: {
3
+ INDEXEDDB: 0,
4
+ ready: (callback) => {
5
+ callback();
6
+ return Promise.resolve();
7
+ },
8
+ config: () => undefined,
9
+ getItem: (key) => Promise.resolve(store[key] ?? null),
10
+ setItem: (key, value) => {
11
+ store[key] = value;
12
+ return Promise.resolve(value);
13
+ },
14
+ removeItem: (key) => {
15
+ delete store[key];
16
+ return Promise.resolve();
17
+ },
18
+ keys: () => Promise.resolve(Object.keys(store)),
19
+ },
20
+ });
@@ -0,0 +1,2 @@
1
+ import type { VneNamespace } from "@vnejs/shared";
2
+ export declare const registerCoreVne: (namespaces?: VneNamespace[]) => void;
@@ -0,0 +1,35 @@
1
+ import { CONSTANTS as COMPONENTS_CONST, PLUGIN_NAME as COMPONENTS, SUBSCRIBE_EVENTS as COMPONENTS_EVENTS } from "@vnejs/contracts.core.components";
2
+ import { CONSTANTS as INTERACT_CONST, PLUGIN_NAME as INTERACT, SUBSCRIBE_EVENTS as INTERACT_EVENTS } from "@vnejs/contracts.core.interact";
3
+ import { CONSTANTS as LOGS_CONST, PLUGIN_NAME as LOGS, SETTINGS_KEYS as LOGS_SETTINGS, SUBSCRIBE_EVENTS as LOGS_EVENTS } from "@vnejs/contracts.core.logs";
4
+ import { PLUGIN_NAME as MEMORY, SUBSCRIBE_EVENTS as MEMORY_EVENTS } from "@vnejs/contracts.core.memory";
5
+ import { CONSTANTS as MEDIA_CONST, PLUGIN_NAME as MEDIA, SUBSCRIBE_EVENTS as MEDIA_EVENTS } from "@vnejs/contracts.core.media";
6
+ import { CONSTANTS as PLATFORMS_CONST, PARAMS as PLATFORMS_PARAMS, PLUGIN_NAME as PLATFORMS } from "@vnejs/contracts.core.platforms";
7
+ import { CONSTANTS as SCENARIO_CONST, PARAMS as SCENARIO_PARAMS, PLUGIN_NAME as SCENARIO, SUBSCRIBE_EVENTS as SCENARIO_EVENTS } from "@vnejs/contracts.core.scenario";
8
+ import { CONSTANTS as SETTINGS_CONST, PLUGIN_NAME as SETTINGS, SUBSCRIBE_EVENTS as SETTINGS_EVENTS } from "@vnejs/contracts.core.settings";
9
+ import { CONSTANTS as STACK_CONST, PLUGIN_NAME as STACK, SUBSCRIBE_EVENTS as STACK_EVENTS } from "@vnejs/contracts.core.stack";
10
+ import { CONSTANTS as STATE_CONST, PLUGIN_NAME as STATE, SUBSCRIBE_EVENTS as STATE_EVENTS } from "@vnejs/contracts.core.state";
11
+ import { PARAMS as STORAGE_PARAMS, PLUGIN_NAME as STORAGE, SUBSCRIBE_EVENTS as STORAGE_EVENTS } from "@vnejs/contracts.core.storage";
12
+ import { CONSTANTS as SYSTEM_CONST, PLUGIN_NAME as SYSTEM, SUBSCRIBE_EVENTS as SYSTEM_EVENTS } from "@vnejs/contracts.core.system";
13
+ import { PLUGIN_NAME as VENDORS, SUBSCRIBE_EVENTS as VENDORS_EVENTS } from "@vnejs/contracts.core.vendors";
14
+ import { registerVnePlugin } from "./register-vne.js";
15
+ const CORE_REGISTRATIONS = [
16
+ { namespace: SYSTEM, shape: { constants: SYSTEM_CONST, events: SYSTEM_EVENTS } },
17
+ { namespace: LOGS, shape: { constants: LOGS_CONST, events: LOGS_EVENTS, settings: LOGS_SETTINGS } },
18
+ { namespace: PLATFORMS, shape: { constants: PLATFORMS_CONST, params: PLATFORMS_PARAMS } },
19
+ { namespace: STORAGE, shape: { events: STORAGE_EVENTS, params: STORAGE_PARAMS } },
20
+ { namespace: MEMORY, shape: { events: MEMORY_EVENTS } },
21
+ { namespace: VENDORS, shape: { events: VENDORS_EVENTS } },
22
+ { namespace: COMPONENTS, shape: { constants: COMPONENTS_CONST, events: COMPONENTS_EVENTS } },
23
+ { namespace: INTERACT, shape: { constants: INTERACT_CONST, events: INTERACT_EVENTS } },
24
+ { namespace: MEDIA, shape: { constants: MEDIA_CONST, events: MEDIA_EVENTS } },
25
+ { namespace: SCENARIO, shape: { constants: SCENARIO_CONST, events: SCENARIO_EVENTS, params: SCENARIO_PARAMS } },
26
+ { namespace: SETTINGS, shape: { constants: SETTINGS_CONST, events: SETTINGS_EVENTS } },
27
+ { namespace: STACK, shape: { constants: STACK_CONST, events: STACK_EVENTS } },
28
+ { namespace: STATE, shape: { constants: STATE_CONST, events: STATE_EVENTS } },
29
+ ];
30
+ export const registerCoreVne = (namespaces) => {
31
+ for (const { namespace, shape } of CORE_REGISTRATIONS) {
32
+ if (!namespaces || namespaces.includes(namespace))
33
+ registerVnePlugin(namespace, shape);
34
+ }
35
+ };
@@ -0,0 +1,2 @@
1
+ import type { VneNamespace, VnePluginShape } from "@vnejs/shared";
2
+ export declare const registerVnePlugin: (namespace: VneNamespace, { constants, events, settings, params }?: VnePluginShape) => void;
@@ -0,0 +1,7 @@
1
+ import { VNE } from "@vnejs/shared";
2
+ export const registerVnePlugin = (namespace, { constants = {}, events = {}, settings = {}, params = {} } = {}) => {
3
+ VNE.EVENTS[namespace] = { ...events };
4
+ VNE.CONST[namespace] = { ...constants };
5
+ VNE.SETTINGS[namespace] = { ...settings };
6
+ VNE.PARAMS[namespace] = { ...params };
7
+ };
@@ -0,0 +1 @@
1
+ export declare const resetDom: () => void;
@@ -0,0 +1,4 @@
1
+ export const resetDom = () => {
2
+ document.body.innerHTML = "";
3
+ document.head.innerHTML = "";
4
+ };
@@ -0,0 +1,7 @@
1
+ import type { Observer } from "@vnejs/observer";
2
+ export declare const spyEvent: (observer: Observer, event: string) => {
3
+ calls: unknown[][];
4
+ count: () => number;
5
+ last: () => unknown[] | undefined;
6
+ first: () => unknown[];
7
+ };
@@ -0,0 +1,12 @@
1
+ export const spyEvent = (observer, event) => {
2
+ const calls = [];
3
+ observer.subscribe(event, (...args) => {
4
+ calls.push(args);
5
+ });
6
+ return {
7
+ calls,
8
+ count: () => calls.length,
9
+ last: () => calls.at(-1),
10
+ first: () => calls[0],
11
+ };
12
+ };
@@ -0,0 +1,4 @@
1
+ import type { Observer } from "@vnejs/observer";
2
+ export declare const stubEvent: (observer: Observer, event: string, handler?: (...args: unknown[]) => unknown) => void;
3
+ export declare const stubLogsEmit: (observer: Observer) => void;
4
+ export declare const stubVendorEvents: (observer: Observer) => void;
@@ -0,0 +1,10 @@
1
+ import { SUBSCRIBE_EVENTS as LOGS_EVENTS } from "@vnejs/contracts.core.logs";
2
+ import { SUBSCRIBE_EVENTS as VENDORS_EVENTS } from "@vnejs/contracts.core.vendors";
3
+ export const stubEvent = (observer, event, handler = () => undefined) => {
4
+ observer.subscribe(event, handler);
5
+ };
6
+ export const stubLogsEmit = (observer) => stubEvent(observer, LOGS_EVENTS.EMIT);
7
+ export const stubVendorEvents = (observer) => {
8
+ stubEvent(observer, VENDORS_EVENTS.UID, () => "test-uid");
9
+ stubEvent(observer, VENDORS_EVENTS.CLONE, (value) => structuredClone(value));
10
+ };
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@vnejs/test-utils",
3
+ "version": "0.1.1",
4
+ "description": "Test harness utilities for @vnejs plugin modules",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js",
11
+ "require": "./dist/index.js",
12
+ "default": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "src",
18
+ "tsconfig.json"
19
+ ],
20
+ "scripts": {
21
+ "test": "echo \"Error: no test specified\" && exit 1",
22
+ "build": "npx @vnejs/monorepo package",
23
+ "publish:major": "npx @vnejs/monorepo publish major --access public",
24
+ "publish:minor": "npx @vnejs/monorepo publish minor --access public",
25
+ "publish:patch": "npx @vnejs/monorepo publish patch --access public"
26
+ },
27
+ "license": "ISC",
28
+ "dependencies": {
29
+ "@vnejs/observer": "~0.1.0",
30
+ "@vnejs/shared": "~0.1.0"
31
+ },
32
+ "peerDependencies": {
33
+ "@vnejs/module": "~0.1.0"
34
+ },
35
+ "devDependencies": {
36
+ "@vnejs/configs.ts-common": "~0.1.0",
37
+ "@vnejs/contracts.core.components": "~0.1.0",
38
+ "@vnejs/contracts.core.interact": "~0.1.0",
39
+ "@vnejs/contracts.core.logs": "~0.1.0",
40
+ "@vnejs/contracts.core.media": "~0.1.0",
41
+ "@vnejs/contracts.core.memory": "~0.1.0",
42
+ "@vnejs/contracts.core.platforms": "~0.1.0",
43
+ "@vnejs/contracts.core.scenario": "~0.1.0",
44
+ "@vnejs/contracts.core.settings": "~0.1.0",
45
+ "@vnejs/contracts.core.stack": "~0.1.0",
46
+ "@vnejs/contracts.core.state": "~0.1.0",
47
+ "@vnejs/contracts.core.storage": "~0.1.0",
48
+ "@vnejs/contracts.core.system": "~0.1.0",
49
+ "@vnejs/contracts.core.vendors": "~0.1.0",
50
+ "@vnejs/module": "~0.1.0"
51
+ }
52
+ }
@@ -0,0 +1,8 @@
1
+ import { DEFAULT_MODULE_GLOBAL_STATE_SCENARIO } from "@vnejs/contracts.core.scenario";
2
+ import { DEFAULT_MODULE_GLOBAL_STATE_STACK } from "@vnejs/contracts.core.stack";
3
+
4
+ export const createCoreGlobalState = (overrides: Record<string, unknown> = {}) => ({
5
+ stack: structuredClone(DEFAULT_MODULE_GLOBAL_STATE_STACK),
6
+ scenario: structuredClone(DEFAULT_MODULE_GLOBAL_STATE_SCENARIO),
7
+ ...overrides,
8
+ });
package/src/harness.ts ADDED
@@ -0,0 +1,33 @@
1
+ import type { ModuleGlobalStateRegistry, ModuleInject, ModuleShared } from "@vnejs/module";
2
+ import { Observer } from "@vnejs/observer";
3
+
4
+ export type TestModuleInstance = {
5
+ name: string;
6
+ inject: (arg?: ModuleInject) => void;
7
+ subscribe: () => void;
8
+ observer?: Observer;
9
+ };
10
+
11
+ export type CreateTestModuleOptions = Partial<ModuleInject> & {
12
+ subscribe?: boolean;
13
+ };
14
+
15
+ export const createTestModule = <T extends TestModuleInstance>(
16
+ ModuleClass: new () => T,
17
+ { subscribe = true, ...injectArg }: CreateTestModuleOptions = {},
18
+ ) => {
19
+ const observer = new Observer();
20
+ const state = (injectArg.state ?? {}) as ModuleGlobalStateRegistry;
21
+ const module = new ModuleClass();
22
+
23
+ module.inject({
24
+ observer,
25
+ state,
26
+ shared: (injectArg.shared ?? {}) as ModuleShared,
27
+ media: injectArg.media ?? {},
28
+ ...injectArg,
29
+ });
30
+ if (subscribe) module.subscribe();
31
+
32
+ return { module, observer, state };
33
+ };
package/src/index.ts ADDED
@@ -0,0 +1,9 @@
1
+ export { createCoreGlobalState } from "./create-core-global-state.js";
2
+ export { createTestModule, type CreateTestModuleOptions, type TestModuleInstance } from "./harness.js";
3
+ export { registerCoreVne } from "./register-core-vne.js";
4
+ export { registerVnePlugin } from "./register-vne.js";
5
+ export { resetDom } from "./reset-dom.js";
6
+ export { spyEvent } from "./spy-event.js";
7
+ export { stubEvent, stubLogsEmit, stubVendorEvents } from "./stub-event.js";
8
+ export { mockFullscreen } from "./mocks/dom.js";
9
+ export { createLocalforageMock } from "./mocks/localforage.js";
@@ -0,0 +1,30 @@
1
+ export type MockFullscreenOptions = {
2
+ fullscreenElement?: Element | null;
3
+ };
4
+
5
+ export const mockFullscreen = ({ fullscreenElement = null }: MockFullscreenOptions = {}) => {
6
+ Object.defineProperty(document, "fullscreenElement", { value: fullscreenElement, configurable: true });
7
+
8
+ let requestCount = 0;
9
+ let exitCount = 0;
10
+
11
+ const requestFullscreen = () => {
12
+ requestCount += 1;
13
+ return Promise.resolve(undefined);
14
+ };
15
+
16
+ const exitFullscreen = () => {
17
+ exitCount += 1;
18
+ return Promise.resolve(undefined);
19
+ };
20
+
21
+ document.body.requestFullscreen = requestFullscreen;
22
+ document.exitFullscreen = exitFullscreen;
23
+
24
+ return {
25
+ requestFullscreen,
26
+ exitFullscreen,
27
+ getRequestCount: () => requestCount,
28
+ getExitCount: () => exitCount,
29
+ };
30
+ };
@@ -0,0 +1,20 @@
1
+ export const createLocalforageMock = (store: Record<string, unknown> = {}) => ({
2
+ default: {
3
+ INDEXEDDB: 0,
4
+ ready: (callback: () => void) => {
5
+ callback();
6
+ return Promise.resolve();
7
+ },
8
+ config: () => undefined,
9
+ getItem: (key: string) => Promise.resolve(store[key] ?? null),
10
+ setItem: (key: string, value: unknown) => {
11
+ store[key] = value;
12
+ return Promise.resolve(value);
13
+ },
14
+ removeItem: (key: string) => {
15
+ delete store[key];
16
+ return Promise.resolve();
17
+ },
18
+ keys: () => Promise.resolve(Object.keys(store)),
19
+ },
20
+ });
@@ -0,0 +1,41 @@
1
+ import type { VneNamespace, VnePluginShape } from "@vnejs/shared";
2
+
3
+ import { CONSTANTS as COMPONENTS_CONST, PLUGIN_NAME as COMPONENTS, SUBSCRIBE_EVENTS as COMPONENTS_EVENTS } from "@vnejs/contracts.core.components";
4
+ import { CONSTANTS as INTERACT_CONST, PLUGIN_NAME as INTERACT, SUBSCRIBE_EVENTS as INTERACT_EVENTS } from "@vnejs/contracts.core.interact";
5
+ import { CONSTANTS as LOGS_CONST, PLUGIN_NAME as LOGS, SETTINGS_KEYS as LOGS_SETTINGS, SUBSCRIBE_EVENTS as LOGS_EVENTS } from "@vnejs/contracts.core.logs";
6
+ import { PLUGIN_NAME as MEMORY, SUBSCRIBE_EVENTS as MEMORY_EVENTS } from "@vnejs/contracts.core.memory";
7
+ import { CONSTANTS as MEDIA_CONST, PLUGIN_NAME as MEDIA, SUBSCRIBE_EVENTS as MEDIA_EVENTS } from "@vnejs/contracts.core.media";
8
+ import { CONSTANTS as PLATFORMS_CONST, PARAMS as PLATFORMS_PARAMS, PLUGIN_NAME as PLATFORMS } from "@vnejs/contracts.core.platforms";
9
+ import { CONSTANTS as SCENARIO_CONST, PARAMS as SCENARIO_PARAMS, PLUGIN_NAME as SCENARIO, SUBSCRIBE_EVENTS as SCENARIO_EVENTS } from "@vnejs/contracts.core.scenario";
10
+ import { CONSTANTS as SETTINGS_CONST, PLUGIN_NAME as SETTINGS, SUBSCRIBE_EVENTS as SETTINGS_EVENTS } from "@vnejs/contracts.core.settings";
11
+ import { CONSTANTS as STACK_CONST, PLUGIN_NAME as STACK, SUBSCRIBE_EVENTS as STACK_EVENTS } from "@vnejs/contracts.core.stack";
12
+ import { CONSTANTS as STATE_CONST, PLUGIN_NAME as STATE, SUBSCRIBE_EVENTS as STATE_EVENTS } from "@vnejs/contracts.core.state";
13
+ import { PARAMS as STORAGE_PARAMS, PLUGIN_NAME as STORAGE, SUBSCRIBE_EVENTS as STORAGE_EVENTS } from "@vnejs/contracts.core.storage";
14
+ import { CONSTANTS as SYSTEM_CONST, PLUGIN_NAME as SYSTEM, SUBSCRIBE_EVENTS as SYSTEM_EVENTS } from "@vnejs/contracts.core.system";
15
+ import { PLUGIN_NAME as VENDORS, SUBSCRIBE_EVENTS as VENDORS_EVENTS } from "@vnejs/contracts.core.vendors";
16
+
17
+ import { registerVnePlugin } from "./register-vne.js";
18
+
19
+ type CoreRegistration = { namespace: VneNamespace; shape: VnePluginShape };
20
+
21
+ const CORE_REGISTRATIONS: CoreRegistration[] = [
22
+ { namespace: SYSTEM, shape: { constants: SYSTEM_CONST, events: SYSTEM_EVENTS } },
23
+ { namespace: LOGS, shape: { constants: LOGS_CONST, events: LOGS_EVENTS, settings: LOGS_SETTINGS } },
24
+ { namespace: PLATFORMS, shape: { constants: PLATFORMS_CONST, params: PLATFORMS_PARAMS } },
25
+ { namespace: STORAGE, shape: { events: STORAGE_EVENTS, params: STORAGE_PARAMS } },
26
+ { namespace: MEMORY, shape: { events: MEMORY_EVENTS } },
27
+ { namespace: VENDORS, shape: { events: VENDORS_EVENTS } },
28
+ { namespace: COMPONENTS, shape: { constants: COMPONENTS_CONST, events: COMPONENTS_EVENTS } },
29
+ { namespace: INTERACT, shape: { constants: INTERACT_CONST, events: INTERACT_EVENTS } },
30
+ { namespace: MEDIA, shape: { constants: MEDIA_CONST, events: MEDIA_EVENTS } },
31
+ { namespace: SCENARIO, shape: { constants: SCENARIO_CONST, events: SCENARIO_EVENTS, params: SCENARIO_PARAMS } },
32
+ { namespace: SETTINGS, shape: { constants: SETTINGS_CONST, events: SETTINGS_EVENTS } },
33
+ { namespace: STACK, shape: { constants: STACK_CONST, events: STACK_EVENTS } },
34
+ { namespace: STATE, shape: { constants: STATE_CONST, events: STATE_EVENTS } },
35
+ ];
36
+
37
+ export const registerCoreVne = (namespaces?: VneNamespace[]) => {
38
+ for (const { namespace, shape } of CORE_REGISTRATIONS) {
39
+ if (!namespaces || namespaces.includes(namespace)) registerVnePlugin(namespace, shape);
40
+ }
41
+ };
@@ -0,0 +1,12 @@
1
+ import { VNE } from "@vnejs/shared";
2
+ import type { VneNamespace, VnePluginShape } from "@vnejs/shared";
3
+
4
+ export const registerVnePlugin = (
5
+ namespace: VneNamespace,
6
+ { constants = {}, events = {}, settings = {}, params = {} }: VnePluginShape = {},
7
+ ) => {
8
+ (VNE.EVENTS as Record<string, unknown>)[namespace] = { ...events };
9
+ (VNE.CONST as Record<string, unknown>)[namespace] = { ...constants };
10
+ (VNE.SETTINGS as Record<string, unknown>)[namespace] = { ...settings };
11
+ (VNE.PARAMS as Record<string, unknown>)[namespace] = { ...params };
12
+ };
@@ -0,0 +1,4 @@
1
+ export const resetDom = () => {
2
+ document.body.innerHTML = "";
3
+ document.head.innerHTML = "";
4
+ };
@@ -0,0 +1,16 @@
1
+ import type { Observer } from "@vnejs/observer";
2
+
3
+ export const spyEvent = (observer: Observer, event: string) => {
4
+ const calls: unknown[][] = [];
5
+
6
+ observer.subscribe(event, (...args: unknown[]) => {
7
+ calls.push(args);
8
+ });
9
+
10
+ return {
11
+ calls,
12
+ count: () => calls.length,
13
+ last: () => calls.at(-1),
14
+ first: () => calls[0],
15
+ };
16
+ };
@@ -0,0 +1,18 @@
1
+ import { SUBSCRIBE_EVENTS as LOGS_EVENTS } from "@vnejs/contracts.core.logs";
2
+ import { SUBSCRIBE_EVENTS as VENDORS_EVENTS } from "@vnejs/contracts.core.vendors";
3
+ import type { Observer } from "@vnejs/observer";
4
+
5
+ export const stubEvent = (
6
+ observer: Observer,
7
+ event: string,
8
+ handler: (...args: unknown[]) => unknown = () => undefined,
9
+ ) => {
10
+ observer.subscribe(event, handler);
11
+ };
12
+
13
+ export const stubLogsEmit = (observer: Observer) => stubEvent(observer, LOGS_EVENTS.EMIT);
14
+
15
+ export const stubVendorEvents = (observer: Observer) => {
16
+ stubEvent(observer, VENDORS_EVENTS.UID, () => "test-uid");
17
+ stubEvent(observer, VENDORS_EVENTS.CLONE, (value) => structuredClone(value));
18
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "@vnejs/configs.ts-common/tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src",
5
+ "outDir": "dist"
6
+ },
7
+ "include": ["src/**/*.ts"],
8
+ "exclude": ["dist", "node_modules"]
9
+ }