runTest.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import * as path from "path"
  2. import * as os from "os"
  3. import * as fs from "fs/promises"
  4. import { runTests } from "@vscode/test-electron"
  5. async function main() {
  6. try {
  7. // The folder containing the Extension Manifest package.json
  8. // Passed to `--extensionDevelopmentPath`
  9. const extensionDevelopmentPath = path.resolve(__dirname, "../../../src")
  10. // The path to the extension test script
  11. // Passed to --extensionTestsPath
  12. const extensionTestsPath = path.resolve(__dirname, "./suite/index")
  13. // Create a temporary workspace folder for tests
  14. const testWorkspace = await fs.mkdtemp(path.join(os.tmpdir(), "roo-test-workspace-"))
  15. // Get test filter from command line arguments or environment variable
  16. // Usage examples:
  17. // - npm run test:e2e -- --grep "write-to-file"
  18. // - TEST_GREP="apply-diff" npm run test:e2e
  19. // - TEST_FILE="task.test.js" npm run test:e2e
  20. const testGrep = process.argv.find((arg, i) => process.argv[i - 1] === "--grep") || process.env.TEST_GREP
  21. const testFile = process.argv.find((arg, i) => process.argv[i - 1] === "--file") || process.env.TEST_FILE
  22. // Pass test filters as environment variables to the test runner
  23. const extensionTestsEnv = {
  24. ...process.env,
  25. ...(testGrep && { TEST_GREP: testGrep }),
  26. ...(testFile && { TEST_FILE: testFile }),
  27. }
  28. // Download VS Code, unzip it and run the integration test
  29. await runTests({
  30. extensionDevelopmentPath,
  31. extensionTestsPath,
  32. launchArgs: [testWorkspace],
  33. extensionTestsEnv,
  34. version: process.env.VSCODE_VERSION || "1.101.2",
  35. })
  36. // Clean up the temporary workspace
  37. await fs.rm(testWorkspace, { recursive: true, force: true })
  38. } catch (error) {
  39. console.error("Failed to run tests", error)
  40. process.exit(1)
  41. }
  42. }
  43. main()