Skip to content

Commit 42c419e

Browse files
committed
Stabilize tests in CI
1 parent 47fc679 commit 42c419e

File tree

7 files changed

+64
-25
lines changed

7 files changed

+64
-25
lines changed

.github/workflows/code-qa.yml

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,24 @@ jobs:
4343
- name: Run knip checks
4444
run: npm run knip
4545

46-
unit-test:
46+
test-extension:
47+
runs-on: ubuntu-latest
48+
env:
49+
NODE_OPTIONS: "--max_old_space_size=16384"
50+
steps:
51+
- name: Checkout code
52+
uses: actions/checkout@v4
53+
- name: Setup Node.js
54+
uses: actions/setup-node@v4
55+
with:
56+
node-version: '18'
57+
cache: 'npm'
58+
- name: Install dependencies
59+
run: npm run install:all
60+
- name: Run unit tests
61+
run: npx jest
62+
63+
test-webview:
4764
runs-on: ubuntu-latest
4865
steps:
4966
- name: Checkout code
@@ -56,7 +73,15 @@ jobs:
5673
- name: Install dependencies
5774
run: npm run install:all
5875
- name: Run unit tests
59-
run: npm test
76+
working-directory: webview-ui
77+
run: npx jest
78+
79+
unit-test:
80+
needs: [test-extension, test-webview]
81+
runs-on: ubuntu-latest
82+
steps:
83+
- name: NO-OP
84+
run: echo "All unit tests passed."
6085

6186
check-openrouter-api-key:
6287
runs-on: ubuntu-latest

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@
277277
"build": "npm run build:webview && npm run vsix",
278278
"build:webview": "cd webview-ui && npm run build",
279279
"changeset": "changeset",
280-
"check-types": "tsc --noEmit",
280+
"check-types": "tsc --noEmit && cd webview-ui && npm run check-types",
281281
"compile": "tsc -p . --outDir out && node esbuild.js",
282282
"compile:integration": "tsc -p tsconfig.integration.json",
283283
"install:all": "npm install && cd webview-ui && npm install",
@@ -289,8 +289,7 @@
289289
"package": "npm run build:webview && npm run check-types && npm run lint && node esbuild.js --production",
290290
"pretest": "npm run compile && npm run compile:integration",
291291
"dev": "cd webview-ui && npm run dev",
292-
"test": "jest && npm run test:webview",
293-
"test:webview": "cd webview-ui && npm run test",
292+
"test": "jest && cd webview-ui && npm run test",
294293
"test:integration": "npm run build && npm run compile:integration && npx dotenvx run -f .env.integration -- node ./out-integration/test/runTest.js",
295294
"prepare": "husky",
296295
"publish:marketplace": "vsce publish && ovsx publish",

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/// <reference types="jest" />
2+
13
import { applyContextMatching, applyDMP, applyGitFallback } from "../edit-strategies"
24
import { Hunk } from "../types"
35

@@ -275,7 +277,7 @@ describe("applyGitFallback", () => {
275277
expect(result.result.join("\n")).toEqual("line1\nnew line2\nline3")
276278
expect(result.confidence).toBe(1)
277279
expect(result.strategy).toBe("git-fallback")
278-
})
280+
}, 10_000)
279281

280282
it("should return original content with 0 confidence when changes cannot be applied", async () => {
281283
const hunk = {
@@ -291,5 +293,5 @@ describe("applyGitFallback", () => {
291293
expect(result.result).toEqual(content)
292294
expect(result.confidence).toBe(0)
293295
expect(result.strategy).toBe("git-fallback")
294-
})
296+
}, 10_000)
295297
})

src/services/checkpoints/__tests__/LocalCheckpointService.test.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { simpleGit, SimpleGit } from "simple-git"
99
import { CheckpointServiceFactory } from "../CheckpointServiceFactory"
1010
import { LocalCheckpointService } from "../LocalCheckpointService"
1111

12+
const tmpDir = path.join(os.tmpdir(), "test-LocalCheckpointService")
13+
1214
describe("LocalCheckpointService", () => {
1315
const taskId = "test-task"
1416

@@ -29,7 +31,7 @@ describe("LocalCheckpointService", () => {
2931
textFileContent?: string
3032
}) => {
3133
// Create a temporary directory for testing.
32-
await fs.mkdir(workspaceDir)
34+
await fs.mkdir(workspaceDir, { recursive: true })
3335

3436
// Initialize git repo.
3537
const git = simpleGit(workspaceDir)
@@ -49,7 +51,7 @@ describe("LocalCheckpointService", () => {
4951
}
5052

5153
beforeEach(async () => {
52-
const workspaceDir = path.join(os.tmpdir(), `checkpoint-service-test-${Date.now()}`)
54+
const workspaceDir = path.join(tmpDir, `checkpoint-service-test-${Date.now()}`)
5355
const repo = await initRepo({ workspaceDir })
5456

5557
testFile = repo.testFile
@@ -60,10 +62,13 @@ describe("LocalCheckpointService", () => {
6062
})
6163

6264
afterEach(async () => {
63-
await fs.rm(service.workspaceDir, { recursive: true, force: true })
6465
jest.restoreAllMocks()
6566
})
6667

68+
afterAll(async () => {
69+
await fs.rm(tmpDir, { recursive: true, force: true })
70+
})
71+
6772
describe("getDiff", () => {
6873
it("returns the correct diff between commits", async () => {
6974
await fs.writeFile(testFile, "Ahoy, world!")
@@ -316,7 +321,7 @@ describe("LocalCheckpointService", () => {
316321

317322
describe("create", () => {
318323
it("initializes a git repository if one does not already exist", async () => {
319-
const workspaceDir = path.join(os.tmpdir(), `checkpoint-service-test2-${Date.now()}`)
324+
const workspaceDir = path.join(tmpDir, `checkpoint-service-test2-${Date.now()}`)
320325
await fs.mkdir(workspaceDir)
321326
const newTestFile = path.join(workspaceDir, "test.txt")
322327
await fs.writeFile(newTestFile, "Hello, world!")
@@ -364,7 +369,7 @@ describe("LocalCheckpointService", () => {
364369
})
365370

366371
it("respects existing git user configuration", async () => {
367-
const workspaceDir = path.join(os.tmpdir(), `checkpoint-service-test-config2-${Date.now()}`)
372+
const workspaceDir = path.join(tmpDir, `checkpoint-service-test-config2-${Date.now()}`)
368373
const userName = "Custom User"
369374
const userEmail = "[email protected]"
370375
await initRepo({ workspaceDir, userName, userEmail })

src/services/checkpoints/__tests__/ShadowCheckpointService.test.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ jest.mock("globby", () => ({
1313
globby: jest.fn().mockResolvedValue([]),
1414
}))
1515

16+
const tmpDir = path.join(os.tmpdir(), "test-ShadowCheckpointService")
17+
1618
describe("ShadowCheckpointService", () => {
1719
const taskId = "test-task"
1820

1921
let workspaceGit: SimpleGit
20-
let shadowGit: SimpleGit
2122
let testFile: string
2223
let service: ShadowCheckpointService
2324

@@ -35,7 +36,7 @@ describe("ShadowCheckpointService", () => {
3536
textFileContent?: string
3637
}) => {
3738
// Create a temporary directory for testing.
38-
await fs.mkdir(workspaceDir)
39+
await fs.mkdir(workspaceDir, { recursive: true })
3940

4041
// Initialize git repo.
4142
const git = simpleGit(workspaceDir)
@@ -57,27 +58,33 @@ describe("ShadowCheckpointService", () => {
5758
beforeEach(async () => {
5859
jest.mocked(require("globby").globby).mockClear().mockResolvedValue([])
5960

60-
const shadowDir = path.join(os.tmpdir(), `shadow-${Date.now()}`)
61-
const workspaceDir = path.join(os.tmpdir(), `workspace-${Date.now()}`)
61+
const shadowDir = path.join(tmpDir, `shadow-${Date.now()}`)
62+
const workspaceDir = path.join(tmpDir, `workspace-${Date.now()}`)
63+
64+
let t0 = Date.now()
6265
const repo = await initRepo({ workspaceDir })
66+
console.log(`initRepo took ${Date.now() - t0}ms (${workspaceDir})`)
6367

6468
testFile = repo.testFile
6569

70+
t0 = Date.now()
6671
service = await CheckpointServiceFactory.create({
6772
strategy: "shadow",
6873
options: { taskId, shadowDir, workspaceDir, log: () => {} },
6974
})
75+
console.log(`CheckpointServiceFactory.create took ${Date.now() - t0}ms (${workspaceDir})`)
7076

7177
workspaceGit = repo.git
72-
shadowGit = service.git
7378
})
7479

7580
afterEach(async () => {
76-
await fs.rm(service.shadowDir, { recursive: true, force: true })
77-
await fs.rm(service.workspaceDir, { recursive: true, force: true })
7881
jest.restoreAllMocks()
7982
})
8083

84+
afterAll(async () => {
85+
await fs.rm(tmpDir, { recursive: true, force: true })
86+
})
87+
8188
describe("getDiff", () => {
8289
it("returns the correct diff between commits", async () => {
8390
await fs.writeFile(testFile, "Ahoy, world!")
@@ -299,8 +306,8 @@ describe("ShadowCheckpointService", () => {
299306

300307
describe("create", () => {
301308
it("initializes a git repository if one does not already exist", async () => {
302-
const shadowDir = path.join(os.tmpdir(), `shadow2-${Date.now()}`)
303-
const workspaceDir = path.join(os.tmpdir(), `workspace2-${Date.now()}`)
309+
const shadowDir = path.join(tmpDir, `shadow2-${Date.now()}`)
310+
const workspaceDir = path.join(tmpDir, `workspace2-${Date.now()}`)
304311
await fs.mkdir(workspaceDir)
305312

306313
const newTestFile = path.join(workspaceDir, "test.txt")

webview-ui/.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"extends": "react-app"
2+
"extends": "react-app",
3+
"ignorePatterns": ["!.storybook"]
34
}

webview-ui/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@
7575
"eslint-plugin-react-hooks": "^4.6.0",
7676
"eslint-plugin-storybook": "^0.11.2",
7777
"identity-obj-proxy": "^3.0.0",
78-
"jest": "^27.5.1",
79-
"jest-environment-jsdom": "^27.5.1",
78+
"jest": "^29.7.0",
79+
"jest-environment-jsdom": "^29.7.0",
8080
"jest-simple-dot-reporter": "^1.0.5",
8181
"shiki": "^2.3.2",
8282
"storybook": "^8.5.6",
8383
"storybook-dark-mode": "^4.0.2",
84-
"ts-jest": "^27.1.5",
84+
"ts-jest": "^29.2.5",
8585
"typescript": "^4.9.5",
8686
"vite": "6.0.11"
8787
}

0 commit comments

Comments
 (0)