typescript的Karma测试:找不到请求的文件
我正在将带有Karma的集成测试添加到React项目中,我有一堆Mocha测试,Chai用TypeScript编写,使用ES6模块导入。我已经添加了一个功能,希望一切都能协同工作,并传输类型脚本测试 为了使用Karma运行这些测试,我已经使用typescript的Karma测试:找不到请求的文件,typescript,karma-runner,karma-typescript,Typescript,Karma Runner,Karma Typescript,我正在将带有Karma的集成测试添加到React项目中,我有一堆Mocha测试,Chai用TypeScript编写,使用ES6模块导入。我已经添加了一个功能,希望一切都能协同工作,并传输类型脚本测试 为了使用Karma运行这些测试,我已经使用Karma init my.conf.js初始化了以下项目: // Karma configuration // Generated on Tue Sep 22 2020 23:59:00 GMT+0200 (Central European Summer
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
有人知道测试失败的原因吗?我不知道它是否会有帮助,但我认为
{pattern:'test/***/.karma.ts',module:true}
应该有类型:“module”
,而不是module:true
,这为karma添加了ESM功能。再说一次,我不知道内置ESM支持如何与开放式wc插件交互——也许你不应该同时使用这两个插件?你有没有找到答案?我试图让karma、mocha、ESM模块和TypeScript都愉快地一起工作,我遇到了同样的障碍。我不知道这是否会有帮助,但我认为{pattern:'test/***/*.karma.ts',module:true}
应该具有类型:“module”
,而不是module:true
,这为karma添加了ESM功能。再说一次,我不知道内置ESM支持如何与开放式wc插件交互——也许你不应该同时使用这两个插件?你有没有找到答案?我试图让karma、mocha、ESM模块和TypeScript都能愉快地协同工作,我遇到了同样的障碍。