Skip to content

Commit

Permalink
Stabilize tests in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
cte committed Feb 23, 2025
1 parent 47fc679 commit 9b734c5
Show file tree
Hide file tree
Showing 11 changed files with 1,422 additions and 812 deletions.
27 changes: 25 additions & 2 deletions .github/workflows/code-qa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,5 @@ module.exports = {
],
roots: ["<rootDir>/src", "<rootDir>/webview-ui/src"],
modulePathIgnorePatterns: [".vscode-test"],
reporters: [["jest-simple-dot-reporter", {}]],
setupFiles: ["<rootDir>/src/__mocks__/jest.setup.ts"],
}
7 changes: 0 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -371,7 +370,6 @@
"glob": "^11.0.1",
"husky": "^9.1.7",
"jest": "^29.7.0",
"jest-simple-dot-reporter": "^1.0.5",
"knip": "^5.44.4",
"lint-staged": "^15.2.11",
"mkdirp": "^3.0.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/// <reference types="jest" />

import { applyContextMatching, applyDMP, applyGitFallback } from "../edit-strategies"
import { Hunk } from "../types"

Expand Down Expand Up @@ -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 = {
Expand All @@ -291,5 +293,5 @@ describe("applyGitFallback", () => {
expect(result.result).toEqual(content)
expect(result.confidence).toBe(0)
expect(result.strategy).toBe("git-fallback")
})
}, 10_000)
})
15 changes: 10 additions & 5 deletions src/services/checkpoints/__tests__/LocalCheckpointService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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!")
Expand Down Expand Up @@ -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!")
Expand Down Expand Up @@ -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 })
Expand Down
20 changes: 11 additions & 9 deletions src/services/checkpoints/__tests__/ShadowCheckpointService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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!")
Expand Down Expand Up @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion webview-ui/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"extends": "react-app"
"extends": "react-app",
"ignorePatterns": ["!.storybook"]
}
1 change: 0 additions & 1 deletion webview-ui/jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ module.exports = {
"^@vscode/webview-ui-toolkit/react$": "<rootDir>/src/__mocks__/@vscode/webview-ui-toolkit/react.ts",
"^@/(.*)$": "<rootDir>/src/$1",
},
reporters: [["jest-simple-dot-reporter", {}]],
transformIgnorePatterns: [
"/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)/)",
],
Expand Down
Loading

0 comments on commit 9b734c5

Please sign in to comment.