Forráskód Böngészése

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

* Add support for tests that use ESM libraries

* Disable win32 for this test for now
Chris Estreich 7 hónapja
szülő
commit
11ed7d7d46

+ 3 - 1
.github/workflows/code-qa.yml

@@ -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 }}

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 1049 - 48
package-lock.json


+ 3 - 1
package.json

@@ -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": {

+ 0 - 8
scripts/run-tests.js

@@ -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" })
-}

+ 35 - 0
src/integrations/terminal/__tests__/ExecaTerminal.spec.ts

@@ -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 - 0
vitest.config.ts

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

Nem az összes módosított fájl került megjelenítésre, mert túl sok fájl változott