and*_*mel 1 typescript karma-jasmine karma-typescript
我尝试使用karma-typescript和 jasmine 运行我的第一个 spec.ts 文件。
我已经遇到了很多不同的错误,我用谷歌搜索并“修复”了这些错误,但我总是遇到其他问题。
运行应用程序没有问题。只是测试不编译。
我需要以不同的方式配置 karma 编译器吗?
目前我只使用1中的“最小业力配置” 。
module.exports = function(config) {
config.set({
frameworks: ["jasmine", "karma-typescript"],
files: [
"src/**/*.ts" // *.tsx for React Jsx
],
preprocessors: {
"**/*.ts": "karma-typescript" // *.tsx for React Jsx
},
reporters: ["progress", "karma-typescript"],
browsers: ["Chrome"]
});
};
Run Code Online (Sandbox Code Playgroud)
当前的错误是
> ts-node node_modules/karma/bin/karma start ./karma.conf.js
29 05 2018 15:49:04.611:INFO [compiler.karma-typescript]: Compiling project using Typescript 2.8.3
29 05 2018 15:49:07.176:ERROR [compiler.karma-typescript]: node_modules/@types/node/index.d.ts(6208,55): error TS2304: Cannot find name 'Map'.
29 05 2018 15:49:07.177:ERROR [compiler.karma-typescript]: node_modules/@types/node/index.d.ts(6215,55): error TS2304: Cannot find name 'Set'.
29 05 2018 15:49:07.178:ERROR [compiler.karma-typescript]: node_modules/@types/node/index.d.ts(6219,64): error TS2304: Cannot find name 'Symbol'.
29 05 2018 15:49:07.178:ERROR [compiler.karma-typescript]: node_modules/@types/node/index.d.ts(6225,59): error TS2304: Cannot find name 'WeakMap'.
29 05 2018 15:49:07.178:ERROR [compiler.karma-typescript]: node_modules/@types/node/index.d.ts(6226,59): error TS2304: Cannot find name 'WeakSet'.
29 05 2018 15:49:07.179:ERROR [compiler.karma-typescript]: src/commands/persistence/eventStore/inmemory/InMemoryES.ts(14,26): error TS2304: Cannot find name 'Map'.
29 05 2018 15:49:07.257:INFO [compiler.karma-typescript]: Compiled 9 files in 2632 ms.
29 05 2018 15:49:07.287:INFO [karma]: Karma v2.0.2 server started at http://0.0.0.0:9876/
29 05 2018 15:49:07.288:INFO [launcher]: Launching browser Chrome with unlimited concurrency
29 05 2018 15:49:07.334:INFO [launcher]: Starting browser Chrome
29 05 2018 15:49:09.701:INFO [Chrome 66.0.3359 (Windows 10 0.0.0)]: Connected on socket JvL2wqL-IoqPWKS8AAAA with id 62494987
Chrome 66.0.3359 (Windows 10 0.0.0) ERROR
{
"message": "You need to include some adapter that implements __karma__.start method!",
"str": "You need to include some adapter that implements __karma__.start method!"
}
Unhandled rejection Error: COMPILATION ERROR
at maybeWrapAsError (E:\_d_a_t_e_n\programmieren\private\_web\ADB\ADB-Service\node_modules\bluebird\js\release\util.js:61:12)
at E:\_d_a_t_e_n\programmieren\private\_web\ADB\ADB-Service\node_modules\bluebird\js\release\nodeback.js:38:50
Run Code Online (Sandbox Code Playgroud)
我当前的tsconfig.json文件
{
"compilerOptions": {
"target": "es5",
"lib": ["es5", "es6", "dom"], // added because of karma problems, did not help though (/sf/answers/2759280541/, /sf/ask/2991703641/)
"module": "commonjs",
"noImplicitAny": true,
"removeComments": true,
"outDir": "./dist/",
"sourceMap": true,
"pretty": true
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules"
],
"typeRoots": [
"node_modules/@types"
]
}
Run Code Online (Sandbox Code Playgroud)
以及package.json中的依赖项
{
"name": "adb-service",
"version": "0.0.0",
"private": true,
"description": "Backend Express Server",
"main": "node dist/index.js",
"scripts": {
"start": "nodemon dist/index.js",
"dev": "concurrently --kill-others \"tsc -w\" \"nodemon dist/index.js\"",
"test2": "ts-node node_modules/jasmine/bin/jasmine",
"test": "ts-node node_modules/karma/bin/karma start ./karma.conf.js"
},
"author": "Andymel",
"dependencies": {
"body-parser": "^1.18.2",
"express": "^4.16.3",
"mongoose": "^5.1.0"
},
"devDependencies": {
"@types/body-parser": "^1.16.8",
"@types/express": "^4.11.1",
"@types/jasmine": "^2.8.7",
"@types/mongodb": "^3.0.13",
"@types/mongoose": "^5.0.13",
"@types/node": "^10.1.3",
"concurrently": "^3.5.1",
"jasmine": "^3.1.0",
"karma": "^2.0.2",
"karma-chrome-launcher": "^2.2.0",
"karma-jasmine": "^1.1.2",
"karma-typescript": "^3.0.12",
"nodemon": "^1.17.3",
"ts-node": "^6.0.5",
"typescript": "^2.8.3"
}
}
Run Code Online (Sandbox Code Playgroud)
预先感谢您的任何提示!
我尝试用 开始测试npm test。
我成功运行该应用程序npm run dev
我将以下行添加到 karma.config.js (受此 github 问题启发)
karmaTypescriptConfig: {
compilerOptions: {
target: "ES2015",
lib: ["es5", "es6", "es2015", "dom"]
},
tsconfig: "tsconfig.json"
},
Run Code Online (Sandbox Code Playgroud)
这消除了编译器错误。我现在遇到运行时错误,但这是另一个问题。
| 归档时间: |
|
| 查看次数: |
2435 次 |
| 最近记录: |