Merge pull request #6091 from uinstinct/core-vitest/command

chore: migrate core (commands, control-plane, data, diff) tests to vitest
This commit is contained in:
Nate Sesti 2025-06-23 09:52:05 -07:00 • committed by GitHub
commit 9308a5a33c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 28 additions and 19 deletions

View file

@ -1,5 +1,6 @@
import { ctxItemToRifWithContents } from "./util";
import { describe, expect, it } from "vitest";
import { ContextItemWithId, RangeInFileWithContents } from "../index";
import { ctxItemToRifWithContents } from "./util";
describe("ctxItemToRifWithContents", () => {
it("should parse start and end lines from the item name when format is valid", () => {

View file

@ -1,4 +1,5 @@
import * as crypto from "crypto";
import { expect, test } from "vitest";
import { LicenseKeyData, validateLicenseKey } from "./mdm";
// We'll create a real key pair once for all tests

View file

@ -1,13 +1,22 @@
import { DevDataLogEvent } from "@continuedev/config-yaml";
import fs from "fs";
import path from "path";
import {
afterAll,
beforeAll,
beforeEach,
describe,
expect,
it,
vi,
} from "vitest";
import { IdeInfo, IdeSettings } from "..";
import { Core } from "../core";
import { getDevDataFilePath } from "../util/paths";
import { DataLogger } from "./log";
// Only mock fetch, not fs
jest.mock("@continuedev/fetch");
vi.mock("@continuedev/fetch");
const TEST_EVENT: DevDataLogEvent = {
name: "tokensGenerated",
@ -54,7 +63,7 @@ describe("DataLogger", () => {
beforeEach(() => {
// Reset mocks
jest.clearAllMocks();
vi.clearAllMocks();
// Remove test file if it exists
if (fs.existsSync(testFilePath)) {
@ -67,7 +76,7 @@ describe("DataLogger", () => {
// Mock core and required promises
dataLogger.core = {
configHandler: {
loadConfig: jest.fn().mockResolvedValue({
loadConfig: vi.fn().mockResolvedValue({
config: {
data: [],
},
@ -78,7 +87,7 @@ describe("DataLogger", () => {
},
},
controlPlaneClient: {
getAccessToken: jest.fn().mockResolvedValue("test-access-token"),
getAccessToken: vi.fn().mockResolvedValue("test-access-token"),
},
},
} as unknown as Core;
@ -184,7 +193,6 @@ describe("DataLogger", () => {
// Read file contents and verify
const fileContent = fs.readFileSync(filepath, "utf8");
console.log("debug1 filecontent", fileContent);
expect(fileContent).toContain('"eventName":"chatInteraction"');
expect(fileContent).toContain('"prompt":"Hello, world!"');
expect(fileContent).toContain('"completion":"Hello, world!"');
@ -195,10 +203,10 @@ describe("DataLogger", () => {
describe("logDevData", () => {
it("should log data locally and to configured destinations", async () => {
// Spy on logLocalData and logToOneDestination
const logLocalDataSpy = jest
const logLocalDataSpy = vi
.spyOn(dataLogger, "logLocalData")
.mockResolvedValue();
const logToOneDestinationSpy = jest
const logToOneDestinationSpy = vi
.spyOn(dataLogger, "logToOneDestination")
.mockResolvedValue();
@ -212,7 +220,7 @@ describe("DataLogger", () => {
},
};
dataLogger.core!.configHandler.loadConfig = jest
dataLogger.core!.configHandler.loadConfig = vi
.fn()
.mockResolvedValue(mockConfig);

View file

@ -1,3 +1,5 @@
import { describe, expect, test } from "vitest";
import { dedent } from "../util";
import { myersDiff } from "./myers";

View file

@ -1,6 +1,8 @@
import fs from "node:fs";
import path from "node:path";
import { describe, expect, test } from "vitest";
// @ts-ignore no typings available
import { changed, diff as myersDiff } from "myers-diff";
import { streamDiff } from "../diff/streamDiff.js";
@ -54,12 +56,7 @@ function displayDiff(diff: DiffLine[]) {
}
async function expectDiff(file: string) {
const testFilePath = path.join(
__dirname,
"diff",
"test-examples",
file + ".diff",
);
const testFilePath = path.join(__dirname, "test-examples", file + ".diff");
const testFileContents = fs.readFileSync(testFilePath, "utf-8");
const [oldText, newText, expectedDiff] = testFileContents
.split("\n---\n")

View file

@ -1,8 +1,8 @@
// Generated by continue
import { matchLine, streamLines, generateLines } from "./util";
import { describe, expect, it, vi } from "vitest";
import { ChatMessage } from "../index";
import { jest } from "@jest/globals";
import { generateLines, matchLine, streamLines } from "./util";
describe.skip("matchLine", () => {
it("should match empty lines if the first old line is also empty", () => {
@ -146,7 +146,7 @@ describe("streamLines", () => {
content: "line4",
};
// const spy = jest.spyOn(messageContentModule, "renderChatMessage");
// const spy = vi.spyOn(messageContentModule, "renderChatMessage");
async function* streamCompletion(): AsyncGenerator<ChatMessage> {
yield messageChunk1;
@ -164,7 +164,7 @@ describe("streamLines", () => {
});
it("should log lines if log parameter is true", async () => {
const consoleSpy = jest.spyOn(console, "log").mockImplementation(() => {});
const consoleSpy = vi.spyOn(console, "log").mockImplementation(() => {});
async function* streamCompletion(): AsyncGenerator<string> {
yield "line1\nline2\n";