Skip to content

Commit c7dc78e

Browse files
committed
Fix CI container testing by detecting CI environment in container-test.js
- Add CI environment detection (GitHub Actions, GitLab CI, etc.) - Run tests directly with vitest when in CI instead of managing containers - Preserve existing containerized behavior for local development - Fixes 'Required file not found: Dockerfile.optimized' error in CI
1 parent fd61742 commit c7dc78e

1 file changed

Lines changed: 52 additions & 1 deletion

File tree

scripts/container-test.js

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,62 @@ class ContainerTestRunner {
195195
});
196196
}
197197

198+
/**
199+
* Run tests directly in CI environment
200+
*/
201+
async runTestsDirectly(testCommand = 'test') {
202+
console.log(`🧪 Running tests directly in CI environment: ${testCommand}`);
203+
204+
// Map test commands to actual npm scripts
205+
const scriptMap = {
206+
'test': 'vitest',
207+
'test:coverage': 'vitest --coverage',
208+
'test:watch': 'vitest --watch'
209+
};
210+
211+
const actualCommand = scriptMap[testCommand] || testCommand;
212+
213+
return new Promise((resolve, reject) => {
214+
const child = spawn('pnpm', actualCommand.split(' '), {
215+
stdio: 'inherit',
216+
cwd: this.projectRoot,
217+
env: {
218+
...process.env,
219+
FORCE_COLOR: '1'
220+
}
221+
});
222+
223+
child.on('close', (code) => {
224+
if (code === 0) {
225+
console.log('✓ Tests completed successfully');
226+
resolve(code);
227+
} else {
228+
console.log(`✗ Tests failed with code ${code}`);
229+
reject(new Error(`Tests failed with code ${code}`));
230+
}
231+
});
232+
233+
child.on('error', reject);
234+
});
235+
}
236+
198237
/**
199238
* Main execution method
200239
*/
201240
async run(testCommand = 'test') {
202241
try {
242+
// Check if we're in CI environment (GitHub Actions, GitLab CI, etc.)
243+
const isCI = process.env.GITHUB_ACTIONS === 'true' ||
244+
process.env.GITLAB_CI === 'true' ||
245+
process.env.CI === 'true';
246+
247+
if (isCI) {
248+
console.log('🤖 CI environment detected, running tests directly...');
249+
await this.runTestsDirectly(testCommand);
250+
console.log('🎉 CI testing completed successfully!');
251+
return;
252+
}
253+
203254
console.log('🚀 Starting containerized test runner...');
204255

205256
// Validate environment
@@ -220,7 +271,7 @@ class ContainerTestRunner {
220271
console.log('🎉 Containerized testing completed successfully!');
221272

222273
} catch (error) {
223-
console.error('❌ Containerized testing failed:', error.message);
274+
console.error('❌ Testing failed:', error.message);
224275
process.exit(1);
225276
}
226277
}

0 commit comments

Comments
 (0)