Skip to content

Commit 4b1c413

Browse files
authored
Merge pull request #332 from arii/feat/test-performance-optimization-phase1
feat: Phase 1 Test Performance Optimizations
2 parents cbcf9a1 + 43506f7 commit 4b1c413

11 files changed

Lines changed: 275 additions & 47 deletions

jest.config.cjs.backup

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/** @type {import('jest').Config} */
2+
const config = {
3+
preset: 'ts-jest',
4+
testEnvironment: 'node',
5+
roots: ['<rootDir>/tests/unit'],
6+
testMatch: ['**/*.test.ts', '**/*.test.tsx'],
7+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'],
8+
collectCoverageFrom: [
9+
'services/**/*.ts',
10+
'utils/socketManager.ts',
11+
'!**/*.d.ts',
12+
'!**/node_modules/**',
13+
],
14+
transform: {
15+
'^.+\\.(ts|tsx)$': [
16+
'ts-jest',
17+
{
18+
useESM: true,
19+
tsconfig: {
20+
module: 'ES2022',
21+
moduleResolution: 'node',
22+
esModuleInterop: true,
23+
allowSyntheticDefaultImports: true,
24+
},
25+
},
26+
],
27+
},
28+
extensionsToTreatAsEsm: ['.ts', '.tsx'],
29+
moduleNameMapper: {
30+
'^(\\.{1,2}/.*)\\.js$': '$1',
31+
'^@/(.*)$': '<rootDir>/$1',
32+
},
33+
testTimeout: 10000,
34+
}
35+
36+
module.exports = config

jest.config.cjs.old

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/** @type {import('jest').Config} */
2+
const config = {
3+
preset: 'ts-jest',
4+
testEnvironment: 'node',
5+
roots: ['<rootDir>/tests/unit'],
6+
testMatch: ['**/*.test.ts', '**/*.test.tsx'],
7+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'],
8+
collectCoverageFrom: [
9+
'services/**/*.ts',
10+
'utils/socketManager.ts',
11+
'!**/*.d.ts',
12+
'!**/node_modules/**',
13+
],
14+
transform: {
15+
'^.+\\.(ts|tsx)$': [
16+
'ts-jest',
17+
{
18+
useESM: true,
19+
tsconfig: {
20+
module: 'ES2022',
21+
moduleResolution: 'node',
22+
esModuleInterop: true,
23+
allowSyntheticDefaultImports: true,
24+
},
25+
},
26+
],
27+
},
28+
extensionsToTreatAsEsm: ['.ts', '.tsx'],
29+
moduleNameMapper: {
30+
'^(\\.{1,2}/.*)\\.js$': '$1',
31+
'^@/(.*)$': '<rootDir>/$1',
32+
},
33+
testTimeout: 10000,
34+
}
35+
36+
module.exports = config

jest.config.cjs.optimized

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/** @type {import('jest').Config} */
2+
const config = {
3+
preset: 'ts-jest',
4+
testEnvironment: 'node',
5+
roots: ['<rootDir>/tests/unit'],
6+
testMatch: ['**/*.test.ts', '**/*.test.tsx'],
7+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'],
8+
collectCoverageFrom: [
9+
'services/**/*.ts',
10+
'utils/socketManager.ts',
11+
'!**/*.d.ts',
12+
'!**/node_modules/**',
13+
],
14+
transform: {
15+
'^.+\\.(ts|tsx)$': [
16+
'ts-jest',
17+
{
18+
useESM: true,
19+
tsconfig: {
20+
module: 'ES2022',
21+
moduleResolution: 'node',
22+
esModuleInterop: true,
23+
allowSyntheticDefaultImports: true,
24+
},
25+
},
26+
],
27+
},
28+
extensionsToTreatAsEsm: ['.ts', '.tsx'],
29+
moduleNameMapper: {
30+
'^(\\.{1,2}/.*)\\.js$': '$1',
31+
'^@/(.*)$': '<rootDir>/$1',
32+
},
33+
testTimeout: 10000,
34+
}
35+
36+
module.exports = config

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
"test:unit": "jest",
2323
"test:unit:watch": "jest --watch",
2424
"test:unit:coverage": "jest --coverage",
25-
"test:visual": "pnpm run build:server && bash start-production.sh > /tmp/hrm-server.log 2>&1 & echo $! > /tmp/hrm-server.pid && sleep 5 && playwright test; kill $(cat /tmp/hrm-server.pid) 2>/dev/null || true",
25+
"test:visual": "pnpm run build && bash start-production.sh > /tmp/hrm-server.log 2>&1 & echo $! > /tmp/hrm-server.pid && sleep 10 && playwright test; kill $(cat /tmp/hrm-server.pid) 2>/dev/null || true",
2626
"test:all": "pnpm run test:visual && pnpm run test:unit",
27-
"test:quick": "pnpm run build:server && bash start-production.sh > /tmp/hrm-server.log 2>&1 & echo $! > /tmp/hrm-server.pid && sleep 5 && playwright test --reporter=dot; kill $(cat /tmp/hrm-server.pid) 2>/dev/null || true",
27+
"test:quick": "pnpm run build && bash start-production.sh > /tmp/hrm-server.log 2>&1 & echo $! > /tmp/hrm-server.pid && sleep 10 && playwright test --reporter=dot; kill $(cat /tmp/hrm-server.pid) 2>/dev/null || true",
2828
"test:visual:ui": "playwright test --ui",
29-
"test:visual:update": "pnpm run build:server && bash start-production.sh > /tmp/hrm-server.log 2>&1 & echo $! > /tmp/hrm-server.pid && sleep 5 && playwright test --update-snapshots --reporter=dot; kill $(cat /tmp/hrm-server.pid) 2>/dev/null || true",
29+
"test:visual:update": "pnpm run build && bash start-production.sh > /tmp/hrm-server.log 2>&1 & echo $! > /tmp/hrm-server.pid && sleep 10 && playwright test --update-snapshots --reporter=dot; kill $(cat /tmp/hrm-server.pid) 2>/dev/null || true",
3030
"test:visual:headed": "playwright test --project=chromium --headed",
3131
"test:visual:report": "playwright show-report",
3232
"test:oauth:local": "python3 scripts/verify_oauth_local.py",
@@ -95,4 +95,4 @@
9595
"pnpm": ">=8.0.0"
9696
},
9797
"packageManager": "pnpm@9.0.0"
98-
}
98+
}

playwright.config.ts

Lines changed: 50 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,61 @@
1-
// File: playwright.config.ts
21
/**
32
* Playwright Test Configuration for HRM Comprehensive Assessment
4-
* Supports visual regression, mobile testing, and video recording
3+
* Optimized for performance and parallel execution
54
*/
6-
import { defineConfig, devices } from '@playwright/test'
7-
import { getBaseURL } from './utils/urls'
5+
import { defineConfig, devices } from '@playwright/test';
6+
import { getBaseURL } from './utils/urls';
87

98
// Check if Spotify/NextAuth credentials are available
109
const hasSpotifyCredentials = !!(
1110
process.env.SPOTIFY_CLIENT_ID && process.env.SPOTIFY_CLIENT_SECRET
12-
)
13-
const hasNextAuthSecret = !!process.env.NEXTAUTH_SECRET
11+
);
12+
const hasNextAuthSecret = !!process.env.NEXTAUTH_SECRET;
1413

15-
// Build ignore list based on available credentials
14+
// Optimized ignore list - run more tests by default
1615
const testIgnoreList = [
17-
'integration-tests.spec.ts',
16+
// Only ignore truly integration-heavy tests for speed
1817
'comprehensive-assessment.spec.ts',
19-
'core-functionality.spec.ts',
20-
'mobile-essential.spec.ts',
2118
'mobile-assessment.spec.ts',
2219
'workflow-assessment.spec.ts',
2320
// OAuth tests are excluded from regular test runs (use separate npm script)
2421
'oauth/**/*.spec.ts',
25-
]
22+
];
2623

2724
// Only ignore auth-dependent tests if credentials are missing
2825
if (!hasSpotifyCredentials) {
29-
testIgnoreList.push('auth-flow.spec.ts')
26+
testIgnoreList.push('auth-flow.spec.ts');
3027
}
3128
if (!hasNextAuthSecret) {
32-
testIgnoreList.push('debug.spec.ts')
29+
testIgnoreList.push('debug.spec.ts');
3330
}
3431

3532
export default defineConfig({
3633
testDir: './tests/playwright',
3734
testMatch: ['**/*.spec.ts'],
3835
testIgnore: testIgnoreList,
3936

40-
// Run tests in parallel
41-
fullyParallel: false,
37+
// Performance Optimizations
38+
fullyParallel: true,
39+
workers: process.env.CI ? 2 : 1, // Use 1 worker for visual tests to avoid race conditions
40+
timeout: 30000, // Adjusted for potentially longer server startups
4241

4342
// Fail build on CI if you accidentally left test.only
4443
forbidOnly: !!process.env.CI,
4544

4645
// Retry failed tests on CI
4746
retries: process.env.CI ? 2 : 0,
4847

49-
// Use 1 worker for visual tests to avoid server race conditions
50-
workers: 1,
51-
52-
// Reporter configuration
53-
reporter: [
54-
['html', { outputFolder: 'playwright-report' }],
55-
['json', { outputFile: 'test-results/results.json' }],
56-
['list'],
57-
],
48+
// Test execution optimizations
49+
expect: {
50+
timeout: 5000, // Faster assertion timeouts
51+
},
5852

5953
// Shared settings for all tests
6054
use: {
6155
// Base URL for all tests
6256
baseURL: getBaseURL(),
57+
actionTimeout: 0,
58+
headless: true,
6359

6460
// Screenshot settings
6561
screenshot: {
@@ -80,26 +76,47 @@ export default defineConfig({
8076
viewport: { width: 1920, height: 1080 },
8177
},
8278

83-
// Single chromium project for fast testing
79+
// Browser configurations
8480
projects: [
8581
{
8682
name: 'chromium',
8783
use: {
8884
...devices['Desktop Chrome'],
85+
launchOptions: {
86+
args: [
87+
'--disable-web-security',
88+
'--disable-features=TranslateUI',
89+
'--no-sandbox',
90+
'--disable-setuid-sandbox',
91+
'--disable-dev-shm-usage',
92+
],
93+
},
8994
viewport: { width: 1920, height: 1080 },
9095
video: {
9196
mode: 'retain-on-failure',
9297
size: { width: 1920, height: 1080 },
9398
},
9499
},
95100
},
101+
// Mobile testing (optional, can be enabled via environment variable)
102+
...(process.env.INCLUDE_MOBILE
103+
? [
104+
{
105+
name: 'Mobile Chrome',
106+
use: { ...devices['Pixel 5'] },
107+
},
108+
]
109+
: []),
96110
],
97111

98-
// Web server configuration disabled - start server manually
99-
// webServer: {
100-
// command: 'npm run dev',
101-
// url: 'http://127.0.0.1:3000',
102-
// reuseExistingServer: !process.env.CI,
103-
// timeout: 120 * 1000,
104-
// },
105-
})
112+
113+
114+
// Output configuration
115+
outputDir: 'test-results/',
116+
reporter: [
117+
['list'],
118+
['html', { outputFolder: 'playwright-report', open: 'never' }],
119+
['json', { outputFile: 'test-results/results.json' }],
120+
...(process.env.CI ? [['github']] : []),
121+
],
122+
});

playwright.config.ts.backup

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// File: playwright.config.ts
2+
/**
3+
* Playwright Test Configuration for HRM Comprehensive Assessment
4+
* Supports visual regression, mobile testing, and video recording
5+
*/
6+
import { defineConfig, devices } from '@playwright/test'
7+
import { getBaseURL } from './utils/urls'
8+
9+
// Check if Spotify/NextAuth credentials are available
10+
const hasSpotifyCredentials = !!(
11+
process.env.SPOTIFY_CLIENT_ID && process.env.SPOTIFY_CLIENT_SECRET
12+
)
13+
const hasNextAuthSecret = !!process.env.NEXTAUTH_SECRET
14+
15+
// Build ignore list based on available credentials
16+
const testIgnoreList = [
17+
'integration-tests.spec.ts',
18+
'comprehensive-assessment.spec.ts',
19+
'core-functionality.spec.ts',
20+
'mobile-essential.spec.ts',
21+
'mobile-assessment.spec.ts',
22+
'workflow-assessment.spec.ts',
23+
]
24+
25+
// Only ignore auth-dependent tests if credentials are missing
26+
if (!hasSpotifyCredentials) {
27+
testIgnoreList.push('auth-flow.spec.ts')
28+
}
29+
if (!hasNextAuthSecret) {
30+
testIgnoreList.push('debug.spec.ts')
31+
}
32+
33+
export default defineConfig({
34+
testDir: './tests/playwright',
35+
testMatch: ['**/*.spec.ts'],
36+
testIgnore: testIgnoreList,
37+
38+
// Run tests in parallel
39+
fullyParallel: false,
40+
41+
// Fail build on CI if you accidentally left test.only
42+
forbidOnly: !!process.env.CI,
43+
44+
// Retry failed tests on CI
45+
retries: process.env.CI ? 2 : 0,
46+
47+
// Use 1 worker for visual tests to avoid server race conditions
48+
workers: 1,
49+
50+
// Reporter configuration
51+
reporter: [
52+
['html', { outputFolder: 'playwright-report' }],
53+
['json', { outputFile: 'test-results/results.json' }],
54+
['list'],
55+
],
56+
57+
// Shared settings for all tests
58+
use: {
59+
// Base URL for all tests
60+
baseURL: getBaseURL(),
61+
62+
// Screenshot settings
63+
screenshot: {
64+
mode: 'only-on-failure',
65+
fullPage: true,
66+
},
67+
68+
// Video settings
69+
video: {
70+
mode: 'retain-on-failure',
71+
size: { width: 1920, height: 1080 },
72+
},
73+
74+
// Trace settings
75+
trace: 'on-first-retry',
76+
77+
// Browser context options
78+
viewport: { width: 1920, height: 1080 },
79+
},
80+
81+
// Single chromium project for fast testing
82+
projects: [
83+
{
84+
name: 'chromium',
85+
use: {
86+
...devices['Desktop Chrome'],
87+
viewport: { width: 1920, height: 1080 },
88+
video: {
89+
mode: 'retain-on-failure',
90+
size: { width: 1920, height: 1080 },
91+
},
92+
},
93+
},
94+
],
95+
96+
// Web server configuration disabled - start server manually
97+
// webServer: {
98+
// command: 'npm run dev',
99+
// url: 'http://127.0.0.1:3000',
100+
// reuseExistingServer: !process.env.CI,
101+
// timeout: 120 * 1000,
102+
// },
103+
})
73.8 KB
Loading

0 commit comments

Comments
 (0)