Skip to content

Commit

Permalink
fix: 修复集成测试失败 (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
yiludege authored Aug 21, 2022
1 parent ea8efcb commit 38fc786
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 16 deletions.
4 changes: 2 additions & 2 deletions packages/wujie-core/__test__/integration/font.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe("main react startApp", () => {
await triggerClickByJsSelector(page, appInfo.fontNavSelector);
await appInfoFontMountedPromise;
// 等待字体加载
await page.waitForResponse((response) => response.url().includes("https://tdesign.gtimg.com/icon/0.1.1/fonts"));
await page.waitForResponse((response) => response.url().includes("https://tdesign.gtimg.com/icon/"));
// 等待字体装载
await new Promise((resolve) => setTimeout(resolve, 1000));
// 检查字体是否生效
Expand All @@ -48,7 +48,7 @@ describe("main vue startApp", () => {
await triggerClickByJsSelector(page, appInfo.fontNavSelector);
await appInfoFontMountedPromise;
// 等待字体加载
await page.waitForResponse((response) => response.url().includes("https://tdesign.gtimg.com/icon/0.1.1/fonts"));
await page.waitForResponse((response) => response.url().includes("https://tdesign.gtimg.com/icon/"));
// 等待字体装载
await new Promise((resolve) => setTimeout(resolve, 1000));
// 检查字体是否生效
Expand Down
15 changes: 3 additions & 12 deletions packages/wujie-core/src/effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,13 @@ function handleStylesheetElementPatch(stylesheetElement: HTMLStyleElement, sandb
/**
* 劫持处理样式元素的属性
*/

type stylesheetElement = HTMLStyleElement & {
_hasPatch?: boolean // 判断新增的style标签是否被劫持
}

function patchStylesheetElement(
stylesheetElement: stylesheetElement,
stylesheetElement: HTMLStyleElement & { _hasPatch?: boolean },
cssLoader: (code: string, url: string, base: string) => string,
sandbox: Wujie,
curUrl: string
) {
if( stylesheetElement._hasPatch ) return
if (stylesheetElement._hasPatch) return;
const innerHTMLDesc = Object.getOwnPropertyDescriptor(Element.prototype, "innerHTML");
const innerTextDesc = Object.getOwnPropertyDescriptor(HTMLElement.prototype, "innerText");
const textContentDesc = Object.getOwnPropertyDescriptor(Node.prototype, "textContent");
Expand Down Expand Up @@ -126,11 +121,7 @@ function patchStylesheetElement(
} else return rawAppendChild(node);
},
},
_hasPatch: {
get: function () {
return true
}
}
_hasPatch: { get: () => true },
});
}

Expand Down
4 changes: 2 additions & 2 deletions packages/wujie-core/src/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ export default class Wujie {
const domContentLoadedTrigger = () => {
eventTrigger(iframeWindow.document, "DOMContentLoaded");
eventTrigger(iframeWindow, "DOMContentLoaded");
this.execQueue.shift()();
this.execQueue.shift()?.();
};
this.execQueue.push(this.fiber ? () => requestIdleCallback(domContentLoadedTrigger) : domContentLoadedTrigger);

Expand All @@ -317,7 +317,7 @@ export default class Wujie {
const domLoadedTrigger = () => {
eventTrigger(iframeWindow.document, "readystatechange");
eventTrigger(iframeWindow, "load");
this.execQueue.shift()();
this.execQueue.shift()?.();
};
this.execQueue.push(this.fiber ? () => requestIdleCallback(domLoadedTrigger) : domLoadedTrigger);
this.execQueue.shift()();
Expand Down

0 comments on commit 38fc786

Please sign in to comment.