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.
173 lines
9.5 KiB
JavaScript
173 lines
9.5 KiB
JavaScript
// Feature plug-in lifecycle: Table formulas and Terminal turn off, persist, reopen across windows, and uninstall without restoration.
|
|
// @requires plugin:terminal plugin:table-formulas
|
|
import assert from 'node:assert/strict';
|
|
import path from 'node:path';
|
|
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from '../_harness/index.mjs';
|
|
import { mockFeaturePlugins } from '../_harness/pluginMocks.mjs';
|
|
|
|
await runSmoke('plugins/lifecycle', async ({ browser }) => {
|
|
const context = await browser.newContext({ viewport: { width: 1440, height: 1000 } });
|
|
await context.route('**/__settings-closed', route => route.fulfill({ contentType: 'text/html', body: '<!doctype html><title>Closed settings</title>' }));
|
|
const page = await openPage(context);
|
|
const settingsPage = await openPage(context);
|
|
page.on('console', message => { if (message.type() === 'error' || message.type() === 'warning') console.log(message.type(), message.text()); });
|
|
await mockTauri(context, {
|
|
commands: test => {
|
|
const ws = 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",
|
|
},
|
|
});
|
|
const files = ws.files;
|
|
test.files = files;
|
|
return {
|
|
...ws,
|
|
workspace_write: ({ rel, contents, expected }) => {
|
|
if (expected !== undefined && files.get(rel) !== expected) throw new Error('Save blocked: file changed on disk');
|
|
files.set(rel, contents);
|
|
test.emit('workspace-event', { root: ws.root, kind: 'modify', paths: [rel] });
|
|
},
|
|
settings_open_window: () => null,
|
|
pty_profiles: () => [{ id: 'powershell', title: 'PowerShell', kind: 'powershell' }],
|
|
pty_open: async ({ id }) => {
|
|
const data = [...new TextEncoder().encode('READY 🪨\r\n\x1b[6n')];
|
|
test.emit('pty-data', { id, data: data.slice(0, 8) });
|
|
test.emit('pty-data', { id, data: data.slice(8) });
|
|
await new Promise(resolve => setTimeout(resolve, 50));
|
|
},
|
|
pty_write: () => null,
|
|
pty_resize: () => null,
|
|
pty_close: () => null,
|
|
};
|
|
},
|
|
});
|
|
await mockFeaturePlugins(context);
|
|
const output = await outputDir('plugins/lifecycle');
|
|
const source = '# Formulas\n\n| A | B |\n| --- | --- |\n| 2 | =A2*3 |\n\nAfter.\n';
|
|
const table = page.locator('.live-writer table');
|
|
const dialog = settingsPage.getByRole('dialog', { name: 'Settings', exact: true });
|
|
const switchFor = name => dialog.getByRole('switch', { name, exact: true });
|
|
const ptyCalled = command => window.__TEST__.calls.some(call => call.command === command);
|
|
const count = command => page.evaluate(command => window.__TEST__.calls.filter(call => call.command === command).length, command);
|
|
async function quickOpen(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();
|
|
await page.locator('.live-writer').waitFor();
|
|
}
|
|
async function settings() {
|
|
await page.getByRole('button', { name: 'Settings (Ctrl+,)', exact: true }).click();
|
|
await settingsPage.goto(smokeUrl + '/?settingsWindow=true');
|
|
await dialog.getByRole('button', { name: 'Plug-ins', exact: true }).click();
|
|
}
|
|
async function closeSettings() {
|
|
await settingsPage.waitForFunction(() => [...document.querySelectorAll('input[role="switch"]')].every(input => !input.disabled));
|
|
await settingsPage.goto(smokeUrl + '/__settings-closed');
|
|
await page.bringToFront();
|
|
}
|
|
|
|
try {
|
|
await page.goto(smokeUrl);
|
|
await page.getByText('smoke-workspace', { exact: true }).waitFor();
|
|
await page.evaluate(text => window.__TEST__.files.set('formulas.md', text), source);
|
|
await quickOpen('formulas.md');
|
|
await table.waitFor();
|
|
assert.equal(await table.locator('.md-table-formula').innerText(), '6');
|
|
await settings();
|
|
await switchFor('Table formulas').uncheck();
|
|
await closeSettings();
|
|
await page.waitForFunction(() => !document.querySelector('.md-table-formula'));
|
|
assert.match(await table.innerText(), /=A2\*3/);
|
|
assert.equal(await page.locator('.table-formula-tools').count(), 0);
|
|
await table.locator('td').last().click();
|
|
await page.locator('.writer-cell-editor').fill('=A2*4');
|
|
await page.keyboard.press('Enter');
|
|
await settings();
|
|
await switchFor('Table formulas').check();
|
|
await closeSettings();
|
|
await page.waitForFunction(() => document.querySelector('.md-table-formula')?.textContent === '8');
|
|
await page.getByRole('group', { name: 'Document view', exact: true }).getByRole('button', { pressed: true }).press('ArrowRight');
|
|
const preview = page.locator('.md-page table').first();
|
|
await preview.locator('.md-table-formula').waitFor();
|
|
await settings();
|
|
await switchFor('Table formulas').uncheck();
|
|
await closeSettings();
|
|
await page.waitForFunction(() => !document.querySelector('.md-page .md-table-formula'));
|
|
assert.match(await preview.innerText(), /=A2\*4/);
|
|
await settings();
|
|
await switchFor('Table formulas').check();
|
|
await closeSettings();
|
|
await preview.locator('.md-table-formula').waitFor();
|
|
assert.equal(await preview.locator('.md-table-formula').innerText(), '8');
|
|
await page.keyboard.press('Control+s');
|
|
await page.waitForFunction(() => window.__TEST__.files.get('formulas.md').includes('=A2*4'));
|
|
assert(!await page.evaluate(() => window.__TEST__.files.get('formulas.md').includes('>8<')));
|
|
|
|
await page.getByRole('button', { name: 'Terminal', exact: true }).click();
|
|
await page.waitForFunction(ptyCalled, 'pty_open');
|
|
await settings();
|
|
await switchFor('Terminal').uncheck();
|
|
await page.waitForFunction(ptyCalled, 'pty_close');
|
|
await settingsPage.screenshot({ path: path.join(output, 'plugins-settings.png') });
|
|
await closeSettings();
|
|
assert.equal(await page.getByRole('button', { name: 'Terminal', exact: true }).count(), 0);
|
|
const opened = await count('pty_open');
|
|
await page.keyboard.press('Control+j');
|
|
assert.equal(await count('pty_open'), opened);
|
|
await page.reload();
|
|
await page.getByText('smoke-workspace', { exact: true }).waitFor();
|
|
assert.equal(await page.getByRole('button', { name: 'Terminal', exact: true }).count(), 0);
|
|
await settings();
|
|
assert(!await switchFor('Terminal').isChecked());
|
|
|
|
const standalone = await openPage(context);
|
|
await standalone.goto(smokeUrl + '?terminalWindow=C%3A%5Csmoke-workspace');
|
|
await standalone.getByText(/Install and enable the Terminal plugin/).waitFor();
|
|
await switchFor('Terminal').check();
|
|
await standalone.locator('.xterm').waitFor();
|
|
await standalone.waitForFunction(ptyCalled, 'pty_open');
|
|
await switchFor('Terminal').uncheck();
|
|
await standalone.getByText(/Install and enable the Terminal plugin/).waitFor();
|
|
await standalone.waitForFunction(ptyCalled, 'pty_close');
|
|
page.errors.push(...standalone.errors);
|
|
await standalone.close();
|
|
await switchFor('Terminal').check();
|
|
await closeSettings();
|
|
await page.getByRole('button', { name: 'Terminal', exact: true }).click();
|
|
await page.locator('.xterm').waitFor();
|
|
await page.evaluate(text => window.__TEST__.files.set('formulas.md', text.replace('=A2*3', '=A2*4')), source);
|
|
await page.getByRole('button', { name: 'Terminal', exact: true }).focus();
|
|
await quickOpen('formulas.md');
|
|
await settings();
|
|
assert.equal(await dialog.getByRole('heading', { name: 'Bundled plugins' }).count(), 0);
|
|
for (const name of ['Terminal', 'Table formulas']) {
|
|
await settingsPage.waitForFunction(() => [...document.querySelectorAll('input[role="switch"]')].every(input => !input.disabled));
|
|
await dialog.locator('.card').filter({ has: settingsPage.getByRole('switch', { name, exact: true }) }).getByRole('button', { name: 'Uninstall', exact: true }).click();
|
|
const confirmation = settingsPage.getByRole('dialog', { name: `Uninstall ${name}?`, exact: true });
|
|
await confirmation.getByRole('button', { name: 'Uninstall and delete files', exact: true }).click();
|
|
await confirmation.waitFor({ state: 'hidden' });
|
|
await switchFor(name).waitFor({ state: 'detached' });
|
|
}
|
|
await closeSettings();
|
|
await page.waitForFunction(() => !document.querySelector('.md-table-formula') && !document.querySelector('.xterm'));
|
|
assert.equal(await page.getByRole('button', { name: 'Terminal', exact: true }).count(), 0);
|
|
assert.match(await table.innerText(), /=A2\*4/);
|
|
await page.reload();
|
|
await page.getByText('smoke-workspace', { exact: true }).waitFor();
|
|
await settings();
|
|
await dialog.getByText('No plugins installed.', { exact: true }).waitFor();
|
|
assert.deepEqual([...page.errors, ...settingsPage.errors], []);
|
|
} catch (error) {
|
|
await settingsPage.screenshot({ path: path.join(output, 'plugins-settings-failure.png') });
|
|
console.log('Settings page:', settingsPage.url(), await settingsPage.locator('body').innerText());
|
|
await page.screenshot({ path: path.join(output, 'plugins-failure.png') });
|
|
console.log(await page.locator('.md-page').allTextContents());
|
|
console.log([...page.errors, ...settingsPage.errors]);
|
|
throw error;
|
|
}
|
|
console.log('Plugin smoke passed: formulas, source preservation, terminal shutdown, persistence, shortcuts, cross-window enable controls, removal, and no automatic restoration.');
|
|
});
|