const { app, BrowserWindow } = require('electron'); const path = require('path'); const os = require('os'); const fs = require('fs'); const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'ink-test-rename-')); const vault = path.join(tmp, 'Vault'); fs.mkdirSync(vault); fs.writeFileSync(path.join(vault, 'A.md'), '# Target\n'); fs.writeFileSync(path.join(vault, 'B.md'), 'Go to [[A#Target]]\n'); app.setPath('userData', tmp); fs.writeFileSync(path.join(tmp, 'settings.json'), JSON.stringify({ vault, lastPage: 'A', bounds: { width: 1280, height: 860 } })); require('../electron/main.cjs'); const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); app.whenReady().then(async () => { let win; for (let i = 0; i < 80 && !(win = BrowserWindow.getAllWindows()[0]); i++) await sleep(100); const wc = win.webContents; if (wc.isLoading()) await new Promise((r) => wc.once('did-finish-load', r)); const js = (code) => wc.executeJavaScript(`(async () => { ${code} })()`); await sleep(1000); // Change heading in A await js(` const el = document.querySelector('.b-h1 .c'); el.textContent = 'New Target'; const evt = new Event('input', { bubbles: true }); el.dispatchEvent(evt); `); // Trigger blur to save await js(` const el = document.querySelector('.b-h1 .c'); el.blur(); `); await sleep(3000); // Wait for heading renames to commit (2000ms delay) // Read B const b = fs.readFileSync(path.join(vault, 'B.md'), 'utf8'); console.log("B content:", b); app.exit(); });