问题描述
我正在将与Karma的集成测试添加到React项目中,并且我有大量使用TypeScript编写的使用Chai编写的Mocha测试,这些测试使用ES6模块导入。希望所有内容都能一起工作,我添加了karma-typescript
,karma-sourcemap-loader
和@open-wc/karma-esm
来转换打字稿测试。
要使用Karma运行这些测试,我已使用karma init my.conf.js
初始化了以下项目:
// Karma configuration
// Generated on Tue Sep 22 2020 23:59:00 GMT+0200 (Central European Summer Time)
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files,exclude)
basePath: '',plugins: [
require.resolve('@open-wc/karma-esm'),'karma-*'
],// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: [
'mocha','chai','karma-typescript','esm'
],// list of files / patterns to load in the browser
files: [
'test/global.ts',{pattern: 'test/**/*.karma.ts',module: true}
],// list of files / patterns to exclude
exclude: [
],// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'test/**/*.ts': ['karma-typescript','sourcemap']
},// test results reporter to use
// possible values: 'dots','progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],// web server port
port: 9876,// enable / disable colors in the output (reporters and logs)
colors: true,// level of logging
// possible values: config.LOG_disABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],// Continuous Integration mode
// if true,Karma captures browsers,runs the tests and exits
singleRun: false,// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity,karmaTypescriptConfig: {
bundlerOptions: {
sourceMap: true
},compilerOptions: {
emitDecoratorMetadata: true,experimentalDecorators: true,allowSyntheticDefaultImports: true,jsx: "react",module: "es6",moduleResolution: "node",sourceMap: true,target: "ES5"
},exclude: ["node_modules"]
}
})
}
但是,当我使用$ npx karma start --log-level debug --no-single-run my.conf.js
运行这些测试时,出现以下错误:
(...)
[karma-esm]: Could not find requested file: /test/sometest.karma.js?7f18cbf56f32714fa3b45bed3920cbf0123c0f13
(...)
TOTAL: 0 SUCCESS
有人知道为什么测试失败吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)