11import * as path from "path"
2+ import * as os from "os"
3+ import * as fs from "fs/promises"
24
35import { runTests } from "@vscode/test-electron"
46
@@ -12,10 +14,36 @@ async function main() {
1214 // Passed to --extensionTestsPath
1315 const extensionTestsPath = path . resolve ( __dirname , "./suite/index" )
1416
17+ // Create a temporary workspace folder for tests
18+ const testWorkspace = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , "roo-test-workspace-" ) )
19+
20+ // Get test filter from command line arguments or environment variable
21+ // Usage examples:
22+ // - npm run test:e2e -- --grep "write-to-file"
23+ // - TEST_GREP="apply-diff" npm run test:e2e
24+ // - TEST_FILE="task.test.js" npm run test:e2e
25+ const testGrep = process . argv . find ( ( arg , i ) => process . argv [ i - 1 ] === "--grep" ) || process . env . TEST_GREP
26+ const testFile = process . argv . find ( ( arg , i ) => process . argv [ i - 1 ] === "--file" ) || process . env . TEST_FILE
27+
28+ // Pass test filters as environment variables to the test runner
29+ const extensionTestsEnv = {
30+ ...process . env ,
31+ ...( testGrep && { TEST_GREP : testGrep } ) ,
32+ ...( testFile && { TEST_FILE : testFile } ) ,
33+ }
34+
1535 // Download VS Code, unzip it and run the integration test
16- await runTests ( { extensionDevelopmentPath, extensionTestsPath } )
17- } catch {
18- console . error ( "Failed to run tests" )
36+ await runTests ( {
37+ extensionDevelopmentPath,
38+ extensionTestsPath,
39+ launchArgs : [ testWorkspace ] ,
40+ extensionTestsEnv,
41+ } )
42+
43+ // Clean up the temporary workspace
44+ await fs . rm ( testWorkspace , { recursive : true , force : true } )
45+ } catch ( error ) {
46+ console . error ( "Failed to run tests" , error )
1947 process . exit ( 1 )
2048 }
2149}
0 commit comments