- pnpm smoke runs tests/smoke/ in parallel. It starts Vite when nothing serves SMOKE_URL, finds an installed Chrome when Playwright has no Chromium, and skips a test with a reason when a requirement that the test declares with "// @requires" is missing. Logs go to output/smoke/logs/. - tests/smoke/_harness/ holds the Playwright launch, page error collection, the Tauri IPC mock with an in-memory workspace, and output folders. tabs/order uses it as the first converted test. - Pin Playwright 1.63.0, the version that browser-runtime uses. - RUNESTONE_PLUGIN_REPOS names the folder of the sibling plugin checkouts for buildPlugins, the menu audit, and the smoke tests. - buildInstaller restores the version fields after Ctrl+C, keeps the backups of each attempt, stops when the browser runtime is not staged, and writes the file name instead of absolute paths to host.json. - buildPlugins clears the staged Table Formulas package before copying. - plugins/choiceMenus used the wrong Local Autocomplete folder name.
184 lines
14 KiB
JavaScript
184 lines
14 KiB
JavaScript
// @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);
|
|
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'),
|
|
};
|
|
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;
|
|
},
|
|
};
|
|
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);
|
|
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);
|
|
await page.keyboard.press('Control+y'); await row('folder/nested/renamed.md').waitFor();
|
|
for (const path of ['folder', 'folder/nested', 'other']) await expanded(path);
|
|
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);
|
|
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);
|
|
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')), '');
|
|
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');
|
|
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 paneMenu(); await item('New note').focus(); await page.keyboard.press('ArrowRight');
|
|
await page.screenshot({ path: `output/host-navigation-pass3/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' });
|
|
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 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);
|
|
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.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();
|
|
const graph = page.getByRole('menuitem', { name: /Show Git graph/ });
|
|
await graph.waitFor();
|
|
assert.equal(await page.getByRole('menuitem', { name: /source control/i }).count(), 0);
|
|
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 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);
|
|
external.pluginNavigation.set([{ owner: 'pm-test', id: 'pm', title: 'Project Management', icon: 'kanban', placement: 'editor', toolbar: true }, { owner: 'git-test', id: 'source', title: 'Source control', icon: 'git', placement: 'sidebar', toolbar: true }]);
|
|
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; };
|
|
});
|
|
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.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);
|
|
await page.getByRole('button', { name: 'Plug-in views', exact: true }).click();
|
|
assert.equal(await page.getByRole('menuitem', { name: /Project Management/ }).count(), 1);
|
|
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 page.getByRole('button', { name: 'Plug-in views', exact: true }).click();
|
|
await page.screenshot({ path: `output/host-navigation-pass3/plugin-navigation-${mode}.png` });
|
|
await page.keyboard.press('Escape');
|
|
}
|
|
const token = '00000000-0000-4000-8000-000000000001';
|
|
const saved = await page.evaluate(token => {
|
|
const layout = JSON.stringify({ leftOpen: true, rightOpen: true, leftWidth: 280, rightWidth: 260, leftView: 'files' });
|
|
localStorage.setItem('runestone.workbenchLayout', layout);
|
|
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}`);
|
|
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);
|
|
assert.equal(await detached.getByRole('button', { name: 'Show outline', exact: true }).count(), 0);
|
|
assert.equal(await detached.evaluate(() => localStorage.getItem('runestone.workbenchLayout')), saved);
|
|
assert.equal(await detached.getByRole('button', { name: 'Files', exact: true }).count(), 0);
|
|
await detached.keyboard.press('Control+b');
|
|
await detached.keyboard.press('Control+Shift+f');
|
|
assert.equal(await detached.locator('aside.left,aside.right,.plugin-ribbon,.gutter-v').count(), 0);
|
|
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 detached.setViewportSize({ width: 650, height: 600 });
|
|
await detached.screenshot({ path: `output/host-navigation-pass3/detached-${mode}-narrow.png` });
|
|
}
|
|
assert.deepEqual(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(); }
|