(page: Page, relativePath: string)
| 162 | } |
| 163 | |
| 164 | async function openFileByPath(page: Page, relativePath: string): Promise<void> { |
| 165 | const opened = await page.evaluate(async (targetPath) => { |
| 166 | const obsidianApp = (window as any).app; |
| 167 | const file = obsidianApp?.vault?.getAbstractFileByPath?.(targetPath); |
| 168 | if (!file) return false; |
| 169 | await obsidianApp.workspace.getLeaf(true).openFile(file); |
| 170 | return true; |
| 171 | }, relativePath); |
| 172 | |
| 173 | if (!opened) { |
| 174 | throw new Error(`Could not open ${relativePath}`); |
| 175 | } |
| 176 | |
| 177 | const fileLabel = path.basename(relativePath, path.extname(relativePath)); |
| 178 | const tabHeader = page.locator(`.workspace-tab-header:has-text("${fileLabel}")`).last(); |
| 179 | if (await tabHeader.isVisible({ timeout: 5000 }).catch(() => false)) { |
| 180 | await tabHeader.click(); |
| 181 | await page.waitForTimeout(400); |
| 182 | } |
| 183 | |
| 184 | await page.waitForTimeout(1400); |
| 185 | } |
| 186 | |
| 187 | async function reloadWithoutSaving(page: Page): Promise<void> { |
| 188 | await runCommand(page, "Reload app without saving"); |
no test coverage detected