Skip to content

Commit 9308a5a

Browse files
authored
Merge pull request #6091 from uinstinct/core-vitest/command
chore: migrate core (commands, control-plane, data, diff) tests to vitest
2 parents 43405bc + 2574a8b commit 9308a5a

File tree

6 files changed

+28
-19
lines changed

6 files changed

+28
-19
lines changed

core/commands/util.test.ts renamed to core/commands/util.vitest.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { ctxItemToRifWithContents } from "./util";
1+
import { describe, expect, it } from "vitest";
22
import { ContextItemWithId, RangeInFileWithContents } from "../index";
3+
import { ctxItemToRifWithContents } from "./util";
34

45
describe("ctxItemToRifWithContents", () => {
56
it("should parse start and end lines from the item name when format is valid", () => {

core/control-plane/mdm/mdm.test.ts renamed to core/control-plane/mdm/mdm.vitest.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as crypto from "crypto";
2+
import { expect, test } from "vitest";
23
import { LicenseKeyData, validateLicenseKey } from "./mdm";
34

45
// We'll create a real key pair once for all tests

core/data/log.test.ts renamed to core/data/log.vitest.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
import { DevDataLogEvent } from "@continuedev/config-yaml";
22
import fs from "fs";
33
import path from "path";
4+
import {
5+
afterAll,
6+
beforeAll,
7+
beforeEach,
8+
describe,
9+
expect,
10+
it,
11+
vi,
12+
} from "vitest";
413
import { IdeInfo, IdeSettings } from "..";
514
import { Core } from "../core";
615
import { getDevDataFilePath } from "../util/paths";
716
import { DataLogger } from "./log";
817

918
// Only mock fetch, not fs
10-
jest.mock("@continuedev/fetch");
19+
vi.mock("@continuedev/fetch");
1120

1221
const TEST_EVENT: DevDataLogEvent = {
1322
name: "tokensGenerated",
@@ -54,7 +63,7 @@ describe("DataLogger", () => {
5463

5564
beforeEach(() => {
5665
// Reset mocks
57-
jest.clearAllMocks();
66+
vi.clearAllMocks();
5867

5968
// Remove test file if it exists
6069
if (fs.existsSync(testFilePath)) {
@@ -67,7 +76,7 @@ describe("DataLogger", () => {
6776
// Mock core and required promises
6877
dataLogger.core = {
6978
configHandler: {
70-
loadConfig: jest.fn().mockResolvedValue({
79+
loadConfig: vi.fn().mockResolvedValue({
7180
config: {
7281
data: [],
7382
},
@@ -78,7 +87,7 @@ describe("DataLogger", () => {
7887
},
7988
},
8089
controlPlaneClient: {
81-
getAccessToken: jest.fn().mockResolvedValue("test-access-token"),
90+
getAccessToken: vi.fn().mockResolvedValue("test-access-token"),
8291
},
8392
},
8493
} as unknown as Core;
@@ -184,7 +193,6 @@ describe("DataLogger", () => {
184193

185194
// Read file contents and verify
186195
const fileContent = fs.readFileSync(filepath, "utf8");
187-
console.log("debug1 filecontent", fileContent);
188196
expect(fileContent).toContain('"eventName":"chatInteraction"');
189197
expect(fileContent).toContain('"prompt":"Hello, world!"');
190198
expect(fileContent).toContain('"completion":"Hello, world!"');
@@ -195,10 +203,10 @@ describe("DataLogger", () => {
195203
describe("logDevData", () => {
196204
it("should log data locally and to configured destinations", async () => {
197205
// Spy on logLocalData and logToOneDestination
198-
const logLocalDataSpy = jest
206+
const logLocalDataSpy = vi
199207
.spyOn(dataLogger, "logLocalData")
200208
.mockResolvedValue();
201-
const logToOneDestinationSpy = jest
209+
const logToOneDestinationSpy = vi
202210
.spyOn(dataLogger, "logToOneDestination")
203211
.mockResolvedValue();
204212

@@ -212,7 +220,7 @@ describe("DataLogger", () => {
212220
},
213221
};
214222

215-
dataLogger.core!.configHandler.loadConfig = jest
223+
dataLogger.core!.configHandler.loadConfig = vi
216224
.fn()
217225
.mockResolvedValue(mockConfig);
218226

core/diff/myers.test.ts renamed to core/diff/myers.vitest.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { describe, expect, test } from "vitest";
2+
13
import { dedent } from "../util";
24

35
import { myersDiff } from "./myers";

core/diff/streamDiff.test.ts renamed to core/diff/streamDiff.vitest.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import fs from "node:fs";
22
import path from "node:path";
33

4+
import { describe, expect, test } from "vitest";
5+
46
// @ts-ignore no typings available
57
import { changed, diff as myersDiff } from "myers-diff";
68
import { streamDiff } from "../diff/streamDiff.js";
@@ -54,12 +56,7 @@ function displayDiff(diff: DiffLine[]) {
5456
}
5557

5658
async function expectDiff(file: string) {
57-
const testFilePath = path.join(
58-
__dirname,
59-
"diff",
60-
"test-examples",
61-
file + ".diff",
62-
);
59+
const testFilePath = path.join(__dirname, "test-examples", file + ".diff");
6360
const testFileContents = fs.readFileSync(testFilePath, "utf-8");
6461
const [oldText, newText, expectedDiff] = testFileContents
6562
.split("\n---\n")

core/diff/util.test.ts renamed to core/diff/util.vitest.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Generated by continue
22

3-
import { matchLine, streamLines, generateLines } from "./util";
3+
import { describe, expect, it, vi } from "vitest";
44
import { ChatMessage } from "../index";
5-
import { jest } from "@jest/globals";
5+
import { generateLines, matchLine, streamLines } from "./util";
66

77
describe.skip("matchLine", () => {
88
it("should match empty lines if the first old line is also empty", () => {
@@ -146,7 +146,7 @@ describe("streamLines", () => {
146146
content: "line4",
147147
};
148148

149-
// const spy = jest.spyOn(messageContentModule, "renderChatMessage");
149+
// const spy = vi.spyOn(messageContentModule, "renderChatMessage");
150150

151151
async function* streamCompletion(): AsyncGenerator<ChatMessage> {
152152
yield messageChunk1;
@@ -164,7 +164,7 @@ describe("streamLines", () => {
164164
});
165165

166166
it("should log lines if log parameter is true", async () => {
167-
const consoleSpy = jest.spyOn(console, "log").mockImplementation(() => {});
167+
const consoleSpy = vi.spyOn(console, "log").mockImplementation(() => {});
168168

169169
async function* streamCompletion(): AsyncGenerator<string> {
170170
yield "line1\nline2\n";

0 commit comments

Comments
 (0)