Each smoke test now uses tests/smoke/_harness/ for Playwright, the Tauri IPC mock, the in-memory workspace, and output folders, instead of its own copy. The tests keep their interactions and assertions. Mock handlers that the app never calls are gone. - Split the four mixed regression scripts into 18 feature tests. - Update tests that broke when the app changed on purpose. Each update cites the app source that shows the new behavior. - Mark two real app defects with @known-issue: the settings window controls are 1px shorter than the main window controls, and plugin tabs cannot be reordered by dragging without a workspace. - Merge three palette unit tests into one table-driven test. - The native tests load Playwright through the harness and read NATIVE_CDP_URL, with their old variable names as fallbacks. - A failed smoke test saves a screenshot and prints the console errors. - The runner runs failed tests once more, alone, and reports a test that then passes as flaky. Result: 89 passed, 1 flaky, 2 known issues, 0 failed. Before, 45 of 78 passed.
99 lines
5.0 KiB
JavaScript
99 lines
5.0 KiB
JavaScript
// Repeated copy and paste of formatted Markdown stays exact across saves, tab switches, IDE switches, and line endings.
|
|
import assert from "node:assert/strict";
|
|
import { mockTauri, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
|
|
|
await runSmoke("editor/pasteRepeat", async ({ page }) => {
|
|
await mockTauri(page, {
|
|
commands: test => {
|
|
const workspace = test.workspace({
|
|
root: "C:\\smoke-workspace",
|
|
files: {
|
|
"notes/welcome.md": "---\ntitle: Welcome\n---\n\n# Working notes\n\nFirst paragraph.\n\n- [ ] A task\n\n[[second]]\n",
|
|
"notes/second.md": "# Second note\n",
|
|
"src/hello.py": "print('hello')\n",
|
|
},
|
|
writeEvents: true,
|
|
});
|
|
test.files = workspace.files;
|
|
return {
|
|
...workspace,
|
|
// Saves send the last saved text. Reject a save when the file changed, as the backend does.
|
|
workspace_write: args => {
|
|
if (args.expected !== undefined && workspace.files.get(args.rel) !== args.expected) throw new Error("Save blocked: file changed on disk");
|
|
return workspace.workspace_write(args);
|
|
},
|
|
};
|
|
},
|
|
});
|
|
async function open(name) {
|
|
await page.keyboard.press('Control+p');
|
|
await page.getByRole('textbox', { name: 'Find a file' }).fill(name);
|
|
await page.getByRole('dialog').getByRole('button').filter({ hasText: name }).first().click();
|
|
}
|
|
async function writer() {
|
|
await page.locator('.cm-content').waitFor();
|
|
return page.evaluate(async () => {
|
|
const { EditorView } = await import('/node_modules/@codemirror/view/dist/index.js');
|
|
window.__WRITER__ = EditorView.findFromDOM(document.querySelector('.cm-content'));
|
|
return window.__WRITER__.state.sliceDoc();
|
|
});
|
|
}
|
|
async function expectWriter(expected) {
|
|
await writer();
|
|
try { await page.waitForFunction(text => window.__WRITER__.state.sliceDoc() === text, expected); } catch (error) { console.log({ expectedLength: expected.length, actualLength: (await writer()).length, errors: page.errors }); throw error; }
|
|
}
|
|
await page.goto(smokeUrl);
|
|
await page.getByText('smoke-workspace', { exact: true }).waitFor();
|
|
const formatted = '# Copied heading\n\n## Links\n\n[Reference](https://example.com) and [[second|Another note]]\n\n**Bold**, *italic*, and `code`.\n\n- A list item\n';
|
|
await page.evaluate(text => { window.__TEST__.files.set('notes/source.md', text); window.__TEST__.files.set('notes/pasted.md', ''); }, formatted);
|
|
await open('source.md');
|
|
await writer();
|
|
await page.locator('.cm-content').click();
|
|
await page.keyboard.press('Control+a');
|
|
await page.keyboard.press('Control+c');
|
|
await open('pasted.md');
|
|
await writer();
|
|
for (let iteration = 0; iteration < 12; iteration++) {
|
|
await page.locator('.cm-content').click();
|
|
await page.keyboard.press('Control+a');
|
|
await page.keyboard.press('Backspace');
|
|
await expectWriter('');
|
|
await page.keyboard.press('Control+v');
|
|
await expectWriter(formatted);
|
|
assert.equal(await page.locator('.live-writer .cm-editor').count(), 1, 'One mounted editor');
|
|
await page.keyboard.press('Control+s');
|
|
assert.equal(await page.evaluate(() => window.__TEST__.files.get('notes/pasted.md').replace(/\r\n?/g, '\n')), formatted);
|
|
if (iteration === 5) {
|
|
await page.keyboard.press('Control+e');
|
|
await page.locator('.monaco-editor textarea').waitFor();
|
|
await page.keyboard.press('Control+e');
|
|
await expectWriter(formatted);
|
|
}
|
|
await open('second.md');
|
|
await writer();
|
|
await page.getByRole('tab', { name: 'pasted.md', exact: true }).click();
|
|
await expectWriter(formatted);
|
|
}
|
|
// Clipboard formats can use different line endings than the destination.
|
|
for (const lineBreak of ['\n', '\r\n', '\r']) {
|
|
await page.evaluate(({ text, lineBreak }) => {
|
|
const view = window.__WRITER__;
|
|
view.dispatch({ selection: { anchor: 0, head: view.state.doc.length } });
|
|
const clipboardData = new DataTransfer();
|
|
clipboardData.setData('text/plain', text.replace(/\n/g, lineBreak));
|
|
view.contentDOM.dispatchEvent(new ClipboardEvent('paste', { bubbles: true, cancelable: true, clipboardData }));
|
|
}, { text: formatted, lineBreak });
|
|
await expectWriter(formatted);
|
|
assert.equal(await page.evaluate(() => window.__WRITER__.state.doc.lines), formatted.split('\n').length);
|
|
await page.keyboard.press('Control+s');
|
|
const synchronized = await page.evaluate(async () => {
|
|
const { monaco } = await import('/src/lib/editor/monacoEnv.ts');
|
|
const model = monaco.editor.getModels().find(model => model.uri.path.endsWith('/pasted.md'));
|
|
const source = window.__WRITER__.state.doc.sliceString(0, undefined, model.getEOL());
|
|
return source === model.getValue() && source === window.__TEST__.files.get('notes/pasted.md');
|
|
});
|
|
assert.equal(synchronized, true, 'Writer, model, and saved source agree');
|
|
}
|
|
console.log('PASS: formatted Markdown copied across notes stays exact through 12 paste/delete cycles, saves, tab reopen, IDE reopen, and LF/CRLF/CR clipboard replacement');
|
|
});
|