Move the smoke tests onto the shared harness
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.
This commit is contained in:
@@ -1,123 +1,115 @@
|
||||
// Tree rename undo and redo keep folders expanded; New note templates, Git plug-in navigation, and detached tab layout isolation.
|
||||
// @requires repo:RuneStone_Git/dist
|
||||
import { createRequire } from 'node:module';
|
||||
import assert from 'node:assert/strict';
|
||||
import { mkdir, readFile } from 'node:fs/promises';
|
||||
const require = createRequire(import.meta.url);
|
||||
const { chromium } = require(process.env.PLAYWRIGHT_MODULE || 'playwright');
|
||||
const browser = await chromium.launch({ headless: true, ...(process.env.CHROME_PATH ? { executablePath: process.env.CHROME_PATH } : {}) });
|
||||
const context = await browser.newContext({ viewport: { width: 1200, height: 850 } });
|
||||
const page = await context.newPage();
|
||||
const errors = [];
|
||||
page.on('pageerror', error => errors.push(error.message));
|
||||
const gitRoot = new URL('../../../../RuneStone_Git/dist/', import.meta.url);
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import { mockTauri, openPage, outputDir, pluginRepo, runSmoke, smokeUrl } from '../_harness/index.mjs';
|
||||
|
||||
const gitRoot = path.join(pluginRepo('RuneStone_Git'), 'dist');
|
||||
const git = {
|
||||
manifest: JSON.parse(await readFile(new URL('plugin.json', gitRoot), 'utf8')),
|
||||
code: await readFile(new URL('main.js', gitRoot), 'utf8'),
|
||||
css: (await readFile(new URL('style.css', gitRoot))).toString('base64'),
|
||||
manifest: JSON.parse(await readFile(path.join(gitRoot, 'plugin.json'), 'utf8')),
|
||||
code: await readFile(path.join(gitRoot, 'main.js'), 'utf8'),
|
||||
css: (await readFile(path.join(gitRoot, 'style.css'))).toString('base64'),
|
||||
};
|
||||
await context.addInitScript(git => {
|
||||
window.isTauri = true;
|
||||
const root = 'C:\\host-todo-test';
|
||||
const files = new Map([['a.md', '# Note\n\nOriginal text.'], ['folder/nested/note.md', '# Nested'], ['other/keep.md', '# Keep'], ['.runestone/templates/Daily.md', '# Daily\n\n## Tasks'], ['.runestone/marks.json', JSON.stringify({ pins: ['a.md'], bookmarks: ['a.md'], order: { '': ['a.md'] } })]]);
|
||||
const state = { files, calls: [], exportResult: 'C:\\exports\\my-theme.json', exportError: '' };
|
||||
window.__HOST_TEST__ = state;
|
||||
let sequence = 0;
|
||||
window.__TAURI_INTERNALS__ = {
|
||||
metadata: { currentWindow: { label: 'main' }, currentWebview: { label: 'main' } },
|
||||
transformCallback: () => ++sequence, unregisterCallback: () => {},
|
||||
invoke: async (command, args = {}) => {
|
||||
state.calls.push({ command, args });
|
||||
if (command === 'plugins_snapshot') return { root: 'C:/plugins', plugins: [{ manifest: git.manifest, hash: 'navigation-git', enabled: true, installedAt: 1, path: 'C:/plugins/runestone.git', error: null, removal: false }] };
|
||||
if (command === 'plugins_load') return git.code;
|
||||
if (command === 'plugins_asset') return git.css;
|
||||
if (command === 'plugins_data') return 'null';
|
||||
if (command === 'workspace_last_path') return root;
|
||||
if (command === 'workspace_open') return { root, name: 'host-todo-test', watch_mode: 'native' };
|
||||
if (command === 'workspace_read') { if (!files.has(args.rel)) throw new Error('Missing file'); return files.get(args.rel); }
|
||||
if (command === 'workspace_list') {
|
||||
const prefix = args.rel ? args.rel + '/' : '';
|
||||
const entries = new Map();
|
||||
for (const path of files.keys()) {
|
||||
if (!path.startsWith(prefix) || (!args.rel && path.startsWith('.runestone/'))) continue;
|
||||
const tail = path.slice(prefix.length), name = tail.split('/')[0];
|
||||
entries.set(name, { name, rel_path: prefix + name, kind: tail.includes('/') ? 'folder' : 'file' });
|
||||
}
|
||||
return [...entries.values()];
|
||||
}
|
||||
if (command === 'workspace_create') { if (files.has(args.rel)) throw new Error('Destination exists'); files.set(args.rel, ''); return; }
|
||||
if (command === 'workspace_write') {
|
||||
if (args.expected !== undefined && files.get(args.rel) !== args.expected) throw new Error('Changed on disk');
|
||||
files.set(args.rel, args.contents); return;
|
||||
}
|
||||
if (command === 'workspace_rename') {
|
||||
if (files.has(args.to)) throw new Error('Destination exists');
|
||||
if (![...files.keys()].some(path => path === args.from || path.startsWith(args.from + '/'))) throw new Error('Missing file');
|
||||
for (const [path, contents] of [...files]) { if (path === args.from || path.startsWith(args.from + '/')) { files.set(args.to + path.slice(args.from.length), contents); files.delete(path); } } return;
|
||||
}
|
||||
if (command === 'workspace_delete') { files.delete(args.rel); return; }
|
||||
if (command === 'workspace_search') return [];
|
||||
if (command === 'plugin:event|listen') return ++sequence;
|
||||
if (command === 'plugin:window|is_maximized') return false;
|
||||
if (command === 'plugin:dialog|message') return 'Ok';
|
||||
if (command === 'theme_export') { if (state.exportError) throw new Error(state.exportError); return state.exportResult; }
|
||||
return null;
|
||||
|
||||
await runSmoke('tree/renameUndo', async ({ browser }) => {
|
||||
const context = await browser.newContext({ viewport: { width: 1200, height: 850 } });
|
||||
await mockTauri(context, {
|
||||
strict: false,
|
||||
state: git,
|
||||
commands: test => {
|
||||
const git = test.state;
|
||||
const ws = test.workspace({
|
||||
root: 'C:\\host-todo-test',
|
||||
files: {
|
||||
'a.md': '# Note\n\nOriginal text.', 'folder/nested/note.md': '# Nested', 'other/keep.md': '# Keep', '.runestone/templates/Daily.md': '# Daily\n\n## Tasks',
|
||||
'.runestone/marks.json': JSON.stringify({ pins: ['a.md'], bookmarks: ['a.md'], order: { '': ['a.md'] } }),
|
||||
},
|
||||
});
|
||||
const files = ws.files;
|
||||
const within = (from, path) => path === from || path.startsWith(from + '/');
|
||||
test.files = files;
|
||||
return {
|
||||
workspace_last_path: ws.workspace_last_path,
|
||||
workspace_open: ws.workspace_open,
|
||||
workspace_read: ws.workspace_read,
|
||||
workspace_list: args => ws.workspace_list(args).filter(entry => args.rel || !entry.rel_path.startsWith('.runestone')),
|
||||
workspace_create: ({ rel }) => { if (files.has(rel)) throw new Error('Destination exists'); files.set(rel, ''); },
|
||||
workspace_write: ({ rel, contents, expected }) => {
|
||||
if (expected !== undefined && files.get(rel) !== expected) throw new Error('Changed on disk');
|
||||
files.set(rel, contents);
|
||||
},
|
||||
workspace_rename: ({ from, to }) => {
|
||||
if (files.has(to)) throw new Error('Destination exists');
|
||||
if (![...files.keys()].some(path => within(from, path))) throw new Error('Missing file');
|
||||
for (const [path, contents] of [...files]) if (within(from, path)) { files.set(to + path.slice(from.length), contents); files.delete(path); }
|
||||
},
|
||||
workspace_delete: ({ rel }) => { files.delete(rel); },
|
||||
workspace_search: () => [],
|
||||
plugins_snapshot: () => ({ root: 'C:/plugins', plugins: [{ manifest: git.manifest, hash: 'navigation-git', enabled: true, installedAt: 1, path: 'C:/plugins/runestone.git', error: null, removal: false }] }),
|
||||
plugins_load: () => git.code,
|
||||
plugins_asset: () => git.css,
|
||||
plugins_data: () => 'null',
|
||||
'plugin:window|is_maximized': () => false,
|
||||
'plugin:dialog|message': () => 'Ok',
|
||||
};
|
||||
},
|
||||
};
|
||||
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: () => {} };
|
||||
}, git);
|
||||
const origin = process.env.SMOKE_URL || 'http://127.0.0.1:5186';
|
||||
const row = path => page.locator(`[data-tree-rel="${path}"]`);
|
||||
const item = name => page.getByRole('menuitem', { name, exact: true });
|
||||
async function paneMenu() { await page.getByRole('navigation', { name: 'Workspace files' }).click({ button: 'right', position: { x: 90, y: 360 } }); }
|
||||
async function rename(path, name) {
|
||||
await row(path).click({ button: 'right' }); await item('Rename').click();
|
||||
await page.locator('.tree input').fill(name); await page.locator('.tree input').press('Enter');
|
||||
}
|
||||
async function expanded(path) { assert.equal(await row(path).getAttribute('aria-expanded'), 'true', `${path} stays expanded`); }
|
||||
await mkdir('output/host-navigation-pass3', { recursive: true });
|
||||
try {
|
||||
await page.goto(origin);
|
||||
});
|
||||
const page = await openPage(context, { timeout: 30000 });
|
||||
const output = await outputDir('tree/renameUndo');
|
||||
const shot = (target, name) => target.screenshot({ path: path.join(output, name) });
|
||||
const row = rel => page.locator(`[data-tree-rel="${rel}"]`);
|
||||
const item = name => page.getByRole('menuitem', { name, exact: true });
|
||||
const setMode = (target, mode) => target.evaluate(async mode => { const { saveAppearance } = await import('/src/lib/theme/appearance.ts'); saveAppearance({ theme: 'default', mode }); }, mode);
|
||||
async function paneMenu() { await page.getByRole('navigation', { name: 'Workspace files' }).click({ button: 'right', position: { x: 90, y: 360 } }); }
|
||||
async function rename(rel, name) {
|
||||
await row(rel).click({ button: 'right' }); await item('Rename').click();
|
||||
await page.locator('.tree input').fill(name); await page.locator('.tree input').press('Enter');
|
||||
}
|
||||
async function expanded(rel) { assert.equal(await row(rel).getAttribute('aria-expanded'), 'true', `${rel} stays expanded`); }
|
||||
|
||||
await page.goto(smokeUrl);
|
||||
await row('folder').click(); await row('folder/nested').click(); await row('other').click();
|
||||
await rename('folder/nested/note.md', 'renamed.md'); await row('folder/nested/renamed.md').waitFor();
|
||||
await row('folder/nested/renamed.md').focus(); await page.keyboard.press('Control+z');
|
||||
await row('folder/nested/note.md').waitFor();
|
||||
for (const path of ['folder', 'folder/nested', 'other']) await expanded(path);
|
||||
for (const rel of ['folder', 'folder/nested', 'other']) await expanded(rel);
|
||||
await page.keyboard.press('Control+y'); await row('folder/nested/renamed.md').waitFor();
|
||||
for (const path of ['folder', 'folder/nested', 'other']) await expanded(path);
|
||||
for (const rel of ['folder', 'folder/nested', 'other']) await expanded(rel);
|
||||
await rename('folder', 'renamed-folder'); await row('renamed-folder/nested/renamed.md').waitFor();
|
||||
await row('renamed-folder').focus(); await page.keyboard.press('Control+z');
|
||||
await row('folder/nested/renamed.md').waitFor();
|
||||
for (const path of ['folder', 'folder/nested', 'other']) await expanded(path);
|
||||
for (const rel of ['folder', 'folder/nested', 'other']) await expanded(rel);
|
||||
await page.keyboard.press('Control+y'); await row('renamed-folder/nested/renamed.md').waitFor();
|
||||
for (const path of ['renamed-folder', 'renamed-folder/nested', 'other']) await expanded(path);
|
||||
for (const rel of ['renamed-folder', 'renamed-folder/nested', 'other']) await expanded(rel);
|
||||
await paneMenu(); assert.equal(await item('Manage templates…').isVisible(), false);
|
||||
await item('New note').click(); await row('untitled.md').waitFor();
|
||||
assert.equal(await page.evaluate(() => window.__HOST_TEST__.files.get('untitled.md')), '');
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.files.get('untitled.md')), '');
|
||||
await paneMenu(); await item('New note').focus(); await page.keyboard.press('ArrowRight');
|
||||
await item('Daily').click(); await row('Daily.md').waitFor();
|
||||
assert.equal(await page.evaluate(() => window.__HOST_TEST__.files.get('Daily.md')), '# Daily\n\n## Tasks');
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.files.get('Daily.md')), '# Daily\n\n## Tasks');
|
||||
await paneMenu(); await item('New note').hover(); await item('Manage templates…').click();
|
||||
await page.getByRole('button', { name: 'Close templates', exact: true }).click();
|
||||
for (const mode of ['light', 'dark']) {
|
||||
await page.evaluate(async mode => { const { saveAppearance } = await import('/src/lib/theme/appearance.ts'); saveAppearance({ theme: 'default', mode }); }, mode);
|
||||
await setMode(page, mode);
|
||||
await paneMenu(); await item('New note').focus(); await page.keyboard.press('ArrowRight');
|
||||
await page.screenshot({ path: `output/host-navigation-pass3/note-menu-${mode}.png` });
|
||||
await shot(page, `note-menu-${mode}.png`);
|
||||
await page.keyboard.press('Escape'); await page.keyboard.press('Escape');
|
||||
}
|
||||
await page.setViewportSize({ width: 600, height: 600 });
|
||||
await paneMenu(); await item('New note').focus(); await page.keyboard.press('ArrowRight');
|
||||
await page.screenshot({ path: 'output/host-navigation-pass3/note-menu-dark-narrow.png' });
|
||||
await shot(page, 'note-menu-dark-narrow.png');
|
||||
assert.ok(await item('Manage templates…').evaluate(node => node.getBoundingClientRect().right <= innerWidth));
|
||||
await page.keyboard.press('Escape'); await page.keyboard.press('Escape');
|
||||
await page.setViewportSize({ width: 1200, height: 850 });
|
||||
await page.evaluate(() => { window.__HOST_TEST__.files.delete('.runestone/templates/Daily.md'); window.dispatchEvent(new Event('runestone-templates-changed')); });
|
||||
await page.evaluate(() => { window.__TEST__.files.delete('.runestone/templates/Daily.md'); window.dispatchEvent(new Event('runestone-templates-changed')); });
|
||||
await paneMenu(); await item('New note').focus(); await page.keyboard.press('ArrowRight');
|
||||
assert.equal(await item('Daily').count(), 0);
|
||||
await item('Manage templates…').click();
|
||||
await page.getByRole('button', { name: 'Close templates', exact: true }).click();
|
||||
const creations = await page.evaluate(() => window.__HOST_TEST__.calls.filter(call => call.command === 'workspace_create').length);
|
||||
const creations = await page.evaluate(() => window.__TEST__.calls.filter(call => call.command === 'workspace_create').length);
|
||||
await paneMenu(); await item('New note').focus(); await page.keyboard.press('Enter');
|
||||
await page.waitForFunction(count => window.__HOST_TEST__.calls.filter(call => call.command === 'workspace_create').length === count + 1, creations);
|
||||
await page.waitForFunction(count => window.__TEST__.calls.filter(call => call.command === 'workspace_create').length === count + 1, creations);
|
||||
await page.getByRole('button', { name: 'Source control', exact: true }).waitFor();
|
||||
assert.equal(await page.locator('.header-left').getByRole('button', { name: 'Source control', exact: true }).count(), 1);
|
||||
await page.getByRole('button', { name: 'Plug-in views', exact: true }).click();
|
||||
@@ -127,7 +119,7 @@ try {
|
||||
const graphIcon = await graph.locator('.action-icon').innerHTML();
|
||||
const expectedIcon = await page.evaluate(async () => (await import('/src/lib/ui/actionIcons.ts')).actionIcon('git').innerHTML);
|
||||
assert.equal(graphIcon, expectedIcon, 'The real Git graph command uses the shared Git icon');
|
||||
await page.screenshot({ path: 'output/host-navigation-pass3/real-git-command-dark.png' });
|
||||
await shot(page, 'real-git-command-dark.png');
|
||||
await page.keyboard.press('Escape');
|
||||
await page.evaluate(async () => {
|
||||
const external = await import(performance.getEntriesByType('resource').find(entry => new URL(entry.name).pathname === '/src/lib/plugins/external.ts').name);
|
||||
@@ -135,10 +127,10 @@ try {
|
||||
external.pluginTools.set([{ owner: 'pm-test', id: 'pm', title: 'Project Management', kind: 'view', surface: 'open' }, { owner: 'git-test', id: 'graph', title: 'Graph view', kind: 'command', surface: 'open', icon: 'git' }]);
|
||||
external.pluginTools.update(items => [...items, { owner: 'runestone.browser', id: 'new-tab', title: 'New browser tab', kind: 'command', surface: 'open' }]);
|
||||
const registry = await import(performance.getEntriesByType('resource').find(entry => new URL(entry.name).pathname === '/src/lib/plugins/registry.ts').name);
|
||||
registry.pluginHost.get('browser').newTab = async () => { window.__HOST_TEST__.browserOpened = true; };
|
||||
registry.pluginHost.get('browser').newTab = async () => { window.__TEST__.browserOpened = true; };
|
||||
});
|
||||
await page.locator('.header-right').getByRole('button', { name: 'New browser tab', exact: true }).click();
|
||||
assert.equal(await page.evaluate(() => window.__HOST_TEST__.browserOpened), true);
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.browserOpened), true);
|
||||
assert.equal(await page.locator('.header-right').getByRole('button', { name: 'Project Management', exact: true }).count(), 0);
|
||||
assert.equal(await page.locator('.header-left').getByRole('button', { name: 'Source control', exact: true }).count(), 1);
|
||||
assert.equal(await page.locator('.header-right').getByRole('button', { name: 'Source control', exact: true }).count(), 0);
|
||||
@@ -147,9 +139,9 @@ try {
|
||||
assert.equal(await page.getByRole('menuitem', { name: /New browser tab/ }).count(), 0);
|
||||
await page.getByRole('menuitem', { name: /Graph view/ }).waitFor(); await page.keyboard.press('Escape');
|
||||
for (const mode of ['light', 'dark']) {
|
||||
await page.evaluate(async mode => { const { saveAppearance } = await import('/src/lib/theme/appearance.ts'); saveAppearance({ theme: 'default', mode }); }, mode);
|
||||
await setMode(page, mode);
|
||||
await page.getByRole('button', { name: 'Plug-in views', exact: true }).click();
|
||||
await page.screenshot({ path: `output/host-navigation-pass3/plugin-navigation-${mode}.png` });
|
||||
await shot(page, `plugin-navigation-${mode}.png`);
|
||||
await page.keyboard.press('Escape');
|
||||
}
|
||||
const token = '00000000-0000-4000-8000-000000000001';
|
||||
@@ -159,9 +151,8 @@ try {
|
||||
localStorage.setItem(`runestone.tab-transfer.${token}`, JSON.stringify({ root: 'C:\\host-todo-test', created: Date.now(), buffer: { id: 'moved', relPath: 'a.md', name: 'a.md', kind: 'text', contents: '# Transferred', saved: '# Note', chrome: 'Writing', pinned: true } }));
|
||||
return layout;
|
||||
}, token);
|
||||
const detached = await context.newPage();
|
||||
detached.on('pageerror', error => errors.push(error.message));
|
||||
await detached.goto(`${origin}/?tabTransfer=${token}`);
|
||||
const detached = await openPage(context, { timeout: 30000 });
|
||||
await detached.goto(`${smokeUrl}/?tabTransfer=${token}`);
|
||||
await detached.getByRole('tab', { name: /a.md/ }).waitFor();
|
||||
await detached.getByText('# Transferred', { exact: true }).waitFor();
|
||||
assert.equal(await detached.locator('.shell.left-open,.shell.right-open').count(), 0);
|
||||
@@ -174,10 +165,10 @@ try {
|
||||
await detached.keyboard.press('Escape');
|
||||
assert.equal(await detached.evaluate(() => localStorage.getItem('runestone.workbenchLayout')), saved);
|
||||
for (const mode of ['light', 'dark']) {
|
||||
await detached.evaluate(async mode => { const { saveAppearance } = await import('/src/lib/theme/appearance.ts'); saveAppearance({ theme: 'default', mode }); }, mode);
|
||||
await setMode(detached, mode);
|
||||
await detached.setViewportSize({ width: 650, height: 600 });
|
||||
await detached.screenshot({ path: `output/host-navigation-pass3/detached-${mode}-narrow.png` });
|
||||
await shot(detached, `detached-${mode}-narrow.png`);
|
||||
}
|
||||
assert.deepEqual(errors, []);
|
||||
assert.deepEqual([...page.errors, ...detached.errors], []);
|
||||
console.log('Host navigation passed: nested file/folder rename undo/redo, expanded folders, blank New note parent, template submenu, plugin navigation dedup, detached layout isolation.');
|
||||
} finally { await browser.close(); }
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user