cte 10 месяцев назад
Родитель
Сommit
f11c0afa1e

+ 25 - 2
.github/workflows/code-qa.yml

@@ -43,7 +43,22 @@ jobs:
       - name: Run knip checks
         run: npm run knip
 
-  unit-test:
+  test-extension:
+    runs-on: ubuntu-latest
+    steps:
+      - name: Checkout code
+        uses: actions/checkout@v4
+      - name: Setup Node.js
+        uses: actions/setup-node@v4
+        with:
+          node-version: '18'
+          cache: 'npm'
+      - name: Install dependencies
+        run: npm run install:all
+      - name: Run unit tests
+        run: npx jest --silent
+
+  test-webview:
     runs-on: ubuntu-latest
     steps:
       - name: Checkout code
@@ -56,7 +71,15 @@ jobs:
       - name: Install dependencies
         run: npm run install:all
       - name: Run unit tests
-        run: npm test
+        working-directory: webview-ui
+        run: npx jest --silent
+
+  unit-test:
+    needs: [test-extension, test-webview]
+    runs-on: ubuntu-latest
+    steps:
+      - name: NO-OP
+        run: echo "All unit tests passed."
 
   check-openrouter-api-key:
     runs-on: ubuntu-latest

+ 2 - 1
package-lock.json

@@ -11312,7 +11312,8 @@
 			"version": "1.0.5",
 			"resolved": "https://registry.npmjs.org/jest-simple-dot-reporter/-/jest-simple-dot-reporter-1.0.5.tgz",
 			"integrity": "sha512-cZLFG/C7k0+WYoIGGuGXKm0vmJiXlWG/m3uCZ4RaMPYxt8lxjdXMLHYkxXaQ7gVWaSPe7uAPCEUcRxthC5xskg==",
-			"dev": true
+			"dev": true,
+			"license": "MIT"
 		},
 		"node_modules/jest-snapshot": {
 			"version": "29.7.0",

+ 2 - 3
package.json

@@ -277,7 +277,7 @@
 		"build": "npm run build:webview && npm run vsix",
 		"build:webview": "cd webview-ui && npm run build",
 		"changeset": "changeset",
-		"check-types": "tsc --noEmit",
+		"check-types": "tsc --noEmit && cd webview-ui && npm run check-types",
 		"compile": "tsc -p . --outDir out && node esbuild.js",
 		"compile:integration": "tsc -p tsconfig.integration.json",
 		"install:all": "npm install && cd webview-ui && npm install",
@@ -289,8 +289,7 @@
 		"package": "npm run build:webview && npm run check-types && npm run lint && node esbuild.js --production",
 		"pretest": "npm run compile && npm run compile:integration",
 		"dev": "cd webview-ui && npm run dev",
-		"test": "jest && npm run test:webview",
-		"test:webview": "cd webview-ui && npm run test",
+		"test": "jest && cd webview-ui && npm run test",
 		"test:integration": "npm run build && npm run compile:integration && npx dotenvx run -f .env.integration -- node ./out-integration/test/runTest.js",
 		"prepare": "husky",
 		"publish:marketplace": "vsce publish && ovsx publish",

+ 4 - 2
src/core/diff/strategies/new-unified/__tests__/edit-strategies.test.ts

@@ -1,3 +1,5 @@
+/// <reference types="jest" />
+
 import { applyContextMatching, applyDMP, applyGitFallback } from "../edit-strategies"
 import { Hunk } from "../types"
 
@@ -275,7 +277,7 @@ describe("applyGitFallback", () => {
 		expect(result.result.join("\n")).toEqual("line1\nnew line2\nline3")
 		expect(result.confidence).toBe(1)
 		expect(result.strategy).toBe("git-fallback")
-	})
+	}, 10_000)
 
 	it("should return original content with 0 confidence when changes cannot be applied", async () => {
 		const hunk = {
@@ -291,5 +293,5 @@ describe("applyGitFallback", () => {
 		expect(result.result).toEqual(content)
 		expect(result.confidence).toBe(0)
 		expect(result.strategy).toBe("git-fallback")
-	})
+	}, 10_000)
 })

+ 10 - 5
src/services/checkpoints/__tests__/LocalCheckpointService.test.ts

@@ -9,6 +9,8 @@ import { simpleGit, SimpleGit } from "simple-git"
 import { CheckpointServiceFactory } from "../CheckpointServiceFactory"
 import { LocalCheckpointService } from "../LocalCheckpointService"
 
+const tmpDir = path.join(os.tmpdir(), "test-LocalCheckpointService")
+
 describe("LocalCheckpointService", () => {
 	const taskId = "test-task"
 
@@ -29,7 +31,7 @@ describe("LocalCheckpointService", () => {
 		textFileContent?: string
 	}) => {
 		// Create a temporary directory for testing.
-		await fs.mkdir(workspaceDir)
+		await fs.mkdir(workspaceDir, { recursive: true })
 
 		// Initialize git repo.
 		const git = simpleGit(workspaceDir)
@@ -49,7 +51,7 @@ describe("LocalCheckpointService", () => {
 	}
 
 	beforeEach(async () => {
-		const workspaceDir = path.join(os.tmpdir(), `checkpoint-service-test-${Date.now()}`)
+		const workspaceDir = path.join(tmpDir, `checkpoint-service-test-${Date.now()}`)
 		const repo = await initRepo({ workspaceDir })
 
 		testFile = repo.testFile
@@ -60,10 +62,13 @@ describe("LocalCheckpointService", () => {
 	})
 
 	afterEach(async () => {
-		await fs.rm(service.workspaceDir, { recursive: true, force: true })
 		jest.restoreAllMocks()
 	})
 
+	afterAll(async () => {
+		await fs.rm(tmpDir, { recursive: true, force: true })
+	})
+
 	describe("getDiff", () => {
 		it("returns the correct diff between commits", async () => {
 			await fs.writeFile(testFile, "Ahoy, world!")
@@ -316,7 +321,7 @@ describe("LocalCheckpointService", () => {
 
 	describe("create", () => {
 		it("initializes a git repository if one does not already exist", async () => {
-			const workspaceDir = path.join(os.tmpdir(), `checkpoint-service-test2-${Date.now()}`)
+			const workspaceDir = path.join(tmpDir, `checkpoint-service-test2-${Date.now()}`)
 			await fs.mkdir(workspaceDir)
 			const newTestFile = path.join(workspaceDir, "test.txt")
 			await fs.writeFile(newTestFile, "Hello, world!")
@@ -364,7 +369,7 @@ describe("LocalCheckpointService", () => {
 		})
 
 		it("respects existing git user configuration", async () => {
-			const workspaceDir = path.join(os.tmpdir(), `checkpoint-service-test-config2-${Date.now()}`)
+			const workspaceDir = path.join(tmpDir, `checkpoint-service-test-config2-${Date.now()}`)
 			const userName = "Custom User"
 			const userEmail = "[email protected]"
 			await initRepo({ workspaceDir, userName, userEmail })

+ 11 - 9
src/services/checkpoints/__tests__/ShadowCheckpointService.test.ts

@@ -13,11 +13,12 @@ jest.mock("globby", () => ({
 	globby: jest.fn().mockResolvedValue([]),
 }))
 
+const tmpDir = path.join(os.tmpdir(), "test-ShadowCheckpointService")
+
 describe("ShadowCheckpointService", () => {
 	const taskId = "test-task"
 
 	let workspaceGit: SimpleGit
-	let shadowGit: SimpleGit
 	let testFile: string
 	let service: ShadowCheckpointService
 
@@ -35,7 +36,7 @@ describe("ShadowCheckpointService", () => {
 		textFileContent?: string
 	}) => {
 		// Create a temporary directory for testing.
-		await fs.mkdir(workspaceDir)
+		await fs.mkdir(workspaceDir, { recursive: true })
 
 		// Initialize git repo.
 		const git = simpleGit(workspaceDir)
@@ -57,8 +58,8 @@ describe("ShadowCheckpointService", () => {
 	beforeEach(async () => {
 		jest.mocked(require("globby").globby).mockClear().mockResolvedValue([])
 
-		const shadowDir = path.join(os.tmpdir(), `shadow-${Date.now()}`)
-		const workspaceDir = path.join(os.tmpdir(), `workspace-${Date.now()}`)
+		const shadowDir = path.join(tmpDir, `shadow-${Date.now()}`)
+		const workspaceDir = path.join(tmpDir, `workspace-${Date.now()}`)
 		const repo = await initRepo({ workspaceDir })
 
 		testFile = repo.testFile
@@ -69,15 +70,16 @@ describe("ShadowCheckpointService", () => {
 		})
 
 		workspaceGit = repo.git
-		shadowGit = service.git
 	})
 
 	afterEach(async () => {
-		await fs.rm(service.shadowDir, { recursive: true, force: true })
-		await fs.rm(service.workspaceDir, { recursive: true, force: true })
 		jest.restoreAllMocks()
 	})
 
+	afterAll(async () => {
+		await fs.rm(tmpDir, { recursive: true, force: true })
+	})
+
 	describe("getDiff", () => {
 		it("returns the correct diff between commits", async () => {
 			await fs.writeFile(testFile, "Ahoy, world!")
@@ -299,8 +301,8 @@ describe("ShadowCheckpointService", () => {
 
 	describe("create", () => {
 		it("initializes a git repository if one does not already exist", async () => {
-			const shadowDir = path.join(os.tmpdir(), `shadow2-${Date.now()}`)
-			const workspaceDir = path.join(os.tmpdir(), `workspace2-${Date.now()}`)
+			const shadowDir = path.join(tmpDir, `shadow2-${Date.now()}`)
+			const workspaceDir = path.join(tmpDir, `workspace2-${Date.now()}`)
 			await fs.mkdir(workspaceDir)
 
 			const newTestFile = path.join(workspaceDir, "test.txt")

+ 2 - 1
webview-ui/.eslintrc.json

@@ -1,3 +1,4 @@
 {
-	"extends": "react-app"
+	"extends": "react-app",
+	"ignorePatterns": ["!.storybook"]
 }

Разница между файлами не показана из-за своего большого размера
+ 380 - 246
webview-ui/package-lock.json


+ 3 - 3
webview-ui/package.json

@@ -75,13 +75,13 @@
 		"eslint-plugin-react-hooks": "^4.6.0",
 		"eslint-plugin-storybook": "^0.11.2",
 		"identity-obj-proxy": "^3.0.0",
-		"jest": "^27.5.1",
-		"jest-environment-jsdom": "^27.5.1",
+		"jest": "^29.7.0",
+		"jest-environment-jsdom": "^29.7.0",
 		"jest-simple-dot-reporter": "^1.0.5",
 		"shiki": "^2.3.2",
 		"storybook": "^8.5.6",
 		"storybook-dark-mode": "^4.0.2",
-		"ts-jest": "^27.1.5",
+		"ts-jest": "^29.2.5",
 		"typescript": "^4.9.5",
 		"vite": "6.0.11"
 	}

Некоторые файлы не были показаны из-за большого количества измененных файлов