diff options
| author | Tommaso Sciortino <[email protected]> | 2025-08-12 15:57:27 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-08-12 22:57:27 +0000 |
| commit | 9d023be1d16a6bf7427569f863e6cfd2c3442d8b (patch) | |
| tree | b983227f56fd9f26008b475061a345b61207c970 /integration-tests/run-tests.js | |
| parent | 8d6eb8c322890b5cdf20d4a30dd17afb1541f5aa (diff) | |
Upgrade integration tests to use Vitest (#6021)
Diffstat (limited to 'integration-tests/run-tests.js')
| -rw-r--r-- | integration-tests/run-tests.js | 182 |
1 files changed, 0 insertions, 182 deletions
diff --git a/integration-tests/run-tests.js b/integration-tests/run-tests.js deleted file mode 100644 index b33e1afa..00000000 --- a/integration-tests/run-tests.js +++ /dev/null @@ -1,182 +0,0 @@ -/** - * @license - * Copyright 2025 Google LLC - * SPDX-License-Identifier: Apache-2.0 - */ - -import { spawnSync, spawn } from 'child_process'; -import { mkdirSync, rmSync, createWriteStream } from 'fs'; -import { join, dirname, basename } from 'path'; -import { fileURLToPath } from 'url'; -import { glob } from 'glob'; - -async function main() { - const __dirname = dirname(fileURLToPath(import.meta.url)); - const rootDir = join(__dirname, '..'); - const integrationTestsDir = join(rootDir, '.integration-tests'); - - if (process.env.GEMINI_SANDBOX === 'docker' && !process.env.IS_DOCKER) { - console.log('Building sandbox for Docker...'); - const buildResult = spawnSync('npm', ['run', 'build:all'], { - stdio: 'inherit', - }); - if (buildResult.status !== 0) { - console.error('Sandbox build failed.'); - process.exit(1); - } - } - - const runId = `${Date.now()}`; - const runDir = join(integrationTestsDir, runId); - - mkdirSync(runDir, { recursive: true }); - - const args = process.argv.slice(2); - const keepOutput = - process.env.KEEP_OUTPUT === 'true' || args.includes('--keep-output'); - if (keepOutput) { - const keepOutputIndex = args.indexOf('--keep-output'); - if (keepOutputIndex > -1) { - args.splice(keepOutputIndex, 1); - } - console.log(`Keeping output for test run in: ${runDir}`); - } - - const verbose = args.includes('--verbose'); - if (verbose) { - const verboseIndex = args.indexOf('--verbose'); - if (verboseIndex > -1) { - args.splice(verboseIndex, 1); - } - } - - const testPatterns = - args.length > 0 - ? args.map((arg) => `integration-tests/${arg}.test.ts`) - : ['integration-tests/*.test.ts']; - const testFiles = glob.sync(testPatterns, { cwd: rootDir, absolute: true }); - - for (const testFile of testFiles) { - const testFileName = basename(testFile); - console.log(` Found test file: ${testFileName}`); - } - - const MAX_RETRIES = 3; - let allTestsPassed = true; - - for (const testFile of testFiles) { - const testFileName = basename(testFile); - const testFileDir = join(runDir, testFileName); - mkdirSync(testFileDir, { recursive: true }); - - console.log( - `------------- Running test file: ${testFileName} ------------------------------`, - ); - - let attempt = 0; - let testFilePassed = false; - let lastStdout = []; - let lastStderr = []; - - while (attempt < MAX_RETRIES && !testFilePassed) { - attempt++; - if (attempt > 1) { - console.log( - `--- Retrying ${testFileName} (attempt ${attempt} of ${MAX_RETRIES}) ---`, - ); - } - - const nodeArgs = ['--test']; - if (verbose) { - nodeArgs.push('--test-reporter=spec'); - } - nodeArgs.push(testFile); - - const child = spawn('npx', ['tsx', ...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, - TELEMETRY_LOG_FILE: join(testFileDir, 'telemetry.log'), - }, - }); - - let outputStream; - if (keepOutput) { - const outputFile = join(testFileDir, `output-attempt-${attempt}.log`); - outputStream = createWriteStream(outputFile); - console.log(`Output for ${testFileName} written to: ${outputFile}`); - } - - const stdout = []; - const stderr = []; - - child.stdout.on('data', (data) => { - if (verbose) { - process.stdout.write(data); - } else { - stdout.push(data); - } - if (outputStream) { - outputStream.write(data); - } - }); - - child.stderr.on('data', (data) => { - if (verbose) { - process.stderr.write(data); - } else { - stderr.push(data); - } - if (outputStream) { - outputStream.write(data); - } - }); - - const exitCode = await new Promise((resolve) => { - child.on('close', (code) => { - if (outputStream) { - outputStream.end(() => { - resolve(code); - }); - } else { - resolve(code); - } - }); - }); - - if (exitCode === 0) { - testFilePassed = true; - } else { - lastStdout = stdout; - lastStderr = stderr; - } - } - - if (!testFilePassed) { - console.error( - `Test file failed after ${MAX_RETRIES} attempts: ${testFileName}`, - ); - if (!verbose) { - process.stdout.write(Buffer.concat(lastStdout).toString('utf8')); - process.stderr.write(Buffer.concat(lastStderr).toString('utf8')); - } - allTestsPassed = false; - } - } - - if (!keepOutput) { - rmSync(runDir, { recursive: true, force: true }); - } - - if (!allTestsPassed) { - console.error('One or more test files failed.'); - process.exit(1); - } -} - -main(); |
