123*_*2kc 5 jestjs babeljs react-native expo
我正在将 SDK 从 Expo 管理的工作流切换到 Expo 裸工作流,以减少 Expo 中包含的一些不必要的库。我目前正在使用 Expo 的一些库,例如 Secure-store、Constants 和 Web 浏览器,而不是使用整个 Expo 包。我有一些测试最初是在 jest、jest-expo 和 Expo 中运行的。我从 jest 中删除了 expo 并尝试仅使用上面的三个 expo 库和 @unimodules 来编译 jest。测试文件具有导入语句,例如:
import * as SecureStore from 'expo-secure-store';
import * as WebBrowser from 'expo-web-browser';
import Constants from 'expo-constants';
Run Code Online (Sandbox Code Playgroud)
但是,在编译 jest 时,它不断给我
Jest 遇到意外标记 这通常意味着您正在尝试导入 Jest 无法解析的文件,例如它不是普通的 JavaScript。>SyntaxError:从“expo-constants”导入常量时出现意外的令牌导入;>ScriptTransformer._transformAndBuildScript(node_modules/@jest/transform/build/ScriptTransformer.js:471:17)
似乎我可能已经解决了 expo-secure-store 的意外导入,因为我之前遇到过该错误。我从 Babel6 切换到 babel7,添加了一个如下所示的 babel.config.js:
module.exports = {
presets: [
'@babel/preset-env'
],
env: {
test: {
presets: [['@babel/preset-env']]
}
},
plugins: [
"@babel/plugin-proposal-class-properties",
"@babel/plugin-transform-modules-commonjs"
]
};
Run Code Online (Sandbox Code Playgroud)
我正在从 jest-preset: jest-expo 切换到 jest-preset: react-native。
我的工作流程有问题吗?任何帮助表示赞赏。
有点晚了,但我遇到了这个问题,我修复了添加
"transformIgnorePatterns": [
"node_modules/(?!(jest-)?react-native|react-clone-referenced-element|@react-native-community|expo(nent)?|@expo(nent)?/.*|react-navigation|@react-navigation/.*|@unimodules/.*|unimodules|sentry-expo|native-base|@sentry/.*)"
]
Run Code Online (Sandbox Code Playgroud)
遵循https://docs.expo.io/guides/testing-with-jest/的指南
| 归档时间: |
|
| 查看次数: |
679 次 |
| 最近记录: |