Skip to content

Commit 9b734c5

Browse files
committed
Stabilize tests in CI
1 parent 47fc679 commit 9b734c5

File tree

11 files changed

+1422
-812
lines changed

11 files changed

+1422
-812
lines changed

.github/workflows/code-qa.yml

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

46-
unit-test:
46+
test-extension:
47+
runs-on: ubuntu-latest
48+
steps:
49+
- name: Checkout code
50+
uses: actions/checkout@v4
51+
- name: Setup Node.js
52+
uses: actions/setup-node@v4
53+
with:
54+
node-version: '18'
55+
cache: 'npm'
56+
- name: Install dependencies
57+
run: npm run install:all
58+
- name: Run unit tests
59+
run: npx jest --silent
60+
61+
test-webview:
4762
runs-on: ubuntu-latest
4863
steps:
4964
- name: Checkout code
@@ -56,7 +71,15 @@ jobs:
5671
- name: Install dependencies
5772
run: npm run install:all
5873
- name: Run unit tests
59-
run: npm test
74+
working-directory: webview-ui
75+
run: npx jest --silent
76+
77+
unit-test:
78+
needs: [test-extension, test-webview]
79+
runs-on: ubuntu-latest
80+
steps:
81+
- name: NO-OP
82+
run: echo "All unit tests passed."
6083

6184
check-openrouter-api-key:
6285
runs-on: ubuntu-latest

jest.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,5 @@ module.exports = {
3636
],
3737
roots: ["<rootDir>/src", "<rootDir>/webview-ui/src"],
3838
modulePathIgnorePatterns: [".vscode-test"],
39-
reporters: [["jest-simple-dot-reporter", {}]],
4039
setupFiles: ["<rootDir>/src/__mocks__/jest.setup.ts"],
4140
}

package-lock.json

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 4 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",
@@ -371,7 +370,6 @@
371370
"glob": "^11.0.1",
372371
"husky": "^9.1.7",
373372
"jest": "^29.7.0",
374-
"jest-simple-dot-reporter": "^1.0.5",
375373
"knip": "^5.44.4",
376374
"lint-staged": "^15.2.11",
377375
"mkdirp": "^3.0.1",

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: 11 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,8 +58,8 @@ 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()}`)
6263
const repo = await initRepo({ workspaceDir })
6364

6465
testFile = repo.testFile
@@ -69,15 +70,16 @@ describe("ShadowCheckpointService", () => {
6970
})
7071

7172
workspaceGit = repo.git
72-
shadowGit = service.git
7373
})
7474

7575
afterEach(async () => {
76-
await fs.rm(service.shadowDir, { recursive: true, force: true })
77-
await fs.rm(service.workspaceDir, { recursive: true, force: true })
7876
jest.restoreAllMocks()
7977
})
8078

79+
afterAll(async () => {
80+
await fs.rm(tmpDir, { recursive: true, force: true })
81+
})
82+
8183
describe("getDiff", () => {
8284
it("returns the correct diff between commits", async () => {
8385
await fs.writeFile(testFile, "Ahoy, world!")
@@ -299,8 +301,8 @@ describe("ShadowCheckpointService", () => {
299301

300302
describe("create", () => {
301303
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()}`)
304+
const shadowDir = path.join(tmpDir, `shadow2-${Date.now()}`)
305+
const workspaceDir = path.join(tmpDir, `workspace2-${Date.now()}`)
304306
await fs.mkdir(workspaceDir)
305307

306308
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/jest.config.cjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ module.exports = {
1313
"^@vscode/webview-ui-toolkit/react$": "<rootDir>/src/__mocks__/@vscode/webview-ui-toolkit/react.ts",
1414
"^@/(.*)$": "<rootDir>/src/$1",
1515
},
16-
reporters: [["jest-simple-dot-reporter", {}]],
1716
transformIgnorePatterns: [
1817
"/node_modules/(?!(rehype-highlight|react-remark|unist-util-visit|unist-util-find-after|vfile|unified|bail|is-plain-obj|trough|vfile-message|unist-util-stringify-position|mdast-util-from-markdown|mdast-util-to-string|micromark|decode-named-character-reference|character-entities|markdown-table|zwitch|longest-streak|escape-string-regexp|unist-util-is|hast-util-to-text|@vscode/webview-ui-toolkit|@microsoft/fast-react-wrapper|@microsoft/fast-element|@microsoft/fast-foundation|@microsoft/fast-web-utilities|exenv-es6|vscrui)/)",
1918
],

0 commit comments

Comments
 (0)