我确实需要一些帮助来配置karma.conf.js来处理输入文件,或者不确定缺少什么或我在这里做错了什么。对单位测试并了解了茉莉框架(在示例中使用 *.js和 *.spec.js文件),但在我的离子角度项目中,它的 *.ts文件并遇到错误(如下所示)。我一直试图弄清楚这2天,无法解决这个问题。任何帮助都非常感谢。
[使用离子3(离子角3.9。+)框架与Angular 6(6.1.10)和Typescript(3.8。+。)]我的tsconfig.json>
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
"dom",
"es2015"
],
"module": "es2015",
"moduleResolution": "node",
"sourceMap": true,
"target": "es6"
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules",
"src/**/*.spec.ts",
"src/**/__tests__/*.ts"
],
"compileOnSave": false,
"atom": {
"rewriteTsconfig": false
}
}
mykarma.conf.js>
module.exports = function (config) {
config.set({
frameworks: ['jasmine', 'jasmine-matchers'],
files: [
'src/**/*.ts',
'src/**/*.spec.ts'
],
plugins: [
'karma-jasmine',
'karma-jasmine-matchers',
'karma-chrome-launcher'
],
reporters: ['dots'],
colors: true,
browsers: ['ChromeHeadless'],
singleRun: true
})
};
"devDependencies": {
"@ionic/app-scripts": "3.2.4",
"jasmine-core": "^3.5.0",
"karma": "^5.1.0",
"karma-chrome-launcher": "^3.1.0",
"karma-jasmine": "^3.3.1",
"karma-jasmine-matchers": "^4.0.2",
"puppeteer": "^1.20.0",
"ts-node": "^8.10.2",
"typescript": "^3.8.3"
},
我得到:
15 06 2020 09:40:23.844:WARN [middleware:karma]: Unable to determine file type from the file extension, defaulting to js.
To silence the warning specify a valid type for C:/Users/USR01/Documents/testing/src/providers/member/member.ts in the configuration file.
See http://karma-runner.github.io/latest/config/files.html
........
........
15 06 2020 09:40:23.844:WARN [middleware:karma]: Unable to determine file type from the file extension, defaulting to js.
To silence the warning specify a valid type for C:/Users/USR01/Documents/testing/src/providers/scores/scores.ts in the configuration file.
Chrome 83.0.4103.97 (Windows 10): Executed 0 of 0 SUCCESS (0.001 secs / 0 secs)
npm ERR! Test failed. See above for more details.
这个看起来很有希望。https://www.npmjs.com/package/karma-typescript
一旦您将预处理器添加到常规JavaScript中,请告诉Karma,这是一个通过将其放入您的js
阵列中的文件:
files: []
我尝试使用Https://stackoverflow.com/users/36330/joeforker的答案,但是我被那样卡住了。警告消失了,但没有发现任何规格可以运行。
在我有Karma.conf.js之前,我能够进行测试。我正在添加
files: [
{
pattern: 'src/**/*.ts',
type: 'js' // to silence the warning. Means load with <script> tag
},
]
karma.conf.js
产生了karma.conf.js
。这产生了一个不再具有密钥“文件”的
ng generate config karma
。它有
karma.conf.js
。在我的frameworks: ['jasmine', '@angular-devkit/build-angular'],
中,我有:angular.json
这些引用了我的
"test": {
"builder": "@angular-devkit/build-angular:karma",
...
"tsConfig": "projects/frank-config-layout/tsconfig.spec.json",
"karmaConfig": "projects/frank-config-layout/karma.conf.js"
和我的新
tsconfig.spec.json
。我的
karma.conf.js
读:tsconfig.spec.json