Elffuss BraidHub

kikocis/continue public

49ebccd05ba8 · 2.9 KiBRawPermalink
1import fs from "node:fs";
2import * as path from "node:path";
3
4import { runTests } from "@vscode/test-electron";
5import { defaultConfig } from "core/config/default";
6
7export const testWorkspacePath = path.resolve(
8 __dirname,
9 "..",
10 "src",
11 "test",
12 "fixtures",
13 "test-workspace",
14);
15
16const continueGlobalDir = path.resolve(
17 __dirname,
18 "..",
19 "src",
20 "test",
21 "fixtures",
22 ".continue",
23);
24
25function setupTestWorkspace() {
26 if (fs.existsSync(testWorkspacePath)) {
27 fs.rmSync(testWorkspacePath, { recursive: true });
28 }
29 fs.mkdirSync(testWorkspacePath, {
30 recursive: true,
31 });
32
33 fs.writeFileSync(
34 path.join(testWorkspacePath, "test.py"),
35 "print('Hello World!')",
36 );
37 fs.writeFileSync(
38 path.join(testWorkspacePath, "index.js"),
39 "console.log('Hello World!')",
40 );
41 fs.writeFileSync(
42 path.join(testWorkspacePath, "test.py"),
43 "print('Hello World!')",
44 );
45 fs.mkdirSync(path.join(testWorkspacePath, "test-folder"));
46 fs.writeFileSync(
47 path.join(testWorkspacePath, "test-folder", "test.js"),
48 "console.log('Hello World!')",
49 );
50}
51
52function setupContinueGlobalDir() {
53 if (fs.existsSync(continueGlobalDir)) {
54 fs.rmSync(continueGlobalDir, { recursive: true });
55 }
56 fs.mkdirSync(continueGlobalDir, {
57 recursive: true,
58 });
59 fs.writeFileSync(
60 path.join(continueGlobalDir, "config.json"),
61 JSON.stringify({
62 ...defaultConfig,
63 models: [
64 {
65 title: "Test Model",
66 provider: "openai",
67 model: "gpt-3.5-turbo",
68 apiKey: "API_KEY",
69 },
70 ],
71 }),
72 );
73}
74
75function cleanupTestWorkspace() {
76 if (fs.existsSync(testWorkspacePath)) {
77 fs.rmSync(testWorkspacePath, { recursive: true });
78 }
79}
80
81function cleanupContinueGlobalDir() {
82 if (fs.existsSync(continueGlobalDir)) {
83 fs.rmSync(continueGlobalDir, { recursive: true });
84 }
85}
86
87async function main() {
88 try {
89 // The folder containing the Extension Manifest package.json
90 // Passed to `--extensionDevelopmentPath`
91
92 // Assumes this file is in out/runTestOnVSCodeHost.js
93 const extensionDevelopmentPath = path.resolve(__dirname, "../");
94 console.log("extensionDevelopmentPath", extensionDevelopmentPath);
95
96 // The path to test runner
97 // Passed to --extensionTestsPath
98 const extensionTestsPath = path.resolve(
99 extensionDevelopmentPath,
100 "out/mochaRunner",
101 );
102
103 const extensionTestsEnv = {
104 NODE_ENV: "test",
105 CONTINUE_GLOBAL_DIR: continueGlobalDir,
106 };
107
108 setupTestWorkspace();
109 setupContinueGlobalDir();
110
111 // Download VS Code, unzip it and run the integration test
112 await runTests({
113 extensionDevelopmentPath,
114 extensionTestsPath,
115 extensionTestsEnv,
116 launchArgs: [testWorkspacePath],
117 });
118 } catch (err) {
119 console.error("Failed to run tests", err);
120 process.exit(1);
121 } finally {
122 cleanupTestWorkspace();
123 cleanupContinueGlobalDir();
124 }
125}
126
127main();