Skip to content

Commit 7139e1b

Browse files
committed
fix(tests): add cache reset and HTML→MD transitions for test isolation
Add __resetCacheForTest helper in bridge.js to clear iframe doc cache. Add beforeAll HTML→MD transitions in each describe block to ensure clean md state when running all livepreview suites together. Fixes cross-contamination from prior suites that left stale cache entries. All 227 livepreview tests pass consistently.
1 parent 18d4439 commit 7139e1b

4 files changed

Lines changed: 47 additions & 7 deletions

File tree

src-mdviewer/src/bridge.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ export function initBridge() {
122122
window.__getWorkingSetPaths = function () {
123123
return docCache._getWorkingSetPathsForTest();
124124
};
125+
window.__resetCacheForTest = function () {
126+
docCache.clearAll();
127+
};
125128
window.__triggerContentSync = function () {
126129
const content = document.getElementById("viewer-content");
127130
if (content) {

test/spec/md-editor-edit-integ-test.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,6 @@ define(function (require, exports, module) {
128128
await awaitsFor(() =>
129129
LiveDevMultiBrowser.status === LiveDevMultiBrowser.STATUS_ACTIVE,
130130
"live dev to open", 20000);
131-
132-
// Open the checkbox test md file
133-
await awaitsForDone(SpecRunnerUtils.openProjectFiles(["checkbox-test.md"]),
134-
"open checkbox-test.md");
135-
await _waitForMdPreviewReady(EditorManager.getActiveEditor());
136131
}
137132
}, 30000);
138133

@@ -155,6 +150,12 @@ define(function (require, exports, module) {
155150

156151
describe("Checkbox (Task List) Sync", function () {
157152

153+
beforeAll(async function () {
154+
// Ensure clean md state by switching HTML→MD
155+
await awaitsForDone(SpecRunnerUtils.openProjectFiles(["simple.html"]),
156+
"open simple.html to reset md state");
157+
}, 10000);
158+
158159
async function _openMdFile(fileName) {
159160
await awaitsForDone(SpecRunnerUtils.openProjectFiles([fileName]),
160161
"open " + fileName);
@@ -239,6 +240,11 @@ define(function (require, exports, module) {
239240

240241
describe("Code Block Editing", function () {
241242

243+
beforeAll(async function () {
244+
await awaitsForDone(SpecRunnerUtils.openProjectFiles(["simple.html"]),
245+
"open simple.html to reset md state");
246+
}, 10000);
247+
242248
async function _openMdFile(fileName) {
243249
await awaitsForDone(SpecRunnerUtils.openProjectFiles([fileName]),
244250
"open " + fileName);
@@ -616,6 +622,11 @@ define(function (require, exports, module) {
616622

617623
describe("List Editing", function () {
618624

625+
beforeAll(async function () {
626+
await awaitsForDone(SpecRunnerUtils.openProjectFiles(["simple.html"]),
627+
"open simple.html to reset md state");
628+
}, 10000);
629+
619630
async function _openMdFile(fileName) {
620631
await awaitsForDone(SpecRunnerUtils.openProjectFiles([fileName]),
621632
"open " + fileName);
@@ -988,7 +999,9 @@ define(function (require, exports, module) {
988999
"End of list test.\n";
9891000

9901001
beforeAll(async function () {
991-
// Open file once — keep it open for all tests in this describe
1002+
// Reset md state then open file
1003+
await awaitsForDone(SpecRunnerUtils.openProjectFiles(["simple.html"]),
1004+
"open simple.html to reset md state");
9921005
await awaitsForDone(SpecRunnerUtils.openProjectFiles(["list-test.md"]),
9931006
"open list-test.md");
9941007
await _waitForMdPreviewReady(EditorManager.getActiveEditor());
@@ -1234,6 +1247,8 @@ define(function (require, exports, module) {
12341247
"## Heading Two\n\nAnother paragraph.\n\n### Heading Three\n\nFinal paragraph.\n";
12351248

12361249
beforeAll(async function () {
1250+
await awaitsForDone(SpecRunnerUtils.openProjectFiles(["simple.html"]),
1251+
"open simple.html to reset md state");
12371252
await awaitsForDone(SpecRunnerUtils.openProjectFiles(["heading-test.md"]),
12381253
"open heading-test.md");
12391254
await _waitForMdPreviewReady(EditorManager.getActiveEditor());

test/spec/md-editor-edit-more-integ-test.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,19 @@ define(function (require, exports, module) {
170170
await awaitsForDone(SpecRunnerUtils.openProjectFiles(["doc1.md"]),
171171
"open doc1.md");
172172
await _waitForMdPreviewReady(EditorManager.getActiveEditor());
173+
// Reset cache after iframe is ready (clears stale entries from prior suites)
174+
const win = _getMdIFrameWin();
175+
if (win && win.__resetCacheForTest) {
176+
win.__resetCacheForTest();
177+
}
178+
// Re-open to get a fresh render after cache reset
179+
await awaitsForDone(SpecRunnerUtils.openProjectFiles(["simple.html"]),
180+
"open simple.html to reset");
181+
await awaitsForDone(SpecRunnerUtils.openProjectFiles(["doc1.md"]),
182+
"reopen doc1.md");
183+
await _waitForMdPreviewReady(EditorManager.getActiveEditor());
173184
await _enterEditMode();
174-
}, 15000);
185+
}, 20000);
175186

176187
afterAll(async function () {
177188
await awaitsForDone(CommandManager.execute(Commands.FILE_CLOSE, { _forceClose: true }),

test/spec/md-editor-integ-test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,17 @@ define(function (require, exports, module) {
266266
await awaitsForDone(SpecRunnerUtils.openProjectFiles(["test-shortcuts.md"]),
267267
"open test-shortcuts.md");
268268
await _waitForMdPreviewReady(EditorManager.getActiveEditor());
269+
// Reset iframe doc cache for predictable test state
270+
const win = _getMdIFrameWin();
271+
if (win && win.__resetCacheForTest) {
272+
win.__resetCacheForTest();
273+
}
274+
// Re-open to get fresh render after cache reset
275+
await awaitsForDone(SpecRunnerUtils.openProjectFiles(["simple1.html"]),
276+
"open simple1.html to reset");
277+
await awaitsForDone(SpecRunnerUtils.openProjectFiles(["test-shortcuts.md"]),
278+
"reopen test-shortcuts.md");
279+
await _waitForMdPreviewReady(EditorManager.getActiveEditor());
269280
testFilePath = testFolder + "/test-shortcuts.md";
270281
}
271282
}, 30000);

0 commit comments

Comments
 (0)