jest-expo 56.0.2 → 56.0.4
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
CHANGED
|
@@ -24,7 +24,7 @@ try {
|
|
|
24
24
|
jestPreset = cloneDeep(jestPreset);
|
|
25
25
|
|
|
26
26
|
const { withTypescriptMapping } = require('./src/preset/withTypescriptMapping');
|
|
27
|
-
const {
|
|
27
|
+
const { resolveBabelOptions } = require('./src/resolveBabelOptions');
|
|
28
28
|
|
|
29
29
|
// Emulate the alias behavior of Expo's Metro resolver.
|
|
30
30
|
jestPreset.moduleNameMapper = {
|
|
@@ -41,13 +41,7 @@ if (upstreamBabelJest) {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
// transform
|
|
44
|
-
const babelOpts =
|
|
45
|
-
caller: { name: 'metro', bundler: 'metro', platform: 'ios' },
|
|
46
|
-
};
|
|
47
|
-
const babelConfigFile = resolveBabelConfig(process.cwd());
|
|
48
|
-
if (babelConfigFile) {
|
|
49
|
-
babelOpts.configFile = babelConfigFile;
|
|
50
|
-
}
|
|
44
|
+
const babelOpts = resolveBabelOptions(process.cwd());
|
|
51
45
|
jestPreset.transform['\\.[jt]sx?$'] = ['babel-jest', babelOpts];
|
|
52
46
|
|
|
53
47
|
/* Update this when metro changes their default extensions */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jest-expo",
|
|
3
|
-
"version": "56.0.
|
|
3
|
+
"version": "56.0.4",
|
|
4
4
|
"description": "A Jest preset to painlessly test your Expo / React Native apps.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -47,11 +47,15 @@
|
|
|
47
47
|
"stacktrace-js": "^2.0.2"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
+
"expo": "*",
|
|
50
51
|
"react-native": "*",
|
|
51
52
|
"@react-native/jest-preset": "^0.85.0",
|
|
52
53
|
"react-server-dom-webpack": "~19.0.4 || ~19.1.5 || ~19.2.4"
|
|
53
54
|
},
|
|
54
55
|
"peerDependenciesMeta": {
|
|
56
|
+
"expo": {
|
|
57
|
+
"optional": true
|
|
58
|
+
},
|
|
55
59
|
"react-server-dom-webpack": {
|
|
56
60
|
"optional": true
|
|
57
61
|
}
|
|
@@ -61,7 +65,7 @@
|
|
|
61
65
|
"@react-native/jest-preset": "0.85.3",
|
|
62
66
|
"react-server-dom-webpack": "~19.0.6"
|
|
63
67
|
},
|
|
64
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "c4c9867a0bcbb188e55ecaec4998e38d33108a5d",
|
|
65
69
|
"scripts": {
|
|
66
70
|
"lint": "eslint .",
|
|
67
71
|
"test": "jest"
|
|
@@ -61,7 +61,6 @@ module.exports = {
|
|
|
61
61
|
argumentsCount: 0,
|
|
62
62
|
key: 'getMemoryUsageSnapshotAsync',
|
|
63
63
|
},
|
|
64
|
-
{ name: 'getStoredEntries', argumentsCount: 0, key: 'getStoredEntries' },
|
|
65
64
|
{ name: 'logEvent', argumentsCount: 2, key: 'logEvent' },
|
|
66
65
|
{ name: 'markFirstRender', argumentsCount: 0, key: 'markFirstRender' },
|
|
67
66
|
{ name: 'markInteractive', argumentsCount: 1, key: 'markInteractive' },
|
|
@@ -849,7 +848,6 @@ module.exports = {
|
|
|
849
848
|
getAppStartupTimesAsync: { type: 'function' },
|
|
850
849
|
getFrameRateMetricsAsync: { type: 'function' },
|
|
851
850
|
getMemoryUsageSnapshotAsync: { type: 'function' },
|
|
852
|
-
getStoredEntries: { type: 'function' },
|
|
853
851
|
logEvent: { type: 'function' },
|
|
854
852
|
markFirstRender: { type: 'function' },
|
|
855
853
|
markInteractive: { type: 'function' },
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
const fs = require('node:fs');
|
|
2
|
+
const path = require('node:path');
|
|
3
|
+
|
|
4
|
+
const BABEL_CONFIG_NAMES = [
|
|
5
|
+
'.babelrc',
|
|
6
|
+
'.babelrc.js',
|
|
7
|
+
'.babelrc.cjs',
|
|
8
|
+
'.babelrc.mjs',
|
|
9
|
+
'.babelrc.json',
|
|
10
|
+
'.babelrc.cts',
|
|
11
|
+
'babel.config.js',
|
|
12
|
+
'babel.config.cjs',
|
|
13
|
+
'babel.config.mjs',
|
|
14
|
+
'babel.config.json',
|
|
15
|
+
'babel.config.cts',
|
|
16
|
+
'babel.config.ts',
|
|
17
|
+
'babel.config.mts',
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
function resolveBabelrcName(projectRoot) {
|
|
21
|
+
// Check for various babel config files in the project root
|
|
22
|
+
return BABEL_CONFIG_NAMES.find((configFileName) => {
|
|
23
|
+
return fs.existsSync(path.resolve(projectRoot, configFileName));
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// NOTE(@kitten): Keep in sync with `@expo/metro-config/src/loadBabelConfig.ts`
|
|
28
|
+
const loadBabelConfig = (function () {
|
|
29
|
+
let result;
|
|
30
|
+
|
|
31
|
+
return function _getBabelRC({ projectRoot, enableBabelRCLookup = true, extendsBabelConfigPath }) {
|
|
32
|
+
if (result == null) {
|
|
33
|
+
result = {};
|
|
34
|
+
if (enableBabelRCLookup && extendsBabelConfigPath) {
|
|
35
|
+
result.exts = path.resolve(projectRoot, extendsBabelConfigPath);
|
|
36
|
+
} else if (projectRoot && enableBabelRCLookup) {
|
|
37
|
+
// Check for various babel config files in the project root
|
|
38
|
+
const foundBabelRCName = resolveBabelrcName(projectRoot);
|
|
39
|
+
// Extend the config if a babel config file is found
|
|
40
|
+
if (foundBabelRCName) {
|
|
41
|
+
result.exts = path.resolve(projectRoot, foundBabelRCName);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Use the default preset for react-native if no babel config file is found
|
|
46
|
+
if (!result.exts) {
|
|
47
|
+
try {
|
|
48
|
+
// NOTE(@kitten): Will need to prefer `projectRoot` manually
|
|
49
|
+
const babelPresetPath = require.resolve('expo/internal/babel-preset', {
|
|
50
|
+
paths: [projectRoot, __dirname],
|
|
51
|
+
});
|
|
52
|
+
result.presets = [babelPresetPath];
|
|
53
|
+
} catch (error) {
|
|
54
|
+
if (error.code === 'MODULE_NOT_FOUND') {
|
|
55
|
+
result.presets = [require('babel-preset-expo')];
|
|
56
|
+
} else {
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return result;
|
|
63
|
+
};
|
|
64
|
+
})();
|
|
65
|
+
|
|
66
|
+
function resolveBabelOptions(projectRoot = process.cwd()) {
|
|
67
|
+
const babelConfigOpts = loadBabelConfig({
|
|
68
|
+
projectRoot,
|
|
69
|
+
enableBabelRCLookup: true,
|
|
70
|
+
extendsBabelConfigPath: null,
|
|
71
|
+
});
|
|
72
|
+
return {
|
|
73
|
+
root: projectRoot,
|
|
74
|
+
babelrcRoots: projectRoot,
|
|
75
|
+
babelrc: true,
|
|
76
|
+
configFile: true,
|
|
77
|
+
extends: babelConfigOpts.exts,
|
|
78
|
+
presets: babelConfigOpts.presets,
|
|
79
|
+
caller: { name: 'metro', bundler: 'metro', platform: 'ios' },
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
module.exports = {
|
|
84
|
+
resolveBabelOptions,
|
|
85
|
+
};
|
|
@@ -1,38 +0,0 @@
|
|
|
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('expo/internal/babel-preset', {
|
|
20
|
-
paths: [projectRoot, __dirname],
|
|
21
|
-
});
|
|
22
|
-
} catch {
|
|
23
|
-
try {
|
|
24
|
-
// TODO(@kitten): Temporary, since our E2E tests don't use monorepo
|
|
25
|
-
// packages consistently, including the `expo` package
|
|
26
|
-
return require.resolve('babel-preset-expo');
|
|
27
|
-
} catch (error) {
|
|
28
|
-
if (error.code === 'MODULE_NOT_FOUND') {
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
throw error;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
module.exports = {
|
|
37
|
-
resolveBabelConfig,
|
|
38
|
-
};
|