Skip to content

Commit 349613e

Browse files
committed
🧪 修复测试脚本同步问题
1 parent 2769a24 commit 349613e

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

example/tests/early_inject_content_test.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,21 @@
6363
// ============ 早期脚本环境检查 ============
6464
console.log("\n%c--- 早期脚本环境检查 ---", "color: orange; font-weight: bold;");
6565

66-
test("检查 document.head 不存在", () => {
66+
await test("检查 document.head 不存在", () => {
6767
console.log("document.head 存在:", !!document.head);
6868
console.log("document.head 值:", document.head);
6969
// 早期脚本运行时 document.head 应该不存在
7070
assertTrue(document.head === null || document.head === undefined, "早期脚本运行时 document.head 应该不存在");
7171
});
7272

73-
test("检查 document.body 不存在", () => {
73+
await test("检查 document.body 不存在", () => {
7474
console.log("document.body 存在:", !!document.body);
7575
console.log("document.body 值:", document.body);
7676
// 早期脚本运行时 document.body 应该不存在
7777
assertTrue(document.body === null || document.body === undefined, "早期脚本运行时 document.body 应该不存在");
7878
});
7979

80-
test("检查可用的DOM节点应该是HTML元素", () => {
80+
await test("检查可用的DOM节点应该是HTML元素", () => {
8181
const firstElement = document.querySelector("*");
8282
console.log("querySelector('*') 找到的第一个元素:", firstElement?.tagName);
8383
assertTrue(firstElement !== null, "应该能找到第一个DOM节点");
@@ -94,7 +94,7 @@
9494
// ============ CSP绕过测试 ============
9595
console.log("\n%c--- CSP绕过测试 ---", "color: orange; font-weight: bold;");
9696

97-
test("CSP绕过 - 内联脚本", () => {
97+
await test("CSP绕过 - 内联脚本", () => {
9898
const script = document.createElement("script");
9999
script.textContent = 'console.log("Content环境绕过CSP测试");';
100100
// 早期脚本运行时 document.head 和 document.body 不存在
@@ -110,7 +110,7 @@
110110
// ============ GM_addElement/GM_addStyle 测试 ============
111111
console.log("\n%c--- DOM操作 API 测试 ---", "color: orange; font-weight: bold;");
112112

113-
test("GM_addElement", () => {
113+
await test("GM_addElement", () => {
114114
const element = GM_addElement("div", {
115115
textContent: "GM_addElement测试元素",
116116
style: "display:none;",
@@ -122,7 +122,7 @@
122122
console.log("返回元素:", element);
123123
});
124124

125-
test("GM_addStyle", () => {
125+
await test("GM_addStyle", () => {
126126
const styleElement = GM_addStyle(`
127127
.gm-style-test {
128128
color: #10b981 !important;
@@ -136,7 +136,7 @@
136136
// ============ GM_log 测试 ============
137137
console.log("\n%c--- GM_log 测试 ---", "color: orange; font-weight: bold;");
138138

139-
test("GM_log", () => {
139+
await test("GM_log", () => {
140140
GM_log("测试日志输出", { type: "test", value: 123 });
141141
// GM_log本身不返回值,只要不抛出异常就算成功
142142
assertTrue(true, "GM_log应该能正常输出");
@@ -145,7 +145,7 @@
145145
// ============ GM_info 测试 ============
146146
console.log("\n%c--- GM_info 测试 ---", "color: orange; font-weight: bold;");
147147

148-
test("GM_info", () => {
148+
await test("GM_info", () => {
149149
assertTrue(typeof GM_info === "object", "GM_info应该是对象");
150150
assertTrue(!!GM_info.script, "GM_info.script应该存在");
151151
assertTrue(!!GM_info.script.name, "GM_info.script.name应该存在");
@@ -161,33 +161,33 @@
161161
assert("content环境测试值", value, "应该正确保存和读取字符串");
162162
});
163163

164-
test("GM_setValue - 数字", () => {
164+
await test("GM_setValue - 数字", () => {
165165
GM_setValue("test_number", 12345);
166166
const value = GM_getValue("test_number");
167167
assert(12345, value, "应该正确保存和读取数字");
168168
});
169169

170-
test("GM_setValue - 对象", () => {
170+
await test("GM_setValue - 对象", () => {
171171
const obj = { name: "ScriptCat", type: "content" };
172172
GM_setValue("test_object", obj);
173173
const value = GM_getValue("test_object", {});
174174
assert("ScriptCat", value.name, "对象的name属性应该正确");
175175
assert("content", value.type, "对象的type属性应该正确");
176176
});
177177

178-
test("GM_getValue - 默认值", () => {
178+
await test("GM_getValue - 默认值", () => {
179179
const value = GM_getValue("non_existent_key", "默认值");
180180
assert("默认值", value, "不存在的键应该返回默认值");
181181
});
182182

183-
test("GM_listValues", () => {
183+
await test("GM_listValues", () => {
184184
const keys = GM_listValues();
185185
assertTrue(Array.isArray(keys), "GM_listValues应该返回数组");
186186
assertTrue(keys.length >= 3, "应该至少有3个存储键");
187187
console.log("存储的键:", keys);
188188
});
189189

190-
test("GM_deleteValue", () => {
190+
await test("GM_deleteValue", () => {
191191
GM_setValue("test_delete", "to_be_deleted");
192192
assert("to_be_deleted", GM_getValue("test_delete"), "值应该存在");
193193
GM_deleteValue("test_delete");

example/tests/inject_content_test.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
// ============ CSP绕过测试 ============
6363
console.log("\n%c--- CSP绕过测试 ---", "color: orange; font-weight: bold;");
6464

65-
test("CSP绕过 - 内联脚本", () => {
65+
await test("CSP绕过 - 内联脚本", () => {
6666
const script = document.createElement("script");
6767
script.textContent = 'console.log("Content环境绕过CSP测试");';
6868
document.head.appendChild(script);
@@ -72,7 +72,7 @@
7272
// ============ GM_addElement/GM_addStyle 测试 ============
7373
console.log("\n%c--- DOM操作 API 测试 ---", "color: orange; font-weight: bold;");
7474

75-
test("GM_addElement", () => {
75+
await test("GM_addElement", () => {
7676
const element = GM_addElement("div", {
7777
textContent: "GM_addElement测试元素",
7878
style: "display:none;",
@@ -84,7 +84,7 @@
8484
console.log("返回元素:", element);
8585
});
8686

87-
test("GM_addStyle", () => {
87+
await test("GM_addStyle", () => {
8888
const styleElement = GM_addStyle(`
8989
.gm-style-test {
9090
color: #10b981 !important;
@@ -98,7 +98,7 @@
9898
// ============ GM_log 测试 ============
9999
console.log("\n%c--- GM_log 测试 ---", "color: orange; font-weight: bold;");
100100

101-
test("GM_log", () => {
101+
await test("GM_log", () => {
102102
GM_log("测试日志输出", { type: "test", value: 123 });
103103
// GM_log本身不返回值,只要不抛出异常就算成功
104104
assertTrue(true, "GM_log应该能正常输出");
@@ -107,7 +107,7 @@
107107
// ============ GM_info 测试 ============
108108
console.log("\n%c--- GM_info 测试 ---", "color: orange; font-weight: bold;");
109109

110-
test("GM_info", () => {
110+
await test("GM_info", () => {
111111
assertTrue(typeof GM_info === "object", "GM_info应该是对象");
112112
assertTrue(!!GM_info.script, "GM_info.script应该存在");
113113
assertTrue(!!GM_info.script.name, "GM_info.script.name应该存在");
@@ -123,33 +123,33 @@
123123
assert("content环境测试值", value, "应该正确保存和读取字符串");
124124
});
125125

126-
test("GM_setValue - 数字", () => {
126+
await test("GM_setValue - 数字", () => {
127127
GM_setValue("test_number", 12345);
128128
const value = GM_getValue("test_number");
129129
assert(12345, value, "应该正确保存和读取数字");
130130
});
131131

132-
test("GM_setValue - 对象", () => {
132+
await test("GM_setValue - 对象", () => {
133133
const obj = { name: "ScriptCat", type: "content" };
134134
GM_setValue("test_object", obj);
135135
const value = GM_getValue("test_object", {});
136136
assert("ScriptCat", value.name, "对象的name属性应该正确");
137137
assert("content", value.type, "对象的type属性应该正确");
138138
});
139139

140-
test("GM_getValue - 默认值", () => {
140+
await test("GM_getValue - 默认值", () => {
141141
const value = GM_getValue("non_existent_key", "默认值");
142142
assert("默认值", value, "不存在的键应该返回默认值");
143143
});
144144

145-
test("GM_listValues", () => {
145+
await test("GM_listValues", () => {
146146
const keys = GM_listValues();
147147
assertTrue(Array.isArray(keys), "GM_listValues应该返回数组");
148148
assertTrue(keys.length >= 3, "应该至少有3个存储键");
149149
console.log("存储的键:", keys);
150150
});
151151

152-
test("GM_deleteValue", () => {
152+
await test("GM_deleteValue", () => {
153153
GM_setValue("test_delete", "to_be_deleted");
154154
assert("to_be_deleted", GM_getValue("test_delete"), "值应该存在");
155155
GM_deleteValue("test_delete");

0 commit comments

Comments
 (0)