Add support for tests that use ESM libraries (#3172)

* Add support for tests that use ESM libraries

* Disable win32 for this test for now
This commit is contained in:
Chris Estreich 2025-05-05 08:21:40 -07:00 committed by GitHub
parent aceff7dfe8
commit 11ed7d7d46
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 1073 additions and 17 deletions

View file

@ -78,8 +78,10 @@ jobs:
run: npm run install:all
- name: Compile (to build and copy WASM files)
run: npm run compile
- name: Run unit tests
- name: Run jest unit tests
run: npx jest --silent
- name: Run vitest unit tests
run: npx vitest run --silent
test-webview:
runs-on: ${{ matrix.os }}

1032
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -337,8 +337,9 @@
"package": "npm-run-all -l -p build:webview build:esbuild check-types lint",
"pretest": "npm run compile",
"dev": "cd webview-ui && npm run dev",
"test": "node scripts/run-tests.js",
"test": "npm-run-all test:*",
"test:extension": "jest -w=40%",
"test:extension-esm": "vitest run",
"test:webview": "cd webview-ui && npm run test",
"prepare": "husky",
"publish:marketplace": "vsce publish && ovsx publish",
@ -459,6 +460,7 @@
"tsup": "^8.4.0",
"tsx": "^4.19.3",
"typescript": "^5.4.5",
"vitest": "^3.1.2",
"zod-to-ts": "^1.2.0"
},
"lint-staged": {

View file

@ -1,8 +0,0 @@
// run-tests.js
const { execSync } = require("child_process")
if (process.platform === "win32") {
execSync("npm-run-all test:*", { stdio: "inherit" })
} else {
execSync("npm-run-all -p test:*", { stdio: "inherit" })
}

View file

@ -0,0 +1,35 @@
// npx vitest run src/integrations/terminal/__tests__/ExecaTerminal.spec.ts
import { vi, describe, it, expect } from "vitest"
import { RooTerminalCallbacks } from "../types"
import { ExecaTerminal } from "../ExecaTerminal"
describe("ExecaTerminal", () => {
it("should run terminal commands and collect output", async () => {
// TODO: Run the equivalent test for Windows.
if (process.platform === "win32") {
return
}
const terminal = new ExecaTerminal(1, "/tmp")
let result
const callbacks: RooTerminalCallbacks = {
onLine: vi.fn(),
onCompleted: (output) => (result = output),
onShellExecutionStarted: vi.fn(),
onShellExecutionComplete: vi.fn(),
}
const subprocess = terminal.runCommand("ls -al", callbacks)
await subprocess
expect(callbacks.onLine).toHaveBeenCalled()
expect(callbacks.onShellExecutionStarted).toHaveBeenCalled()
expect(callbacks.onShellExecutionComplete).toHaveBeenCalled()
expect(result).toBeTypeOf("string")
expect(result).toContain("total")
})
})

7
vitest.config.ts Normal file
View file

@ -0,0 +1,7 @@
import { defineConfig } from "vitest/config"
export default defineConfig({
test: {
include: ["**/__tests__/**/*.spec.ts"],
},
})