Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:white_check_mark: Synchronize rendering fixtures and stabilize UI regression tests

Daniel7aee91e01e6e
diff --git a/app/src/protyle/render/listMindmap/fullscreen.test.ts b/app/src/protyle/render/listMindmap/fullscreen.test.ts
index 0aca7bf400..01cc998b39 100644
--- a/app/src/protyle/render/listMindmap/fullscreen.test.ts
+++ b/app/src/protyle/render/listMindmap/fullscreen.test.ts
@@ -71,8 +71,10 @@ const browserCases = async (source: string, css: string) => {
button("exitFullscreen").click();
await settle();
equalCenter(documentCenter);
- check.deepEqual([view.scale, view.offsetX, view.offsetY], documentTransform,
- "an unchanged round trip restores the document transform");
+ [view.scale, view.offsetX, view.offsetY].forEach((value, index) => {
+ check.ok(Math.abs(value - documentTransform[index]) < 1e-8,
+ "an unchanged round trip restores the document transform");
+ });
check.equal(guide.hidden, true);
button("fullscreen").click();
diff --git a/app/src/protyle/util/onGetMobileTopBar.test.ts b/app/src/protyle/util/onGetMobileTopBar.test.ts
index e9bb759aa3..53afd18f46 100644
--- a/app/src/protyle/util/onGetMobileTopBar.test.ts
+++ b/app/src/protyle/util/onGetMobileTopBar.test.ts
@@ -24,6 +24,7 @@ const sources = {
layout: compile(sliceSource("../../mobile/util/mobileTopBar.ts", "const MOBILE_TOP_BAR_ELEMENT_IDS = ")),
editor: compile(sliceSource("../../mobile/util/setEmpty.ts", "export const setEditor = ")),
render: compile(sliceSource("onGet.ts", "export const onGet = ", "export const disabledForeverProtyle = ")),
+ content: compile(sliceSource("renderContent.ts", "export const getInsertedRenderRoots = ")),
backgroundActions: compile(sliceSource("../header/backgroundActions.ts", "export const updateBackgroundActions = ")),
loading: compile(sliceSource("../ui/initUI.ts", "export const addLoading = ", "export const setPadding = ")),
navigation: compile(sliceSource("../render/av/databaseRowNavigation.ts", "export const clearDatabaseRowNavigation = ", "export const mountDatabaseRowNavigation = ")),
@@ -82,6 +83,7 @@ const browserCases = (code: typeof sources) => {
setTitle: noop, finishMobileStartup: noop, bindMobileBarsScroll: noop,
isValid: () => true, action: [], afterOpen: () => {opened++;}, onFailure: () => {failed++;},
sanitizeKernelHTML: (html: string) => html,
+ beginPerformance: noop,
};
for (const name of ["invalidateTrackedRanges", "hideElements", "invalidateHeadingNumberRefresh",
"normalizeHTMLAssetIFrameSources", "updateWidgetCacheVersion", "disposeCustomBlocksInElement",
@@ -90,7 +92,7 @@ const browserCases = (code: typeof sources) => {
dependencies[name] = noop;
}
const runtime = new Function(...Object.keys(dependencies), code.orientation + code.layout + code.editor + code.loading +
- code.backgroundActions + code.render + code.navigation + code.completion + "\nreturn {onGet, addLoading, complete, fail, updateMobileTopBarLayout};")(
+ code.backgroundActions + code.content + code.render + code.navigation + code.completion + "\nreturn {onGet, addLoading, complete, fail, updateMobileTopBarLayout};")(
...Object.values(dependencies));
if (mode !== "desktop") {
runtime.updateMobileTopBarLayout();
diff --git a/app/tests/fixtures/windowHitTest.ps1 b/app/tests/fixtures/windowHitTest.ps1
index de3a8881d8..12df4e8bc5 100644
--- a/app/tests/fixtures/windowHitTest.ps1
+++ b/app/tests/fixtures/windowHitTest.ps1
@@ -1,6 +1,9 @@
-param([string]$WindowHandle, [string]$Points)
+param([string]$WindowHandle, [string]$Points, [string]$AssemblyPath, [switch]$Prepare)
-Add-Type -TypeDefinition @'
+$ErrorActionPreference = "Stop"
+
+if ($Prepare) {
+ Add-Type -OutputAssembly $AssemblyPath -TypeDefinition @'
using System;
using System.Runtime.InteropServices;
public static class SettingsHitTest {
@@ -30,6 +33,10 @@ public static class SettingsHitTest {
}
}
'@
+ exit
+}
+
+Add-Type -Path $AssemblyPath
$results = @()
foreach ($point in ($Points | ConvertFrom-Json)) {
diff --git a/app/tests/markdownClipboard.test.js b/app/tests/markdownClipboard.test.js
index feb8160831..767052dee5 100644
--- a/app/tests/markdownClipboard.test.js
+++ b/app/tests/markdownClipboard.test.js
@@ -127,6 +127,7 @@ const runCases = async source => {
isUploadDocumentAvailable: () => !switched,
},
"./selection": {getEditorRange: () => range},
+ "./tableCellRichContext": {getTableCellRichContext: () => undefined},
"./hasClosest": {hasClosestBlock: () => block},
"./wpsPresentation": {extractWPSPresentationClipboard: () => undefined},
"./compatibility": {isInHarmony: () => false,
diff --git a/app/tests/searchAVPreview.test.js b/app/tests/searchAVPreview.test.js
index eae4a66d31..8c2e51b6e7 100644
--- a/app/tests/searchAVPreview.test.js
+++ b/app/tests/searchAVPreview.test.js
@@ -6,7 +6,7 @@ const os = require("node:os");
const sources = () => {
const ts = require("typescript");
return Object.fromEntries(["search/util", "search/avPreview", "boot/globalEvent/searchKeydown",
- "protyle/util/onGet", "protyle/render/searchMarkRender"]
+ "protyle/util/onGet", "protyle/util/renderContent", "protyle/render/searchMarkRender"]
.map(name => [name, ts.transpileModule(readFileSync(path.join(__dirname, "../src", name + ".ts"), "utf8"), {
compilerOptions: {module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2021},
}).outputText]));
diff --git a/app/tests/settingsWindow.test.js b/app/tests/settingsWindow.test.js
index 5f00b51014..33c7ef0b87 100644
--- a/app/tests/settingsWindow.test.js
+++ b/app/tests/settingsWindow.test.js
@@ -612,7 +612,8 @@ if (process.versions.electron && process.type === "browser") {
const buffer = child.getNativeWindowHandle();
const handle = buffer.length === 8 ? buffer.readBigUInt64LE().toString() : String(buffer.readUInt32LE());
const {stdout} = await promisify(execFile)("powershell.exe", ["-NoProfile", "-NonInteractive",
- "-File", path.join(__dirname, "fixtures/windowHitTest.ps1"), handle, JSON.stringify(points)],
+ "-File", path.join(__dirname, "fixtures/windowHitTest.ps1"), handle, JSON.stringify(points),
+ "-AssemblyPath", path.join(process.argv[2], "WindowHitTest.dll")],
{windowsHide: true, timeout: 15000});
return JSON.parse(stdout);
});
@@ -661,11 +662,17 @@ if (process.versions.electron && process.type === "browser") {
const {test} = require("node:test");
const {execFile} = require("node:child_process");
const {promisify} = require("node:util");
- test("native settings preserve plugin controls, callbacks, default dialogs and owning-window lifecycle", {timeout: 120000}, async () => {
+ test("native settings preserve plugin controls, callbacks, default dialogs and owning-window lifecycle", {timeout: 180000}, async () => {
const profile = fs.mkdtempSync(path.join(os.tmpdir(), "siyuan-settings-window-"));
const env = {...process.env};
delete env.ELECTRON_RUN_AS_NODE;
try {
+ if (process.platform === "win32") {
+ // 原生类型只编译一次,冷启动耗时不占用窗口消息探测的超时预算。
+ await promisify(execFile)("powershell.exe", ["-NoProfile", "-NonInteractive", "-File",
+ path.join(__dirname, "fixtures/windowHitTest.ps1"), "-Prepare",
+ "-AssemblyPath", path.join(profile, "WindowHitTest.dll")], {windowsHide: true, timeout: 60000});
+ }
// 两轮窗口生命周期包含多个原生命中测试子进程,为 CI 启动开销预留时间。
await promisify(execFile)(require("electron"), [__filename, profile], {env, windowsHide: true, timeout: 110000});
} finally {
diff --git a/app/tests/templateManager.test.js b/app/tests/templateManager.test.js
index 176c5dc871..5edab9b1c9 100644
--- a/app/tests/templateManager.test.js
+++ b/app/tests/templateManager.test.js
@@ -6,6 +6,13 @@ const path = require("node:path");
const runCases = async (sources, css, mobile, legacyMobile) => {
const assert = require("node:assert/strict");
const tick = () => new Promise(resolve => setTimeout(resolve, 30));
+ const waitFor = async (predicate, message) => {
+ const deadline = performance.now() + 5000;
+ while (!predicate()) {
+ assert.ok(performance.now() < deadline, message);
+ await tick();
+ }
+ };
document.body.innerHTML = '<div id="model"><button class="toolbar__icon">Back</button><div id="modelMain"></div></div>';
new Function(sources.icons)();
const style = document.createElement("style");
@@ -263,8 +270,10 @@ const runCases = async (sources, css, mobile, legacyMobile) => {
for (const width of mobile ? [360, 740] : [1440, 850]) {
await require("electron").ipcRenderer.invoke("template-manager-size", width, 800);
- await tick();
const wide = !mobile && width === 1440;
+ await waitFor(() => window.innerWidth === width && root.classList.contains("template-manager--wide") === wide &&
+ getComputedStyle(root.querySelector(".template-manager__editor")).flexDirection === (wide ? "row" : "column"),
+ `${mobile}/${width}: resized manager layout did not settle`);
assert.equal(root.classList.contains("template-manager--wide"), wide);
assert.equal(getComputedStyle(root.querySelector(".template-manager__editor")).flexDirection, wide ? "row" : "column");
assert.ok(root.scrollWidth <= root.clientWidth + 1, `${mobile}/${width}: manager overflows`);
@@ -286,7 +295,7 @@ const runCases = async (sources, css, mobile, legacyMobile) => {
source.value = original;
if (mobile && width === 360) {
await require("electron").ipcRenderer.invoke("template-manager-size", width, 360);
- await tick();
+ await waitFor(() => window.innerHeight === 360, "mobile keyboard viewport did not resize");
button("source").scrollIntoView({block: "nearest"});
assert.ok(button("source").getBoundingClientRect().bottom <= 360, "actions remain reachable above the keyboard");
}
diff --git a/app/tests/verticalNavigation.test.js b/app/tests/verticalNavigation.test.js
index 75e9a871cf..f7a66863f7 100644
--- a/app/tests/verticalNavigation.test.js
+++ b/app/tests/verticalNavigation.test.js
@@ -197,11 +197,14 @@ const rendererModules = () => {
};
visitTrim(onGet);
assert.ok(trimBranch?.elseStatement && ts.isIfStatement(trimBranch.elseStatement));
+ modules["util/renderContent"] = extract("util/renderContent", ["getInsertedRenderRoots"]);
modules["util/navigationTrim"] = `import {containsCurrentSelection} from "./documentRange";
+ import {getInsertedRenderRoots} from "./renderContent";
import {Constants} from "../../constants";
const invalidateTrackedRangesInElement = () => {}, disposeCustomBlocksInElement = () => {}, hideElements = () => {};
export const run = (protyle, content, before) => {
const options = {content, action: [before ? Constants.CB_GET_BEFORE : Constants.CB_GET_APPEND]};
+ let renderRoots;
const REMOVED_OVER_HEIGHT = protyle.contentElement.clientHeight * 8;
if (${trimBranch.expression.getText(onGet)}) ${trimBranch.thenStatement.getText(onGet)}
else ${trimBranch.elseStatement.thenStatement.getText(onGet)}