Skip to content

Commit 9bdf2e5

Browse files
authored
feat(tests): Add comprehensive unit tests for background and popup sc… (#5)
* feat(tests): Add comprehensive unit tests for background and popup scripts - Implemented Chrome API mocks for testing purposes. - Created a mock for the popup script to simulate DOM interactions. - Developed unit tests for the background script, covering constants, error handling, and display bounds. - Added unit tests for the popup script, including DOM initialization, language selection, and button functionality. - Enhanced test utilities for better setup and teardown of test environments. - Configured TypeScript for testing with specific compiler options. * refactor(ci): Update CI configuration to focus on unit tests only * refactor(ci): Remove caching configuration for npm dependencies * fix(ci): Change npm ci to npm install for dependency installation * fix(ci): Update dependency installation method and cache configuration * refactor(tests): Optimize test environment behavior for popup and background scripts
1 parent fb83818 commit 9bdf2e5

File tree

17 files changed

+6890
-4
lines changed

17 files changed

+6890
-4
lines changed

.github/dependabot.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "npm"
4+
directory: "/"
5+
schedule:
6+
interval: "daily"
7+
labels:
8+
- "dependencies"
9+
- "automated"
10+
# Group minor and patch updates
11+
groups:
12+
development-dependencies:
13+
dependency-type: "development"
14+
patterns:
15+
- "@types/*"
16+
- "jest*"
17+
- "typescript"
18+
- "ts-jest"
19+
production-dependencies:
20+
dependency-type: "production"
21+
exclude-patterns:
22+
- "@types/*"
23+
24+
# GitHub Actions
25+
- package-ecosystem: "github-actions"
26+
directory: "/"
27+
schedule:
28+
interval: "daily"
29+
labels:
30+
- "github-actions"
31+
- "automated"

.github/workflows/ci.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: CI/CD Pipeline
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
workflow_dispatch:
9+
10+
env:
11+
NODE_VERSION: '22'
12+
CACHE_DEPENDENCY_PATH: 'package-lock.json'
13+
14+
jobs:
15+
test:
16+
name: 🧪 Unit Tests
17+
runs-on: ubuntu-latest
18+
timeout-minutes: 15
19+
20+
strategy:
21+
matrix:
22+
test-type: [unit]
23+
24+
steps:
25+
- name: 📥 Checkout code
26+
uses: actions/checkout@v4
27+
28+
- name: 🟢 Setup Node.js
29+
uses: actions/setup-node@v4
30+
with:
31+
node-version: ${{ env.NODE_VERSION }}
32+
cache: 'npm'
33+
cache-dependency-path: ${{ env.CACHE_DEPENDENCY_PATH }}
34+
35+
- name: 📦 Install dependencies
36+
run: npm ci --prefer-offline --no-audit
37+
38+
- name: 🏗️ Build project
39+
run: npm run build
40+
41+
- name: 🧪 Run ${{ matrix.test-type }} tests
42+
run: npm run test:${{ matrix.test-type }}
43+
44+
- name: 📊 PR Test Summary
45+
run: |
46+
echo "## 🧪 Test Results" >> $GITHUB_STEP_SUMMARY
47+
echo "✅ Build: Successful" >> $GITHUB_STEP_SUMMARY
48+
echo "✅ Unit Tests: Passed" >> $GITHUB_STEP_SUMMARY

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ node_modules/
33
npm-debug.log*
44
yarn-debug.log*
55
yarn-error.log*
6-
package-lock.json
76

87
# Environment files
98
.env
@@ -65,6 +64,10 @@ pids/
6564
coverage/
6665
*.lcov
6766

67+
# Test results
68+
test-results/
69+
junit.xml
70+
6871
# Dev Container
6972
.devcontainer/.env
7073

.npmrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ audit-level=moderate
1111

1212
# Performance settings
1313
prefer-offline=false
14-
cache-max=86400000
1514

1615
# Registry settings
1716
registry=https://registry.npmjs.org/

jest.config.js

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/** @type {import('jest').Config} */
2+
module.exports = {
3+
preset: 'ts-jest',
4+
testEnvironment: 'jsdom',
5+
6+
// Enhanced performance optimizations
7+
maxWorkers: process.env.CI ? 2 : '75%', // More workers locally, fewer in CI
8+
cache: true,
9+
cacheDirectory: '<rootDir>/node_modules/.cache/jest',
10+
11+
// Faster test discovery
12+
haste: {
13+
computeSha1: false,
14+
throwOnModuleCollision: false,
15+
},
16+
17+
// Test file patterns
18+
testMatch: [
19+
'<rootDir>/tests/**/*.test.ts',
20+
'<rootDir>/tests/**/*.spec.ts'
21+
],
22+
23+
// Module path mapping
24+
moduleNameMapper: {
25+
'^@/(.*)$': '<rootDir>/src/$1'
26+
},
27+
28+
// Setup files
29+
setupFilesAfterEnv: [
30+
'<rootDir>/tests/setup/jest.setup.ts'
31+
],
32+
33+
// Coverage configuration (disable during development)
34+
collectCoverageFrom: [
35+
'src/**/*.ts',
36+
'!src/**/*.d.ts',
37+
'!src/**/index.ts'
38+
],
39+
40+
coverageReporters: [
41+
'text-summary', // Faster than full text
42+
'lcov'
43+
],
44+
45+
coverageDirectory: 'coverage',
46+
47+
// Enhanced transform configuration with performance optimizations
48+
transform: {
49+
'^.+\\.ts$': ['ts-jest', {
50+
tsconfig: 'tsconfig.test.json',
51+
isolatedModules: true,
52+
useESM: false,
53+
// Skip type checking for faster compilation
54+
diagnostics: false, // Completely disable diagnostics for speed
55+
// Disable source maps for faster execution
56+
sourcemap: false,
57+
// Use faster compiler options
58+
compilerOptions: {
59+
skipLibCheck: true,
60+
skipDefaultLibCheck: true,
61+
}
62+
}]
63+
},
64+
65+
// Transform ignore patterns
66+
transformIgnorePatterns: [
67+
'node_modules/(?!(some-es6-module)/)'
68+
],
69+
70+
// Module file extensions
71+
moduleFileExtensions: [
72+
'ts',
73+
'js',
74+
'json'
75+
],
76+
77+
// Clear mocks between tests
78+
clearMocks: true,
79+
80+
// Reduce verbosity for faster execution
81+
verbose: false,
82+
silent: false,
83+
84+
// Optimized timeout settings
85+
testTimeout: 5000, // Reduced from 10 seconds to 5 seconds
86+
87+
// Performance settings
88+
detectOpenHandles: false,
89+
forceExit: true, // Enable for faster exit
90+
91+
// Bail early on failures (for faster feedback during development)
92+
bail: false,
93+
94+
// Faster test running options
95+
passWithNoTests: true,
96+
errorOnDeprecated: false,
97+
98+
// Optimize watch mode
99+
watchPathIgnorePatterns: [
100+
'/node_modules/',
101+
'/dist/',
102+
'/coverage/',
103+
'/.git/'
104+
]
105+
};

0 commit comments

Comments
 (0)