jkt*_*vis 9 typescript jestjs babeljs openlayers-5
我正在尝试为某些碰巧导入一两个 openlayers 模块的模块编写一些测试。但正如其他一些人发现的那样(此处、此处和此处),这并不是开箱即用的。这是我尝试过的:
.babelrc
并babel.config.js
导出配置transformIgnorePatterns
到我的jest.config.js
我现在只是不知道如何解决这个问题。
我在用着:
这是我的配置:
笑话:
module.exports = {
setupFiles: [
"./testConfig/test-shim.js",
"./testConfig/test-setup.js"
],
transform: {
"^.+\\.tsx?$": "ts-jest"
},
transformIgnorePatterns: [
"/node_modules/(?!(ol)/).*/",
"node_modules/(?!(ol)/)",
],
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx|tsx?)$",
moduleNameMapper: {
"^(Controllers|Api|Utilities)/(.*)$": "<rootDir>Scripts/$1/$2"
},
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
coverageReporters: ["text", "text-summary", "html"],
coverageDirectory: "testConfig/coverageReport",
collectCoverageFrom: ["**/Scripts/{App,Controllers,Utilities,Localization,EntryPoints}/**/*.{ts,tsx}"],
coverageThreshold: {
global: {
branches: 0,
functions: 0,
lines: 0,
statements: 0
}
}
};
Run Code Online (Sandbox Code Playgroud)
终于可以工作了。问题在于该项目正在使用 TypeScript,并且像往常一样,这使事情变得比需要的复杂得多。
由于需要编译 OL 源,并且这些文件是用 JavaScript 编写的,因此我需要向我的配置添加另一个转换来处理这些文件。之后,它抱怨画布,所以我还必须安装一个画布模拟。
所以我的配置的更改部分如下:
setupFiles: [
"./testConfig/test-shim.js",
"jest-canvas-mock", // <- the new mock
"./testConfig/test-setup.js"
],
transform: {
"^.+\\.tsx?$": "ts-jest",
"^.+\\.jsx?$": "babel-jest", // <- also compile js/x files
},
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
transformIgnorePatterns: [
"node_modules/(?!(ol)/)", // <- exclude the OL lib
],
Run Code Online (Sandbox Code Playgroud)
希望这对其他人有帮助!
归档时间: |
|
查看次数: |
2826 次 |
最近记录: |