jest-expo 52.0.0 → 52.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/jest-preset.js +9 -4
- package/package.json +3 -3
- package/src/resolveBabelConfig.js +30 -0
package/jest-preset.js
CHANGED
|
@@ -6,6 +6,7 @@ const isEqual = require('lodash/isEqual');
|
|
|
6
6
|
const jestPreset = cloneDeep(require('react-native/jest-preset'));
|
|
7
7
|
|
|
8
8
|
const { withTypescriptMapping } = require('./src/preset/withTypescriptMapping');
|
|
9
|
+
const { resolveBabelConfig } = require('./src/resolveBabelConfig');
|
|
9
10
|
|
|
10
11
|
// Emulate the alias behavior of Expo's Metro resolver.
|
|
11
12
|
jestPreset.moduleNameMapper = {
|
|
@@ -22,10 +23,14 @@ if (upstreamBabelJest) {
|
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
// transform
|
|
25
|
-
|
|
26
|
-
'
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
const babelOpts = {
|
|
27
|
+
caller: { name: 'metro', bundler: 'metro', platform: 'ios' },
|
|
28
|
+
};
|
|
29
|
+
const babelConfigFile = resolveBabelConfig(process.cwd());
|
|
30
|
+
if (babelConfigFile) {
|
|
31
|
+
babelOpts.configFile = babelConfigFile;
|
|
32
|
+
}
|
|
33
|
+
jestPreset.transform['\\.[jt]sx?$'] = ['babel-jest', babelOpts];
|
|
29
34
|
|
|
30
35
|
/* Update this when metro changes their default extensions */
|
|
31
36
|
const defaultMetroAssetExts = [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jest-expo",
|
|
3
|
-
"version": "52.0.
|
|
3
|
+
"version": "52.0.2",
|
|
4
4
|
"description": "A Jest preset to painlessly test your Expo / React Native apps.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"preset": "jest-expo/universal"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@expo/config": "~10.0.
|
|
40
|
+
"@expo/config": "~10.0.4",
|
|
41
41
|
"@expo/json-file": "^9.0.0",
|
|
42
42
|
"@jest/create-cache-key-function": "^29.2.1",
|
|
43
43
|
"@jest/globals": "^29.2.1",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"expo": "*",
|
|
60
60
|
"react-native": "*"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "dc2f6d254174599c74ebc2a20523d09b57a628fc"
|
|
63
63
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const fs = require('node:fs');
|
|
2
|
+
const path = require('node:path');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Resolve the babel `configFile` option.
|
|
6
|
+
*/
|
|
7
|
+
function resolveBabelConfig(projectRoot) {
|
|
8
|
+
// TODO(EvanBacon): We might want to disable babelrc lookup when the user specifies `enableBabelRCLookup: false`.
|
|
9
|
+
const possibleBabelRCPaths = ['.babelrc', '.babelrc.js', 'babel.config.js'];
|
|
10
|
+
const foundBabelRCPath = possibleBabelRCPaths.find((configFileName) =>
|
|
11
|
+
fs.existsSync(path.resolve(process.cwd(), configFileName))
|
|
12
|
+
);
|
|
13
|
+
if (foundBabelRCPath) {
|
|
14
|
+
// If the user has a babel config file, we should return null and use the default configFile resolution from babel.
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
return require.resolve('babel-preset-expo');
|
|
20
|
+
} catch (error) {
|
|
21
|
+
if (error.code === 'MODULE_NOT_FOUND') {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
throw error;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
module.exports = {
|
|
29
|
+
resolveBabelConfig,
|
|
30
|
+
};
|