more progress on tests

This commit is contained in:
Nate Sesti 2024-06-09 18:32:43 -07:00
parent b9ef50497f
commit cf88f31610
4 changed files with 5 additions and 127 deletions

View file

@ -16,7 +16,8 @@ export default {
},
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
extensionsToTreatAsEsm: [".ts"],
// Remove or comment out the moduleNameMapper configuration
moduleNameMapper: {
"^(\\.{1,2}/.*)\\.js$": "$1",
"^(.*)\\.js$": "$1",
},
};

View file

@ -57,7 +57,7 @@
"@biomejs/biome": "1.6.4",
"@google/generative-ai": "^0.11.4",
"@types/follow-redirects": "^1.14.4",
"@types/jest": "^29.5.11",
"@types/jest": "^29.5.12",
"@types/jquery": "^3.5.29",
"@types/mustache": "^4.2.5",
"@types/uuid": "^9.0.7",

View file

@ -3,7 +3,7 @@
"version": "1.0.13",
"description": "The Continue Core contains functionality that can be shared across web, VS Code, or Node.js server. It is written in TypeScript and contains much of the functionality that was previously inside of the legacy Continue Python Server.",
"scripts": {
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest ./test/diff.test.ts",
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest ./test",
"build:npm": "tsc -p ./tsconfig.npm.json",
"lint": "eslint . --ext ts",
"lint:fix": "eslint . --ext ts --fix"
@ -16,7 +16,7 @@
"@biomejs/biome": "1.6.4",
"@google/generative-ai": "^0.11.4",
"@types/follow-redirects": "^1.14.4",
"@types/jest": "^29.5.11",
"@types/jest": "^29.5.12",
"@types/jquery": "^3.5.29",
"@types/mustache": "^4.2.5",
"@types/uuid": "^9.0.7",

View file

@ -1,123 +0,0 @@
import * as dotenv from "dotenv";
import fetch from "node-fetch";
import { ContinueSDK } from "../index.js";
import EditSlashCommand, { getPromptParts } from "../commands/slash/edit.js";
import { contextItemToRangeInFileWithContents } from "../commands/util.js";
import FreeTrial from "../llm/llms/FreeTrial.js";
import Ollama from "../llm/llms/Ollama.js";
import { dedentAndGetCommonWhitespace } from "../util/index.js";
import FileSystemIde from "../util/filesystem.js";
jest.setTimeout(100_000);
dotenv.config();
const TEST_CONTEXT_ITEM = {
name: "editme.py (1-2)",
description: "/Users/natesesti/Desktop/continue/core/llm/test/editme.py",
content: "def average(nums: list) -> float:\n pass\n",
id: {
providerTitle: "code",
itemId: "/Users/natesesti/Desktop/continue/core/llm/test/editme.py",
},
editing: true,
};
const f1 = `\
def maximum(nums: list) -> float:
return max(nums)
`;
const f2 = `\
def total(nums: list) -> float:
s = sum(nums)
return s
`;
const f3 = `\
def average(nums: list) -> float:
return sum(nums) / len(nums)
`;
const fullFile = `${f1}\n${f2}\n${f3}\n`;
const TEST_CONTEXT_ITEM2 = {
name: "editme2.py (4-7)",
description: "/Users/natesesti/Desktop/continue/core/llm/test/editme2.py",
content: f2,
id: {
providerTitle: "code",
itemId: "/Users/natesesti/Desktop/continue/core/llm/test/editme2.py",
},
editing: true,
};
describe("/edit slash command", () => {
test.only("doesn't break", async () => {
const command = EditSlashCommand;
const sdk: ContinueSDK = {
ide: new FileSystemIde(),
// llm: new FreeTrial({ model: "gpt-3.5-turbo" }),
llm: new Ollama({ model: "codellama-7b" }),
addContextItem: (item: any) => {},
history: [],
input: "implement this function",
contextItems: [TEST_CONTEXT_ITEM],
selectedCode: [],
config: {} as any,
fetch,
};
let total = "";
for await (const update of command.run(sdk)) {
if (update === undefined) {continue;}
total += update;
}
console.log(total);
});
test.skip("dedentAndGetCommonWhitespace", () => {
// TODO
const [dedented, whitespace] = dedentAndGetCommonWhitespace(
`\
...
...
...
..
. .`,
);
expect(dedented).toEqual(`\
...
...
...
..
. .`);
expect(whitespace).toEqual(" ");
const [dedented2, whitespace2] = dedentAndGetCommonWhitespace("");
expect(dedented2).toEqual("");
expect(whitespace2).toEqual("");
const [dedented3, whitespace3] = dedentAndGetCommonWhitespace(" \n\n ");
expect(dedented3).toEqual(" \n\n ");
expect(whitespace3).toEqual("");
});
test.skip("getPromptParts", async () => {
// TODO
const { filePrefix, fileSuffix, contents, maxTokens } =
await getPromptParts(
contextItemToRangeInFileWithContents(TEST_CONTEXT_ITEM2),
fullFile,
new FreeTrial({ model: "gpt-3.5-turbo" }),
"implement this function",
1200,
);
expect(filePrefix).toEqual(`${f1}`);
expect(`${fileSuffix}\n`).toEqual(`\n${f3}`);
expect(contents).toEqual(f2);
expect(maxTokens).toEqual(2048);
});
});