diff --git a/.vscode/launch.json b/.vscode/launch.json index 291c3c067a..605a464df1 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -21,10 +21,14 @@ "type": "node", "request": "launch", "name": "Launch E2E", - "runtimeExecutable": "npm", - "runtimeArgs": ["run", "test:e2e", "read_many_files"], + "program": "${workspaceFolder}/integration-tests/run-tests.js", + "args": ["--verbose", "--keep-output", "list_directory"], "skipFiles": ["/**"], - "cwd": "${workspaceFolder}" + "cwd": "${workspaceFolder}", + "console": "integratedTerminal", + "env": { + "GEMINI_SANDBOX": "false" + } }, { "name": "Attach", diff --git a/integration-tests/list_directory.test.js b/integration-tests/list_directory.test.js index 3190e48228..af7aae78e8 100644 --- a/integration-tests/list_directory.test.js +++ b/integration-tests/list_directory.test.js @@ -15,11 +15,10 @@ test('should be able to list a directory', async (t) => { rig.mkdir('subdir'); rig.sync(); - const prompt = `Can you list the files in the current directory`; - const result = await rig.run(prompt); + const prompt = `Can you list the files in the current directory. Display them in the style of 'ls'`; + const result = rig.run(prompt); const lines = result.split('\n').filter((line) => line.trim() !== ''); - assert.equal(lines.length, 2); - assert.ok(lines.includes('file1.txt')); - assert.ok(lines.includes('subdir')); + assert.ok(lines.some((line) => line.includes('file1.txt'))); + assert.ok(lines.some((line) => line.includes('subdir'))); }); diff --git a/integration-tests/run-tests.js b/integration-tests/run-tests.js index 1e8ccad9a1..848b9293fc 100644 --- a/integration-tests/run-tests.js +++ b/integration-tests/run-tests.js @@ -72,35 +72,56 @@ async function main() { `------------- Running test file: ${testFileName} ------------------------------`, ); - const child = spawn('node', ['--test', testFile], { + const nodeArgs = ['--test']; + if (verbose) { + nodeArgs.push('--test-reporter=spec'); + } + nodeArgs.push(testFile); + + const child = spawn('node', nodeArgs, { stdio: 'pipe', env: { ...process.env, GEMINI_CLI_INTEGRATION_TEST: 'true', INTEGRATION_TEST_FILE_DIR: testFileDir, KEEP_OUTPUT: keepOutput.toString(), + VERBOSE: verbose.toString(), TEST_FILE_NAME: testFileName, }, }); - if (verbose) { - child.stdout.pipe(process.stdout); - child.stderr.pipe(process.stderr); - } - + let outputStream; if (keepOutput) { const outputFile = join(testFileDir, 'output.log'); - const outputStream = createWriteStream(outputFile); - child.stdout.pipe(outputStream); - child.stderr.pipe(outputStream); + outputStream = createWriteStream(outputFile); console.log(`Output for ${testFileName} written to: ${outputFile}`); - } else if (!verbose) { - child.stdout.pipe(process.stdout); - child.stderr.pipe(process.stderr); } + child.stdout.on('data', (data) => { + if (verbose) { + process.stdout.write(data); + } + if (outputStream) { + outputStream.write(data); + } + }); + + child.stderr.on('data', (data) => { + if (verbose) { + process.stderr.write(data); + } + if (outputStream) { + outputStream.write(data); + } + }); + const exitCode = await new Promise((resolve) => { - child.on('close', resolve); + child.on('close', (code) => { + if (outputStream) { + outputStream.end(); + } + resolve(code); + }); }); if (exitCode !== 0) { diff --git a/integration-tests/test-helper.js b/integration-tests/test-helper.js index 7acdc7aa7d..7ee3db8745 100644 --- a/integration-tests/test-helper.js +++ b/integration-tests/test-helper.js @@ -72,7 +72,7 @@ export class TestRig { const output = execSync(command, execOptions); - if (env.KEEP_OUTPUT === 'true') { + if (env.KEEP_OUTPUT === 'true' || env.VERBOSE === 'true') { const testId = `${env.TEST_FILE_NAME.replace( '.test.js', '', @@ -87,7 +87,7 @@ export class TestRig { readFile(fileName) { const content = readFileSync(join(this.testDir, fileName), 'utf-8'); - if (env.KEEP_OUTPUT === 'true') { + if (env.KEEP_OUTPUT === 'true' || env.VERBOSE === 'true') { const testId = `${env.TEST_FILE_NAME.replace( '.test.js', '',