forked from solutions-plug/predictIQ
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-e2e-tests.js
More file actions
executable file
·73 lines (59 loc) · 2.01 KB
/
Copy pathrun-e2e-tests.js
File metadata and controls
executable file
·73 lines (59 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env node
/**
* CI/CD Test Runner for E2E Tests
* Runs Playwright tests with proper configuration for CI environments
*/
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
const CI = process.env.CI === 'true';
const REPORT_DIR = path.join(__dirname, '..', 'playwright-report');
console.log('🚀 Starting E2E Test Suite...\n');
// Ensure report directory exists
if (!fs.existsSync(REPORT_DIR)) {
fs.mkdirSync(REPORT_DIR, { recursive: true });
}
// Configuration
const config = {
workers: CI ? 1 : undefined,
retries: CI ? 2 : 0,
reporter: CI ? 'github' : 'list',
};
console.log('Configuration:', config);
console.log('CI Mode:', CI ? 'Yes' : 'No');
console.log('');
try {
// Run Playwright tests. Built from `config` above so the printed
// "Configuration" actually reflects what gets invoked — it previously
// hardcoded `--reporter=github,html,json,junit` in CI and computed the
// rest for display only, with no effect on the command.
const flags = [
`--reporter=${CI ? 'github,html,json,junit' : config.reporter}`,
`--retries=${config.retries}`,
config.workers ? `--workers=${config.workers}` : '',
].filter(Boolean);
const command = `npx playwright test ${flags.join(' ')}`;
console.log(`Running: ${command}\n`);
execSync(command, {
stdio: 'inherit',
env: {
...process.env,
CI: CI ? 'true' : 'false',
},
});
console.log('\n✅ All E2E tests passed!');
// Generate summary
if (fs.existsSync(path.join(REPORT_DIR, 'results.json'))) {
const results = JSON.parse(
fs.readFileSync(path.join(REPORT_DIR, 'results.json'), 'utf-8')
);
console.log('\n📊 Test Summary:');
console.log(` Total Suites: ${results.suites?.length || 0}`);
console.log(` Report: ${REPORT_DIR}/index.html`);
}
process.exit(0);
} catch (error) {
console.error('\n❌ E2E tests failed!');
console.error('Check the report at:', path.join(REPORT_DIR, 'index.html'));
process.exit(1);
}