-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathjest.config.ts
105 lines (94 loc) · 3.22 KB
/
jest.config.ts
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
95
96
97
98
99
100
101
102
103
104
105
import type { Config } from "jest";
/**
* Jest configuration for Expo projects with environment
* variable preservation and additional setup.
*
* This config extends the default Expo preset and adds
* custom transformers and settings from package.json.
*/
const config: Config = {
/**
* Extends the Expo preset for Jest configuration.
* This includes default settings for React Native and Expo projects.
*/
preset: "jest-expo",
/**
* Specifies the root directory for Jest to use when running tests.
* All paths in the config are relative to this directory.
* Example: If rootDir is ".", tests in "./src/components" will be found.
*/
rootDir: ".",
/**
* Specifies the test environment that will be used for testing.
* 'node' environment simulates Node.js environment.
*/
testEnvironment: "node",
/**
* Specifies glob patterns for locating test files.
* @example
* Matches:
* - "__tests__/MyComponent.test.js"
* - "src/utils/helper.spec.ts"
* Does not match:
* - "src/components/Button.js"
* - "tests/setup.js"
*/
testMatch: ["**/__tests__/**/*.[jt]s?(x)", "**/?(*.)+(spec|test).[jt]s?(x)"],
/**
* Specifies how files should be transformed before running tests.
* Uses babel-jest for JS/TS files, preserving environment variables.
*/
transform: {
"^.+\\.(js|jsx|ts|tsx)$": [
"babel-jest",
/**
* Preserves environment variables in the test environment.
* This is required because without it, we could not access
* the environment variables (for example, in utils/api.ts).
*
* Without this, environment variables accessed via normal syntax,
* (for example, `process.env.EXPO_PUBLIC_DEV_API_URI`) would be
* undefined in the test environment.
*
* @see https://github.com/expo/expo/issues/26513#issuecomment-1989035903
*/
{
caller: { preserveEnvVars: true },
},
],
},
/**
* Specifies file extensions Jest will look for when running tests.
* @example
* Will resolve: "MyComponent.tsx", "utils.js", "constants.json"
* Won't resolve: "styles.css", "image.png"
*/
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
/**
* Specifies setup files to run before each test.
* These files can set up the testing environment.
*/
setupFiles: ["<rootDir>/jest.setup.ts"],
/**
* Specifies patterns for modules that should not be transformed.
* Typically used for node_modules, but allows exceptions for
* specific packages.
*
* @example
* Will transform: "@react-native-community/async-storage"
* Won't transform: "lodash", "moment"
*/
transformIgnorePatterns: [
"node_modules/(?!((jest-)?react-native|@react-native(-community)?|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@unimodules/.*|unimodules|sentry-expo|native-base|react-native-svg|rn-fetch-blob|@xmtp|uuid|wagmi))",
],
/**
* Enables verbose output, providing detailed information about each test.
*/
verbose: true,
/**
* Specifies setup files to run after the test environment is set up
* but before tests are run.
*/
setupFilesAfterEnv: ["<rootDir>/jest.setup.ts"],
};
export default config;