@lynn123411/dsh-kimi-cu 0.3.3 → 0.3.4
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 +1 -1
- package/scripts/smoke-client.mjs +18 -23
package/package.json
CHANGED
package/scripts/smoke-client.mjs
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* 跑法:pnpm test / node scripts/smoke-client.mjs
|
|
7
7
|
*/
|
|
8
8
|
import { fileURLToPath } from 'node:url';
|
|
9
|
+
import { JSDOM } from 'jsdom';
|
|
9
10
|
import { dirname, join, resolve } from 'node:path';
|
|
10
11
|
|
|
11
12
|
import { loadClientBundle } from './lib/client-bundle.mjs';
|
|
@@ -19,34 +20,15 @@ const check = (label, ok) => {
|
|
|
19
20
|
else { console.error(' FAIL ' + label); failures.push(label); }
|
|
20
21
|
};
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
dataset: {}, style: {}, appendChild() {}, remove() {}, setAttribute() {},
|
|
25
|
-
addEventListener() {}, removeEventListener() {}, classList: { add() {}, remove() {} },
|
|
26
|
-
};
|
|
27
|
-
const appendedStyles = [];
|
|
28
|
-
globalThis.document = {
|
|
29
|
-
...stubElement,
|
|
30
|
-
documentElement: stubElement,
|
|
31
|
-
body: stubElement,
|
|
32
|
-
head: {
|
|
33
|
-
...stubElement,
|
|
34
|
-
appendChild: (node) => { appendedStyles.push(node); },
|
|
35
|
-
querySelector: () => null,
|
|
36
|
-
querySelectorAll: () => [],
|
|
37
|
-
},
|
|
38
|
-
createElement: () => ({ ...stubElement, id: '', textContent: '' }),
|
|
39
|
-
createTextNode: () => ({}),
|
|
40
|
-
getElementById: () => null,
|
|
41
|
-
querySelector: () => null,
|
|
42
|
-
querySelectorAll: () => [],
|
|
43
|
-
};
|
|
23
|
+
const dom = new JSDOM();
|
|
24
|
+
globalThis.document = dom.window.document;
|
|
44
25
|
|
|
45
26
|
const { exported, requires } = await loadClientBundle(root);
|
|
46
27
|
|
|
47
28
|
const locales = [];
|
|
48
29
|
const registrations = [];
|
|
49
30
|
const errors = [];
|
|
31
|
+
const effects = [];
|
|
50
32
|
|
|
51
33
|
/** cordis 忠实的上下文:读未声明的服务抛 cannot get property "x" without inject。 */
|
|
52
34
|
function makeCtx(label, declared = []) {
|
|
@@ -72,7 +54,11 @@ function makeCtx(label, declared = []) {
|
|
|
72
54
|
};
|
|
73
55
|
const base = {
|
|
74
56
|
label,
|
|
75
|
-
effect: (fn) => {
|
|
57
|
+
effect: (fn) => {
|
|
58
|
+
const dispose = fn();
|
|
59
|
+
if (typeof dispose === 'function') effects.push(dispose);
|
|
60
|
+
return dispose;
|
|
61
|
+
},
|
|
76
62
|
inject: () => () => {},
|
|
77
63
|
get: (name) => table[name],
|
|
78
64
|
};
|
|
@@ -117,6 +103,15 @@ check('状态卡注册在 plugins.bundle.config 且 key 是包名', card?.option
|
|
|
117
103
|
check('状态卡带本插件的字典命名空间', card?.options?.locale === 'kimiCu');
|
|
118
104
|
check('状态卡组件是个函数', typeof card?.component === 'function');
|
|
119
105
|
|
|
106
|
+
const pluginStyles = () => document.head.querySelectorAll(`style[data-plugin="${pkgName}"]`);
|
|
107
|
+
check('启用后挂载插件样式', pluginStyles().length === 1);
|
|
108
|
+
for (const dispose of effects.splice(0).reverse()) dispose();
|
|
109
|
+
check('停用后不残留插件样式', pluginStyles().length === 0);
|
|
110
|
+
exported.apply(makeCtx('restarted', exported.inject ?? []));
|
|
111
|
+
check('重新启用后每张样式各有一份', pluginStyles().length === 1);
|
|
112
|
+
for (const dispose of effects.splice(0).reverse()) dispose();
|
|
113
|
+
dom.window.close();
|
|
114
|
+
|
|
120
115
|
check('apply 期间没有接线错误', errors.length === 0);
|
|
121
116
|
for (const error of errors) console.error(' ' + error);
|
|
122
117
|
|