Skip to content

Commit dc35ec8

Browse files
committed
🎨 Lint fix
1 parent 356399f commit dc35ec8

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

src/app/service/content/utils.test.ts

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe("utils", () => {
2020
beforeEach(() => {
2121
// 重置所有 mock
2222
vi.clearAllMocks();
23-
23+
2424
// 设置 console mock 来避免测试输出污染
2525
vi.spyOn(console, "error").mockImplementation(() => {});
2626
vi.spyOn(console, "log").mockImplementation(() => {});
@@ -30,7 +30,7 @@ describe("utils", () => {
3030
// 清理 DOM
3131
document.head.innerHTML = "";
3232
document.documentElement.innerHTML = "<head></head><body></body>";
33-
33+
3434
vi.restoreAllMocks();
3535
});
3636

@@ -221,9 +221,9 @@ describe("utils", () => {
221221
it("应该编译并执行简单代码", () => {
222222
const code = "return arguments[0].value + arguments[1];";
223223
const func: ScriptFunc = compileScript(code);
224-
224+
225225
const result = func({ value: 10 }, "test-script");
226-
226+
227227
expect(result).toBe("10test-script");
228228
});
229229

@@ -237,10 +237,10 @@ describe("utils", () => {
237237
return scriptName;
238238
`;
239239
const func: ScriptFunc = compileScript(code);
240-
240+
241241
const result1 = func({ value: 5, multiply: 3 }, "test");
242242
const result2 = func({ value: 5 }, "fallback");
243-
243+
244244
expect(result1).toBe(15);
245245
expect(result2).toBe("fallback");
246246
});
@@ -252,16 +252,16 @@ describe("utils", () => {
252252
});
253253
`;
254254
const func: ScriptFunc = compileScript(code);
255-
255+
256256
const result = await func({ value: 5 }, "async-test");
257-
257+
258258
expect(result).toBe(10);
259259
});
260260

261261
it("应该正确处理错误", () => {
262262
const code = "throw new Error('Test error');";
263263
const func: ScriptFunc = compileScript(code);
264-
264+
265265
expect(() => func({}, "error-test")).toThrow("Test error");
266266
});
267267
});
@@ -288,18 +288,18 @@ describe("utils", () => {
288288
it("应该生成基本的注入脚本代码", () => {
289289
const script = createMockScript();
290290
const scriptCode = "console.log('injected');";
291-
291+
292292
const result = compileInjectScript(script, scriptCode);
293-
293+
294294
expect(result).toBe(`window['inject-test-flag'] = function(){console.log('injected');}`);
295295
});
296296

297297
it("应该包含自动删除挂载函数的代码", () => {
298298
const script = createMockScript();
299299
const scriptCode = "console.log('with auto delete');";
300-
300+
301301
const result = compileInjectScript(script, scriptCode, true);
302-
302+
303303
expect(result).toContain(`try{delete window['inject-test-flag']}catch(e){}`);
304304
expect(result).toContain("console.log('with auto delete');");
305305
expect(result).toBe(
@@ -310,9 +310,9 @@ describe("utils", () => {
310310
it("默认情况下不应该包含自动删除代码", () => {
311311
const script = createMockScript();
312312
const scriptCode = "console.log('without auto delete');";
313-
313+
314314
const result = compileInjectScript(script, scriptCode);
315-
315+
316316
expect(result).not.toContain("try{delete window");
317317
expect(result).toBe(`window['inject-test-flag'] = function(){console.log('without auto delete');}`);
318318
});
@@ -324,9 +324,9 @@ describe("utils", () => {
324324
function test() { return x + 1; }
325325
console.log(test());
326326
`;
327-
327+
328328
const result = compileInjectScript(script, scriptCode, true);
329-
329+
330330
expect(result).toContain("window['complex-flag']");
331331
expect(result).toContain("var x = 1;");
332332
expect(result).toContain("function test()");
@@ -336,19 +336,19 @@ describe("utils", () => {
336336
it("应该正确转义脚本标志名称", () => {
337337
const script = createMockScript({ flag: "flag-with-special-chars_123" });
338338
const scriptCode = "console.log('test');";
339-
339+
340340
const result = compileInjectScript(script, scriptCode);
341-
341+
342342
expect(result).toContain(`window['flag-with-special-chars_123']`);
343343
});
344344
});
345345

346346
describe("addStyle", () => {
347347
it("应该创建并添加 style 元素到 head", () => {
348348
const css = "body { background: red; }";
349-
349+
350350
const styleElement = addStyle(css);
351-
351+
352352
expect(styleElement).toBeInstanceOf(HTMLStyleElement);
353353
expect(styleElement.textContent).toBe(css);
354354
expect(document.head.contains(styleElement)).toBe(true);
@@ -358,23 +358,23 @@ describe("utils", () => {
358358
// 移除 head 元素
359359
const head = document.head;
360360
head.remove();
361-
361+
362362
const css = ".test { color: blue; }";
363363
const styleElement = addStyle(css);
364-
364+
365365
expect(styleElement).toBeInstanceOf(HTMLStyleElement);
366366
expect(styleElement.textContent).toBe(css);
367367
expect(document.documentElement.contains(styleElement)).toBe(true);
368-
368+
369369
// 恢复 head 元素以便其他测试
370370
document.documentElement.appendChild(head);
371371
});
372372

373373
it("应该处理空的 CSS 字符串", () => {
374374
const css = "";
375-
375+
376376
const styleElement = addStyle(css);
377-
377+
378378
expect(styleElement.textContent).toBe("");
379379
expect(document.head.contains(styleElement)).toBe(true);
380380
});
@@ -398,20 +398,20 @@ describe("utils", () => {
398398
transition: transform 0.3s ease;
399399
}
400400
`;
401-
401+
402402
const styleElement = addStyle(css);
403-
403+
404404
expect(styleElement.textContent).toBe(css);
405405
expect(document.head.contains(styleElement)).toBe(true);
406406
});
407407

408408
it("应该允许添加多个样式", () => {
409409
const css1 = ".class1 { color: red; }";
410410
const css2 = ".class2 { color: blue; }";
411-
411+
412412
const style1 = addStyle(css1);
413413
const style2 = addStyle(css2);
414-
414+
415415
expect(document.head.contains(style1)).toBe(true);
416416
expect(document.head.contains(style2)).toBe(true);
417417
expect(style1.textContent).toBe(css1);
@@ -421,10 +421,10 @@ describe("utils", () => {
421421

422422
it("应该返回添加的 style 元素", () => {
423423
const css = ".return-test { font-size: 14px; }";
424-
424+
425425
const returnedElement = addStyle(css);
426426
const queriedElement = document.querySelector("style");
427-
427+
428428
expect(returnedElement).toBe(queriedElement);
429429
expect(returnedElement?.textContent).toBe(css);
430430
});

0 commit comments

Comments
 (0)