Refactor test setup and improve prompt generation error handling

This commit is contained in:
2025-03-13 08:28:00 +00:00
parent 69475782eb
commit 7eb0d49d07
8 changed files with 107 additions and 433 deletions

59
src/test/runTest.mjs Normal file
View File

@@ -0,0 +1,59 @@
import { runTests } from '@vscode/test-electron';
import * as path from 'path';
import { fileURLToPath } from 'url';
import * as os from 'os';
import * as fs from 'fs';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
async function main() {
try {
// Create a temporary test workspace
// Using the system temp directory instead of external volume
const tmpDir = os.tmpdir();
const testWorkspaceDir = path.join(tmpDir, `vscode-test-workspace-${Math.random().toString(36).substring(2)}`);
const userDataDir = path.join(tmpDir, `vscode-test-user-data-${Math.random().toString(36).substring(2)}`);
// Ensure the test workspace directory exists
if (!fs.existsSync(testWorkspaceDir)) {
fs.mkdirSync(testWorkspaceDir, { recursive: true });
}
// The folder containing the Extension Manifest package.json
// Passed to `--extensionDevelopmentPath`
const extensionDevelopmentPath = path.resolve(__dirname, '../../');
// The path to the extension test script
// Passed to --extensionTestsPath
const extensionTestsPath = path.resolve(__dirname, '../../out/test');
console.log('Running tests with the following configuration:');
console.log(`Extension Development Path: ${extensionDevelopmentPath}`);
console.log(`Extension Tests Path: ${extensionTestsPath}`);
console.log(`Workspace Dir: ${testWorkspaceDir}`);
console.log(`User Data Dir: ${userDataDir}`);
// Download VS Code, unzip it and run the integration test
await runTests({
version: '1.98.0', // Specify the exact version your extension is built for
extensionDevelopmentPath,
extensionTestsPath,
launchArgs: [
testWorkspaceDir,
'--disable-extensions',
`--user-data-dir=${userDataDir}`,
'--skip-getting-started',
'--skip-release-notes',
'--disable-telemetry',
'--disable-updates',
'--disable-crash-reporter',
'--disable-workspace-trust'
]
});
} catch (err) {
console.error('Failed to run tests', err);
process.exit(1);
}
}
main();