Move the tests from scripts/ to tests/ by feature
Unit tests go to tests/unit/<area>/, browser smoke tests to tests/smoke/<area>/, and tests against a running desktop app to tests/native/. Files named after dates, work passes, or Kanban cards get feature names, for example editorOctober12 -> editor/footnotes. scripts/ keeps the build, release, and package tools. Plugin repositories import scripts/packagePlugin.mjs, and the Terminal smoke test imports scripts/pluginMocks.mjs, which now re-exports the harness copy. The unit tests get their own type check (tests/tsconfig.json) with Node types. pnpm check runs it after the app check. Add @types/node and fix the three test mocks that it reported.
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import {createRequire} from 'node:module';
|
||||
import assert from 'node:assert/strict';
|
||||
const {chromium}=createRequire(import.meta.url)(process.env.PLAYWRIGHT_MODULE || 'playwright');
|
||||
const browser=await chromium.connectOverCDP(process.env.SPELLING_CDP_URL || 'http://127.0.0.1:9224');
|
||||
const context=browser.contexts()[0];
|
||||
const page=context.pages().find(page => new URL(page.url()).pathname === '/' && !new URL(page.url()).search);
|
||||
assert.ok(page, 'The isolated main window must be open.');
|
||||
let transferred, settings;
|
||||
try {
|
||||
const identity=await page.evaluate(async()=> (await import('/node_modules/@tauri-apps/api/path.js')).appDataDir());
|
||||
assert.match(identity, /[\\/]com\.runestone\.spelling-test[\\/]?$/);
|
||||
const pending=context.waitForEvent('page');
|
||||
const token=await page.evaluate(async()=>{
|
||||
const {invoke}=await import('/node_modules/@tauri-apps/api/core.js');
|
||||
const root=await invoke('workspace_last_path');
|
||||
const token=crypto.randomUUID(), id=crypto.randomUUID();
|
||||
localStorage.setItem('runestone.tab-transfer.'+token,JSON.stringify({root,created:Date.now(),reading:false,buffer:{id,relPath:'empty:'+id,name:'New tab',kind:'empty',imageUrl:null,contents:'',saved:'',chrome:'Writing',chromeOverride:null}}));
|
||||
await invoke('workspace_open_window',{path:root,transfer:token});
|
||||
return token;
|
||||
});
|
||||
transferred=await pending;
|
||||
await transferred.locator('.empty').waitFor();
|
||||
assert.ok(transferred.url().includes('?tabTransfer='+token));
|
||||
assert.ok(!transferred.url().includes('index.html'));
|
||||
assert.equal(await transferred.getByText('404',{exact:true}).count(),0);
|
||||
await page.waitForFunction(token=>localStorage.getItem('runestone.tab-transfer.'+token+'.accepted') === 'true',token);
|
||||
console.log('PASS: native empty-tab transfer loads the splash screen and acknowledges its saved tab state.');
|
||||
await transferred.evaluate(async()=> (await import('/node_modules/@tauri-apps/api/window.js')).getCurrentWindow().close()); transferred=undefined;
|
||||
settings=context.pages().find(page => page.url().includes('settingsWindow=true'));
|
||||
const next=settings ? Promise.resolve(settings) : context.waitForEvent('page');
|
||||
await page.evaluate(async()=> (await import('/node_modules/@tauri-apps/api/core.js')).invoke('settings_open_window'));
|
||||
settings=await next;
|
||||
await settings.waitForURL(/settingsWindow=true/);
|
||||
await settings.waitForLoadState('domcontentloaded');
|
||||
const error=await settings.evaluate(async()=>{
|
||||
try { await (await import('/node_modules/@tauri-apps/api/core.js')).invoke('theme_export',{contents:'{',defaultName:'test.json'}); }
|
||||
catch(error) { return String(error); }
|
||||
});
|
||||
assert.equal(error,'The theme contains invalid JSON.');
|
||||
console.log('PASS: the native settings window can call theme export; invalid JSON stops before the save dialog.');
|
||||
} finally {
|
||||
for(const target of [transferred,settings]) if(target&&!target.isClosed()) await target.evaluate(async()=> (await import('/node_modules/@tauri-apps/api/window.js')).getCurrentWindow().close()).catch(()=>{});
|
||||
await browser.close();
|
||||
}
|
||||
Reference in New Issue
Block a user