diff --git a/README.md b/README.md index a4e6b91..c84ce23 100644 --- a/README.md +++ b/README.md @@ -40,10 +40,12 @@ This extension requires: -- **[PostScript Language](https://marketplace.visualstudio.com/items?itemName=mxschmitt.postscript)** extension for syntax highlighting +- **[PostScript Language](https://marketplace.visualstudio.com/items?itemName=mxschmitt.postscript)** extension — required for the preview button to appear (it registers `.ps`/`.eps` files as PostScript, which this extension's preview button and activation depend on; it also provides syntax highlighting). Installed automatically alongside this extension. - **GhostScript** (provides `ps2pdf`) - **Poppler** (provides `pdftocairo` and `pdfinfo`) +> **No preview button?** If the preview icon does not appear in the editor title bar, your `.ps`/`.eps` file is likely opening as *Plain Text* (check the language indicator in the status bar). Make sure the [PostScript Language](https://marketplace.visualstudio.com/items?itemName=mxschmitt.postscript) extension is installed and enabled, then reload VS Code. + ### macOS ```bash diff --git a/package.json b/package.json index ba9235c..2e68c00 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,9 @@ "activationEvents": [ "onLanguage:postscript" ], + "extensionDependencies": [ + "mxschmitt.postscript" + ], "main": "./out/extension.js", "contributes": { "commands": [ diff --git a/src/test/runTest.ts b/src/test/runTest.ts index 81ceb16..ca41f5c 100644 --- a/src/test/runTest.ts +++ b/src/test/runTest.ts @@ -1,5 +1,56 @@ +import * as cp from "child_process"; +import * as fs from "fs"; import * as path from "path"; -import { runTests } from "@vscode/test-electron"; +import { + downloadAndUnzipVSCode, + resolveCliArgsFromVSCodeExecutablePath, + runTests, +} from "@vscode/test-electron"; + +const POSTSCRIPT_LANGUAGE_VSIX_URL = + "https://marketplace.visualstudio.com/_apis/public/gallery/publishers/mxschmitt/vsextensions/postscript/latest/vspackage"; + +/** + * This extension declares an extension dependency on mxschmitt.postscript + * (it registers the `postscript` language for .ps/.eps files), so the + * extension under test cannot activate unless that dependency is present in + * the test instance. Install it from a downloaded VSIX file: installing by id + * can fail in the test CLI when the marketplace signature verification + * tooling is unavailable ("Signature verification failed with 'ENOENT'"). + */ +async function installPostscriptLanguageExtension( + vscodeExecutablePath: string +) { + const vsixPath = path.resolve( + __dirname, + "../../.vscode-test/mxschmitt.postscript.vsix" + ); + const response = await fetch(POSTSCRIPT_LANGUAGE_VSIX_URL); + if (!response.ok) { + throw new Error( + `Failed to download PostScript Language extension: HTTP ${response.status}` + ); + } + fs.mkdirSync(path.dirname(vsixPath), { recursive: true }); + fs.writeFileSync(vsixPath, Buffer.from(await response.arrayBuffer())); + + const [cliPath, ...cliArgs] = + resolveCliArgsFromVSCodeExecutablePath(vscodeExecutablePath); + const result = cp.spawnSync( + cliPath, + [...cliArgs, "--install-extension", vsixPath], + { + encoding: "utf-8", + stdio: "inherit", + shell: process.platform === "win32", + } + ); + if (result.status !== 0) { + throw new Error( + `Failed to install PostScript Language extension (exit code ${result.status})` + ); + } +} async function main() { try { @@ -11,14 +62,20 @@ async function main() { // Passed to --extensionTestsPath const extensionTestsPath = path.resolve(__dirname, "./suite/index"); - // Download VS Code, unzip it and run the integration test + // Download VS Code and install the PostScript Language dependency + // into the test instance before running the tests. + const vscodeExecutablePath = await downloadAndUnzipVSCode(); + await installPostscriptLanguageExtension(vscodeExecutablePath); + + // Run the integration test await runTests({ + vscodeExecutablePath, extensionDevelopmentPath, extensionTestsPath, launchArgs: [extensionDevelopmentPath], }); } catch (err) { - console.error("Failed to run tests"); + console.error("Failed to run tests", err); process.exit(1); } }