Skip to content

Commit

Permalink
[#72063] Fail tests on exceptions and console errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikolaj Trzcinski authored and mgielda committed Jan 28, 2025
1 parent 9e2bd7e commit 84d8528
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/extensions/syncDualPane.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function scrollPreviewElemIntoView({ view, matchingLine, matchingElem, behavior

const elemScrollOffset = cursorBlock.top + previewTopPadding;

const top = matchingRect.top + preview.scrollTop - elemScrollOffset - previewRect.top + editor.scrollTop;
const top = matchingRect.top + preview.scrollTop - elemScrollOffset - previewRect.top + (editor?.scrollTop ?? 0);
preview.scrollTo({ top, behavior });
}

Expand All @@ -69,7 +69,7 @@ export function handlePreviewClickToScroll(ev, lineMap, preview, editor) {
let elem = ev.target;
if (!id) {
// check parents and siblings
while (elem.tagName !== "HTML-CHUNK") {
while (elem && elem.tagName !== "HTML-CHUNK") {
const parent = elem.parentElement;
[id, elem] = findSoruceMappedPreviousElement(elem);
if (id) break;
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useText.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,12 @@ export const useText = ({ preview }) => {
if (preview.current == null) return;

const resizeObserver = new ResizeObserver(() => {
editorView.value.dispatch({
editorView.value?.dispatch?.({
effects: markdownUpdatedStateEffect.of(null),
});
});
const mutationObserver = new MutationObserver((mutationList) => {
editorView.value.dispatch({
editorView.value?.dispatch?.({
effects: markdownUpdatedStateEffect.of(null),
});
for (const mutation of mutationList) {
Expand Down
6 changes: 2 additions & 4 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head>
<title>MyST editor Demo</title>
<link rel="stylesheet" href="./styles/MystEditor.css" />
<link rel="icon" href="data:," />
<style>
body {
margin: 0;
Expand Down Expand Up @@ -265,10 +266,7 @@
action: () => alert("Custom button action"),
},
]),
spellcheckOpts: {
dict: "en_US",
dictionaryPath: "/myst-editor/dictionaries",
},
spellcheckOpts: { dict: "en_US", dictionaryPath: `${window.location.pathname}dictionaries` },
syncScroll: true,
},
document.getElementById("myst"),
Expand Down
2 changes: 1 addition & 1 deletion src/mystState.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const defaults = {
color: "#ff0000",
mode: "websocket",
},
spellcheckOpts: { dict: "en_US", dictionaryPath: "/dictionaries" },
spellcheckOpts: null,
customRoles: [],
transforms: [],
customDirectives: [],
Expand Down
11 changes: 11 additions & 0 deletions tests/myst-editor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,17 @@ const insertChangesAndCheckOutput = async (page: Page, changes: ChangeSpec | nul
const applyPageOpts = async (page: Page, opts: object) => {
let query = new URLSearchParams();
Object.entries(opts).forEach(([k, v]) => query.set(k, v));

// Fail on errors
page.on("pageerror", (err) => {
throw new Error(`Unhandled page exception: ${err.stack || err}`);
});
page.on("console", (msg) => {
if (msg.type() === "error") {
throw new Error(`Console error: ${msg.text()} ${JSON.stringify(msg.location())}`);
}
});

await page.goto("/?" + query.toString());
await page.waitForSelector(".cm-content");
return page;
Expand Down

0 comments on commit 84d8528

Please sign in to comment.