Skip to content

Commit 9963b33

Browse files
author
martin
committed
Fix E2E tests: use static build server instead of dev server
- Use 'serve -s build' instead of 'npm start' for E2E tests - This avoids webpack dev server compiling test files - Update Playwright config to match CI setup - Remove webServer config in CI (server started externally)
1 parent d65d029 commit 9963b33

3 files changed

Lines changed: 46 additions & 20 deletions

File tree

.github/workflows/tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,16 +203,16 @@ jobs:
203203
cd frontend
204204
npm run build
205205
206-
- name: Start frontend
206+
- name: Start frontend (serve static build)
207207
run: |
208208
cd frontend
209-
npm start &
209+
npx serve -s build -l 3000 &
210210
211211
- name: Wait for services
212212
run: |
213213
# Wait for backend - use health endpoint (no auth required)
214214
timeout 120 bash -c 'until curl -sf http://localhost:8080/api/v1/health 2>/dev/null || curl -sf http://localhost:8080/actuator/health 2>/dev/null; do sleep 2; done'
215-
# Wait for frontend on port 3000 (npm start default)
215+
# Wait for frontend on port 3000
216216
timeout 120 bash -c 'until curl -sf http://localhost:3000 2>/dev/null; do sleep 2; done'
217217
218218
- name: Run E2E tests

frontend/craco.config.js

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,37 @@
11
const { VueLoaderPlugin } = require('vue-loader');
22
const webpack = require('webpack');
3+
const path = require('path');
34

45
module.exports = {
56
webpack: {
67
configure: (webpackConfig) => {
78
// Add .vue extension to resolve
89
webpackConfig.resolve.extensions.push('.vue');
910

10-
// Exclude test files from webpack compilation - use null-loader pattern
11-
// This replaces test files with empty modules
12-
webpackConfig.module.rules.unshift({
13-
test: /\.(test|spec)\.(ts|tsx|js|jsx)$/,
14-
use: 'null-loader',
15-
});
16-
17-
// Exclude __tests__ directories
18-
webpackConfig.module.rules.unshift({
19-
test: /[\\/]__tests__[\\/].*\.(ts|tsx|js|jsx)$/,
20-
use: 'null-loader',
21-
});
11+
// Completely exclude test files from webpack compilation
12+
// by modifying the oneOf rules to exclude test patterns
13+
if (webpackConfig.module.rules) {
14+
webpackConfig.module.rules.forEach((rule) => {
15+
if (rule.oneOf) {
16+
// Add exclusion pattern to all oneOf rules
17+
rule.oneOf.forEach((oneOfRule) => {
18+
if (oneOfRule.test && !oneOfRule.exclude) {
19+
oneOfRule.exclude = [];
20+
}
21+
if (oneOfRule.exclude && Array.isArray(oneOfRule.exclude)) {
22+
oneOfRule.exclude.push(/__tests__/);
23+
oneOfRule.exclude.push(/\.(test|spec)\.(ts|tsx|js|jsx)$/);
24+
} else if (oneOfRule.exclude) {
25+
oneOfRule.exclude = [
26+
oneOfRule.exclude,
27+
/__tests__/,
28+
/\.(test|spec)\.(ts|tsx|js|jsx)$/,
29+
];
30+
}
31+
});
32+
}
33+
});
34+
}
2235

2336
// Add vue-loader rule BEFORE the oneOf rule
2437
webpackConfig.module.rules.unshift({
@@ -44,6 +57,17 @@ module.exports = {
4457
vue: 'vue/dist/vue.esm-bundler.js',
4558
};
4659

60+
// Ignore test files in watch mode
61+
webpackConfig.watchOptions = {
62+
...webpackConfig.watchOptions,
63+
ignored: [
64+
'**/node_modules/**',
65+
'**/__tests__/**',
66+
'**/*.test.*',
67+
'**/*.spec.*',
68+
],
69+
};
70+
4771
return webpackConfig;
4872
},
4973
},

frontend/e2e/playwright.config.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default defineConfig({
88
workers: process.env.CI ? 1 : undefined,
99
reporter: 'html',
1010
use: {
11-
baseURL: process.env.PLAYWRIGHT_TEST_BASE_URL || 'http://localhost:8090',
11+
baseURL: process.env.PLAYWRIGHT_TEST_BASE_URL || 'http://localhost:3000',
1212
trace: 'on-first-retry',
1313
screenshot: 'only-on-failure',
1414
},
@@ -28,10 +28,12 @@ export default defineConfig({
2828
},
2929
],
3030

31-
webServer: {
32-
command: 'npm start',
33-
url: 'http://localhost:8090',
34-
reuseExistingServer: !process.env.CI,
31+
// In CI, the server is started externally via 'serve -s build'
32+
// Locally, use 'npx serve -s build -l 3000' to serve the built app
33+
webServer: process.env.CI ? undefined : {
34+
command: 'npx serve -s build -l 3000',
35+
url: 'http://localhost:3000',
36+
reuseExistingServer: true,
3537
timeout: 120 * 1000,
3638
},
3739
});

0 commit comments

Comments
 (0)