diff --git a/tools/test-helper/README.md b/tools/test-helper/README.md index d99aa4962..d3092d0d7 100644 --- a/tools/test-helper/README.md +++ b/tools/test-helper/README.md @@ -4,7 +4,8 @@ This is a small VS Code extension that helps with managing Typst's test suite. When installed, three new buttons appear in the menubar for all `.typ` files in the `tests` folder. -- Open test output: Opens the output and reference images of a test to the side. -- Refresh test output: Re-runs the test and reloads the preview. -- Approve test output: Copies the output into the reference folder and optimizes +- Open: Opens the output and reference images of a test to the side. +- Refresh: Refreshes the preview. +- Rerun: Re-runs the test. +- Approve: Copies the output into the reference folder and optimizes it with `oxipng`. diff --git a/tools/test-helper/extension.js b/tools/test-helper/extension.js index 775b2894b..e5325bed8 100644 --- a/tools/test-helper/extension.js +++ b/tools/test-helper/extension.js @@ -4,7 +4,7 @@ const cp = require('child_process') function activate(context) { let panel = null - function refreshPanel() { + function refreshPanel(stdout, stderr) { const uri = vscode.window.activeTextEditor.document.uri const { pngPath, refPath } = getPaths(uri) @@ -13,11 +13,15 @@ function activate(context) { const pngSrc = panel.webview.asWebviewUri(pngPath) const refSrc = panel.webview.asWebviewUri(refPath) panel.webview.html = '' - panel.webview.html = getWebviewContent(pngSrc, refSrc) + + // Make refresh notable. + setTimeout(() => { + panel.webview.html = getWebviewContent(pngSrc, refSrc, stdout, stderr) + }, 50) } } - const openCmd = vscode.commands.registerCommand("ShortcutMenuBar.openTestOutput", () => { + const openCmd = vscode.commands.registerCommand("ShortcutMenuBar.testOpen", () => { panel = vscode.window.createWebviewPanel( 'testOutput', 'Test output', @@ -25,10 +29,14 @@ function activate(context) { {} ) - refreshPanel() + refreshPanel("", "") }) - const refreshCmd = vscode.commands.registerCommand("ShortcutMenuBar.refreshTestOutput", () => { + const refreshCmd = vscode.commands.registerCommand("ShortcutMenuBar.testRefresh", () => { + refreshPanel("", "") + }) + + const rerunCmd = vscode.commands.registerCommand("ShortcutMenuBar.testRerun", () => { const uri = vscode.window.activeTextEditor.document.uri const components = uri.fsPath.split('tests') const dir = components[0] @@ -37,29 +45,27 @@ function activate(context) { cp.exec( `cargo test --manifest-path ${dir}/Cargo.toml --test typeset ${subPath}`, (err, stdout, stderr) => { - console.log(stdout) - console.log(stderr) - refreshPanel() + console.log('Ran tests') + refreshPanel(stdout, stderr) } ) }) - const approveCmd = vscode.commands.registerCommand("ShortcutMenuBar.approveTestOutput", () => { + const approveCmd = vscode.commands.registerCommand("ShortcutMenuBar.testApprove", () => { const uri = vscode.window.activeTextEditor.document.uri const { pngPath, refPath } = getPaths(uri) vscode.workspace.fs.copy(pngPath, refPath, { overwrite: true }).then(() => { console.log('Copied to reference file') cp.exec(`oxipng -o max -a ${refPath.fsPath}`, (err, stdout, stderr) => { - console.log(stdout) - console.log(stderr) - refreshPanel() + refreshPanel(stdout, stderr) }) }) }) context.subscriptions.push(openCmd) context.subscriptions.push(refreshCmd) + context.subscriptions.push(rerunCmd) context.subscriptions.push(approveCmd) } @@ -75,7 +81,7 @@ function getPaths(uri) { return { pngPath, refPath } } -function getWebviewContent(pngSrc, refSrc) { +function getWebviewContent(pngSrc, refSrc, stdout, stderr) { return ` @@ -95,6 +101,9 @@ function getWebviewContent(pngSrc, refSrc) { max-height: 40vh; object-fit: contain; } + pre { + font-family: var(--vscode-editor-font-family); + }
@@ -103,6 +112,12 @@ function getWebviewContent(pngSrc, refSrc) {${stdout}+ +
${stderr}