无法将 .ts 文件与 Jasmine 和 Karma 一起使用。获取错误 'Unable to determine file type..'
Not able to use .ts files with Jasmine and Karma. Getting error 'Unable to determine file type..'
我真的需要一些帮助来配置 karma.conf.js 来处理打字稿文件,或者不确定缺少什么或我在这里做错了什么。单元测试的新手并学习了 Jasmine 框架(在示例中它使用 *.js 和 *.spec.js 文件)但在我的 ionic-angular 项目中它的 *.ts 文件并出现错误(如下所示)。我一直试图弄清楚 2 天,但无法解决这个问题。非常感谢任何帮助。
[使用 ionic 3 (ionic-angular 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
}
}
我的 karma.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
})
};
我的 package.json devDependencies:
"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
添加预处理器将 TypeScript 编译为常规 Javascript 后,通过将其放入 files: []
数组来告诉 Karma 它是一个 js
文件:
files: [
{
pattern: 'src/**/*.ts',
type: 'js' // to silence the warning. Means load with <script> tag
},
]
我真的需要一些帮助来配置 karma.conf.js 来处理打字稿文件,或者不确定缺少什么或我在这里做错了什么。单元测试的新手并学习了 Jasmine 框架(在示例中它使用 *.js 和 *.spec.js 文件)但在我的 ionic-angular 项目中它的 *.ts 文件并出现错误(如下所示)。我一直试图弄清楚 2 天,但无法解决这个问题。非常感谢任何帮助。
[使用 ionic 3 (ionic-angular 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
}
}
我的 karma.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
})
};
我的 package.json devDependencies:
"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
添加预处理器将 TypeScript 编译为常规 Javascript 后,通过将其放入 files: []
数组来告诉 Karma 它是一个 js
文件:
files: [
{
pattern: 'src/**/*.ts',
type: 'js' // to silence the warning. Means load with <script> tag
},
]