@thelacanians/vue-native-runtime 0.4.13 → 0.4.15
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/dist/index.cjs +474 -162
- package/dist/index.d.cts +299 -25
- package/dist/index.d.ts +299 -25
- package/dist/index.js +443 -128
- package/dist/testing.cjs +63 -0
- package/dist/testing.d.cts +42 -0
- package/dist/testing.d.ts +42 -0
- package/dist/testing.js +37 -0
- package/package.json +8 -3
package/dist/testing.cjs
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/testing.ts
|
|
21
|
+
var testing_exports = {};
|
|
22
|
+
__export(testing_exports, {
|
|
23
|
+
installMockBridge: () => installMockBridge,
|
|
24
|
+
nextTick: () => nextTick
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(testing_exports);
|
|
27
|
+
function installMockBridge() {
|
|
28
|
+
const ops = [];
|
|
29
|
+
globalThis.__VN_flushOperations = (json) => {
|
|
30
|
+
const parsed = JSON.parse(json);
|
|
31
|
+
ops.push(...parsed);
|
|
32
|
+
};
|
|
33
|
+
globalThis.__VN_handleEvent = (..._args) => {
|
|
34
|
+
};
|
|
35
|
+
globalThis.__VN_resolveCallback = (..._args) => {
|
|
36
|
+
};
|
|
37
|
+
globalThis.__VN_handleGlobalEvent = (..._args) => {
|
|
38
|
+
};
|
|
39
|
+
globalThis.__DEV__ = true;
|
|
40
|
+
function getOps() {
|
|
41
|
+
return [...ops];
|
|
42
|
+
}
|
|
43
|
+
function getOpsByType(type) {
|
|
44
|
+
return ops.filter((o) => o.op === type);
|
|
45
|
+
}
|
|
46
|
+
function reset() {
|
|
47
|
+
ops.length = 0;
|
|
48
|
+
}
|
|
49
|
+
function flush() {
|
|
50
|
+
return new Promise((resolve) => setTimeout(resolve, 0));
|
|
51
|
+
}
|
|
52
|
+
return { getOps, getOpsByType, reset, flush };
|
|
53
|
+
}
|
|
54
|
+
async function nextTick() {
|
|
55
|
+
await Promise.resolve();
|
|
56
|
+
await Promise.resolve();
|
|
57
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
58
|
+
}
|
|
59
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
60
|
+
0 && (module.exports = {
|
|
61
|
+
installMockBridge,
|
|
62
|
+
nextTick
|
|
63
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @thelacanians/vue-native-runtime/testing
|
|
3
|
+
*
|
|
4
|
+
* Test utilities for Vue Native applications. Import from
|
|
5
|
+
* '@thelacanians/vue-native-runtime/testing' to set up a mock bridge
|
|
6
|
+
* for unit testing without a native runtime.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { installMockBridge, nextTick } from '@thelacanians/vue-native-runtime/testing'
|
|
11
|
+
*
|
|
12
|
+
* const { getOps, getOpsByType, reset, flush } = installMockBridge()
|
|
13
|
+
*
|
|
14
|
+
* // ... create app, interact with components ...
|
|
15
|
+
*
|
|
16
|
+
* const createOps = getOpsByType('create')
|
|
17
|
+
* expect(createOps.length).toBeGreaterThan(0)
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
interface CapturedOperation {
|
|
21
|
+
op: string;
|
|
22
|
+
args: any[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Install a mock __VN_flushOperations that captures all bridge operations.
|
|
26
|
+
* Returns helpers to inspect and reset captured operations.
|
|
27
|
+
*
|
|
28
|
+
* Call this before creating your Vue Native app in tests.
|
|
29
|
+
*/
|
|
30
|
+
declare function installMockBridge(): {
|
|
31
|
+
getOps: () => CapturedOperation[];
|
|
32
|
+
getOpsByType: (type: string) => CapturedOperation[];
|
|
33
|
+
reset: () => void;
|
|
34
|
+
flush: () => Promise<void>;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Wait for the microtask queue and any pending bridge flushes to complete.
|
|
38
|
+
* Useful after triggering state changes to ensure all bridge operations have fired.
|
|
39
|
+
*/
|
|
40
|
+
declare function nextTick(): Promise<void>;
|
|
41
|
+
|
|
42
|
+
export { type CapturedOperation, installMockBridge, nextTick };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @thelacanians/vue-native-runtime/testing
|
|
3
|
+
*
|
|
4
|
+
* Test utilities for Vue Native applications. Import from
|
|
5
|
+
* '@thelacanians/vue-native-runtime/testing' to set up a mock bridge
|
|
6
|
+
* for unit testing without a native runtime.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { installMockBridge, nextTick } from '@thelacanians/vue-native-runtime/testing'
|
|
11
|
+
*
|
|
12
|
+
* const { getOps, getOpsByType, reset, flush } = installMockBridge()
|
|
13
|
+
*
|
|
14
|
+
* // ... create app, interact with components ...
|
|
15
|
+
*
|
|
16
|
+
* const createOps = getOpsByType('create')
|
|
17
|
+
* expect(createOps.length).toBeGreaterThan(0)
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
interface CapturedOperation {
|
|
21
|
+
op: string;
|
|
22
|
+
args: any[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Install a mock __VN_flushOperations that captures all bridge operations.
|
|
26
|
+
* Returns helpers to inspect and reset captured operations.
|
|
27
|
+
*
|
|
28
|
+
* Call this before creating your Vue Native app in tests.
|
|
29
|
+
*/
|
|
30
|
+
declare function installMockBridge(): {
|
|
31
|
+
getOps: () => CapturedOperation[];
|
|
32
|
+
getOpsByType: (type: string) => CapturedOperation[];
|
|
33
|
+
reset: () => void;
|
|
34
|
+
flush: () => Promise<void>;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Wait for the microtask queue and any pending bridge flushes to complete.
|
|
38
|
+
* Useful after triggering state changes to ensure all bridge operations have fired.
|
|
39
|
+
*/
|
|
40
|
+
declare function nextTick(): Promise<void>;
|
|
41
|
+
|
|
42
|
+
export { type CapturedOperation, installMockBridge, nextTick };
|
package/dist/testing.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// src/testing.ts
|
|
2
|
+
function installMockBridge() {
|
|
3
|
+
const ops = [];
|
|
4
|
+
globalThis.__VN_flushOperations = (json) => {
|
|
5
|
+
const parsed = JSON.parse(json);
|
|
6
|
+
ops.push(...parsed);
|
|
7
|
+
};
|
|
8
|
+
globalThis.__VN_handleEvent = (..._args) => {
|
|
9
|
+
};
|
|
10
|
+
globalThis.__VN_resolveCallback = (..._args) => {
|
|
11
|
+
};
|
|
12
|
+
globalThis.__VN_handleGlobalEvent = (..._args) => {
|
|
13
|
+
};
|
|
14
|
+
globalThis.__DEV__ = true;
|
|
15
|
+
function getOps() {
|
|
16
|
+
return [...ops];
|
|
17
|
+
}
|
|
18
|
+
function getOpsByType(type) {
|
|
19
|
+
return ops.filter((o) => o.op === type);
|
|
20
|
+
}
|
|
21
|
+
function reset() {
|
|
22
|
+
ops.length = 0;
|
|
23
|
+
}
|
|
24
|
+
function flush() {
|
|
25
|
+
return new Promise((resolve) => setTimeout(resolve, 0));
|
|
26
|
+
}
|
|
27
|
+
return { getOps, getOpsByType, reset, flush };
|
|
28
|
+
}
|
|
29
|
+
async function nextTick() {
|
|
30
|
+
await Promise.resolve();
|
|
31
|
+
await Promise.resolve();
|
|
32
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
33
|
+
}
|
|
34
|
+
export {
|
|
35
|
+
installMockBridge,
|
|
36
|
+
nextTick
|
|
37
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thelacanians/vue-native-runtime",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.15",
|
|
4
4
|
"description": "Vue 3 custom renderer for native iOS and Android apps",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Vue Native Contributors",
|
|
@@ -21,12 +21,17 @@
|
|
|
21
21
|
"types": "./dist/index.d.ts",
|
|
22
22
|
"import": "./dist/index.js",
|
|
23
23
|
"require": "./dist/index.cjs"
|
|
24
|
+
},
|
|
25
|
+
"./testing": {
|
|
26
|
+
"types": "./dist/testing.d.ts",
|
|
27
|
+
"import": "./dist/testing.js",
|
|
28
|
+
"require": "./dist/testing.cjs"
|
|
24
29
|
}
|
|
25
30
|
},
|
|
26
31
|
"files": ["dist", "README.md"],
|
|
27
32
|
"scripts": {
|
|
28
|
-
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
29
|
-
"dev": "tsup src/index.ts --format esm,cjs --dts --watch",
|
|
33
|
+
"build": "tsup src/index.ts src/testing.ts --format esm,cjs --dts",
|
|
34
|
+
"dev": "tsup src/index.ts src/testing.ts --format esm,cjs --dts --watch",
|
|
30
35
|
"test": "vitest run",
|
|
31
36
|
"test:watch": "vitest",
|
|
32
37
|
"test:coverage": "vitest run --coverage",
|