Skip to content
2 changes: 1 addition & 1 deletion src/app/service/service_worker/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ export class PopupService {
async getPopupData(req: GetPopupDataReq): Promise<GetPopupDataRes> {
const { url, tabId } = req;
const [matchingResult, runScripts, backScriptList] = await Promise.all([
this.runtime.getPageScriptMatchingResultByUrl(url, true, true),
this.runtime.getPopupPageScriptMatchingResultByUrl(url),
this.getScriptMenu(tabId),
this.getScriptMenu(-1),
]);
Expand Down
51 changes: 51 additions & 0 deletions src/app/service/service_worker/resource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ResourceService } from "./resource";
import { vi, describe, it, expect, beforeEach } from "vitest";
import type { Group } from "@Packages/message/server";
import type { IMessageQueue } from "@Packages/message/message_queue";
import type { Resource } from "@App/app/repo/resource";

initTestEnv();

Expand Down Expand Up @@ -96,3 +97,53 @@ describe("ResourceService - loadByUrl", () => {
expect(res.contentType).toBe("application/octet-stream");
});
});

describe("ResourceService - getScriptResources", () => {
let service: ResourceService;

const createResource = (url: string): Resource => ({
url,
content: "local content",
contentType: "text/plain",
hash: {
md5: "",
sha1: "",
sha256: "",
sha384: "",
sha512: "sha512",
},
base64: "",
link: {},
type: "resource",
createtime: 1,
updatetime: 1,
});

beforeEach(() => {
vi.clearAllMocks();
const mockGroup = {} as Group;
const mockMQ = {} as IMessageQueue;
service = new ResourceService(mockGroup, mockMQ);
});

it("命名 @resource 使用 file:/// 时应立即刷新本地文件", async () => {
const url = "file:///tmp/local.txt";
const resource = createResource(url);
const updateResource = vi.spyOn(service, "updateResource").mockResolvedValue(resource);
const getResource = vi.spyOn(service, "getResource");

const result = await service.getScriptResources(
{
uuid: "script-uuid",
metadata: {
resource: [`asset ${url}`],
},
} as any,
false
);

expect(updateResource).toHaveBeenCalledWith("script-uuid", url, "resource");
expect(getResource).not.toHaveBeenCalled();
expect(result.asset).toBe(resource);
});
});
2 changes: 1 addition & 1 deletion src/app/service/service_worker/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class ResourceService {
}
}
if (path) {
if (uri.startsWith("file:///")) {
if (path.startsWith("file:///")) {
// 如果是file://协议,则每次请求更新一下文件
const res = await this.updateResource(script.uuid, path, type);
ret[resourceKey] = res;
Expand Down
Loading
Loading