- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
该项目正在使用 ReactJS、Typescript、Webpack 和 Jest。为了实现模块解析(以最小化导入),我们进行了以下更改:
TSConfig.js:
"compilerOptions": { "baseUrl": "src",}
Webpack.config.js
alias: {
Common: path.resolve(__dirname, 'src/Common/'),
},
代码工作正常,但是 Jest 测试开始失败并出现错误:
Cannot find module 'Common/js/utils' from 'MyContact.ts'
这是因为,Jest 还不知道如何将 Common 解析为 Src/common 而不是在 node_module 中查找。为解决此问题,进行了以下更改:
jestConfig.js
moduleNameMapper: {"Common": "<rootDir>/src/Common"}
这似乎是固定的,但后来我有另一个问题 [这就是我在这里的原因:)]
Jest 遇到了意外的 token
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
Here's what you can do:
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/en/configuration.html
Details:
C:\Users\ua\Project\develop\src\Common\index.ts:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){export * from './Acc'
^^^^^^
SyntaxError: Unexpected token export
at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:537:17)
at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:579:25)
这是完整的 jest.config.js 文件:
module.exports = {
verbose: false,
roots: ["<rootDir>/src"],
transform: {
"^.+\\.tsx?$": "ts-jest",
},
globals: {
'ts-jest': {
diagnostics: false
}
},
moduleNameMapper: {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$":
"<rootDir>/__mocks__/fileMock.js",
"\\.(css|less|pcss)$": "<rootDir>/__mocks__/styleMock.js",
"Common": "<rootDir>/src/Common",
},
snapshotSerializers: ["enzyme-to-json/serializer"],
setupFilesAfterEnv: ["<rootDir>/setupEnzyme.ts"],
testMatch: [ "**/__tests__/**/*.test.[jt]s?(x)", "**/?(*.)+(spec|test).[jt]s?(x)"],
collectCoverageFrom: ["**/*.{ts,tsx}", "!**/node_modules/**", "!**/vendor/**"]
};
tsconfig.js:
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "src",
"typeRoots": [
"./node_modules/@types",
"./custom_typings"
],
"outDir": "build",
"module": "commonjs",
"skipLibCheck": true,
"moduleResolution": "node",
"removeComments": true,
"target": "es5",
"sourceMap": true,
"lib": [ "dom", "es2015", "es2017", "esnext" ],
"noEmit": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"noImplicitAny": false,
"allowUnusedLabels": false,
"jsx": "react",
"allowJs": true,
"isolatedModules": false,
"strictNullChecks": false,
"noEmitHelpers": false,
"allowSyntheticDefaultImports": true
},
"typeRoots": [
"./node_modules/@types",
"./custom_typings"
],
"exclude":[
"./node_modules"
],
"include": [
"src/*",
"custom_typings"
]
}
最佳答案
好的,所以我能够通过将这一行添加到 jest.config.js 来修复模块解析
模块目录:["node_modules", "src"],
关于typescript - 带有模块分辨率的 typescript 的 Jest 设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58206476/
我正在使用 JavaFX 开发视频播放器。我正在将视频从本地文件系统加载到 JavaFX 类媒体中。然后我想获取宽度和高度,以便我可以将场景的尺寸设置为该大小: Media media = new M
我是OpenCV的新手,正在尝试解决这个问题。我有一个.mp4文件保存在从网络摄像头流式传输的磁盘上。现在,我需要制作视频的低分辨率版本,以上传到Web服务器(这个想法是,低分辨率预览实时或多或少地上
我在我的应用程序中使用 jfree 图表(折线图)...创建时我的图表看起来很模糊...我怎样才能获得高清晰度图像。 我使用过:ChartUtilities.writeScaledChartAsPNG
我正在用 Java 编写一个工具来处理我网站上上传的文件。我想以特定的方式管理图像:如果尺寸大于限制,我想首先调整图像的尺寸,然后再次检查尺寸。当然,我不想做无用的工作,所以我想在调整图像大小之前估计
是否有一种纯 WPF 方法来获取有关所有可用显示器大小(分辨率)的信息。我知道我可以使用 Screen.AllScreens 来获取它们,但在我的遗留项目中我无法添加新的引用(内置 WPF 程序集除外
看了Developer文档,部分理解了LDPI,HDPI,MDPI,XHDPI类比,网上到处找也没有找到具体答案。 我有两部手机,一部是小屏幕,一部是平板电脑。我希望我的小屏幕手机上的按钮看起来很小,
对于下面给定的网页, xyz {% load staticfiles %} html, body {
我在 Mac 上使用多个 JFrames 制作了一个程序,分辨率还可以,一切都适合屏幕。但是,当我在我的 PC 上运行该程序时,JFrames 太大并且会立即离开屏幕。 我的问题是:是否可以在 JFr
我需要有关如何检索屏幕分辨率的帮助,如下图所示。 我找到了 this documentation这真的很有帮助。这是我根据这些文档尝试的代码: int numberOfScreens = GetSys
有什么方法可以更改分辨率或为亚马逊 Kindle 键盘上的屏幕设置不同的边界?我的屏幕有一部分出现裂纹,我想解决这个问题。 我试过在文件系统中乱搞(通过 WiFi 连接),但我的所有属性更改都没有任何
快速提问, 我正在开发 libgdx 中的游戏,但遇到了问题。我正在尝试扩展我的 Assets ,我正在使用 Gdx.graphics.getDensity() 来获取密度,然后使用它作为乘数来设置我
我有一些关于屏幕分辨率的问题,我不清楚。这些问题假设我的应用程序将在 iOS 4.0 及更高版本以及 iPhone 3GS 或 iPhone 4 上运行。 启动图像 (default.png) 的大小
我们有一个应用程序在审核过程中被 Apple 应用程序审核人员拒绝。拒绝的原因是应用程序在 Ipad 上运行时无法正确缩放。 该应用程序本来就不是要在 Ipad 上运行的,但与他们争论这一点似乎没有意
我试图在不解码文件的情况下获取 JPEG 图像的分辨率。我从互联网上获得了几个样本,但没有一个可以正常工作。似乎是这样,因为许多 JPEG 文件不是标准的,尽管任何图形应用程序(Irfan、PSP、F
我尝试了很多事情,但是所有尝试都失败了。 我需要将灰度图像(2560x1440)调整为更低或更高的分辨率,然后我需要将边界设置为原始大小(2560x1440),但将调整后的图像保持在中心。 我使用的是
我正在使用 GLSulfaceView 开发一个静音相机应用程序,该应用程序从预览中捕获图片。 为了捕捉图片,我使用 GLES20.glReadPixels(0, 0, surfaceWidth, s
是否有相当于 yarn resolutions 的 npm功能? npm package.json docs 中没有提及它. 例如,我想在 3.3.2 上安装 lerna@3.3.2 及其依赖项之一
我制作了一个在 Arduino 上运行的 24x15 LED 显示屏,去年我在内存中放入了 32KB 的图形例程,这很酷。 但现在我已经升级到 Arduino Mega,具有 256KB 内存,并且有
我的场景是,我正在收集网络数据包,如果数据包与网络过滤器匹配,我想记录连续数据包之间的时间差,最后一部分是不起作用的部分。我的问题是,无论我使用什么 C 定时器函数,我都无法获得准确的亚秒级测量。我尝
我们一直在学校布置一项任务,需要更改图像(反转颜色、切换颜色、旋转 90 度、双倍大小、放大图像),现在我正在尝试通过将分辨率加倍来使其大小加倍,但无法弄清楚如何访问该地址并更改它。我们得到了两个函数
我是一名优秀的程序员,十分优秀!