-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathjest.config.js
More file actions
94 lines (79 loc) · 2.14 KB
/
jest.config.js
File metadata and controls
94 lines (79 loc) · 2.14 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/**
* Jest configuration for OneSearch.
*
* Extends @wordpress/scripts default configuration with:
* - Custom test setup for WordPress mocks
* - Module path aliases for cleaner imports
* - Coverage thresholds to maintain code quality
*
* @see https://jestjs.io/docs/configuration
*/
/**
* WordPress dependencies
*/
const defaultConfig = require( '@wordpress/scripts/config/jest-unit.config' );
module.exports = {
...defaultConfig,
// Display name for clarity in multi-project setups
displayName: 'onesearch',
// Root directory for tests
rootDir: '.',
roots: [ '<rootDir>', '<rootDir>/tests/js' ],
// Test setup files run after Jest environment is set up
setupFilesAfterEnv: [
...( defaultConfig.setupFilesAfterEnv || [] ),
'<rootDir>/tests/js/setup.ts',
],
// Module resolution aliases
moduleNameMapper: {
...defaultConfig.moduleNameMapper,
// Path alias for assets/src directory
'^@/(.*)$': '<rootDir>/assets/src/$1',
},
// Directories to ignore when searching for tests
testPathIgnorePatterns: [
'/node_modules/',
'/build/',
'/inc',
'/vendor/',
'/tests/e2e/',
'/tests/php/',
],
// Test match patterns
testMatch: [
'**/__tests__/**/*.{js,jsx,ts,tsx}',
'**/*.{test,spec}.{js,jsx,ts,tsx}',
],
// Files to include in coverage reports
collectCoverageFrom: [
'assets/src/**/*.{js,jsx,ts,tsx}',
// Exclude type definition files
'!assets/src/**/*.d.ts',
// Exclude barrel exports
'!assets/src/**/index.{js,tsx,jsx}',
// Exclude style files
'!assets/src/**/*.{css,scss}',
],
// Coverage output directory
coverageDirectory: 'tests/_output/js-coverage',
// Coverage thresholds - start at 0% to allow gradual adoption
coverageThreshold: {
global: {
branches: 0,
functions: 0,
lines: 0,
statements: 0,
},
},
// Coverage reporters for different outputs
coverageReporters: [ 'text', 'text-summary', 'lcov', 'html' ],
// Verbose output for CI environments
verbose: process.env.CI === 'true',
// Timeout for slow tests (useful for integration tests)
testTimeout: 10000,
// Watch plugins for better DX
watchPlugins: [
'jest-watch-typeahead/filename',
'jest-watch-typeahead/testname',
],
};