我正在尝试使用业力进行单元测试,但是会抛出一些错误,我认为这是因为ES6。我正在使用:
这是我的package.json
{
"name": "wep-backend",
"version": "3.0.0-alfa",
"description": "Back-end API ",
"main": "./src/server/index.ts",
"scripts": {
"test": "tsc && karma start",
"debug": "tsc && npm run build.debug && gulp copy && concurrently \"npm run tsc:w\" \"npm run nodemon:debug \" ",
"prod": "tsc && npm run build.prod && concurrently \"npm run tsc:w\" \"npm run nodemon:w\" ",
"staging": "tsc && npm run build.staging && concurrently \"npm run tsc:w\" \"npm run nodemon:w\" ",
"start": "tsc && npm run build.dev && concurrently \"npm run tsc:w\" \"npm run nodemon:w\" ",
"nodemon:w": "nodemon --config",
"nodemon:debug": "nodemon --exec ts-node --debug src/server/index.ts",
"tsc:w": "tsc -w",
"tsc": "tsc",
"build.dev": "gulp dev",
"build.staging": "gulp staging",
"build.prod": "gulp prod",
"build.debug": "gulp debug"
},
"repository": {
"type": "git",
"url": "git@git.netlogistik.com:wep/backend.git"
},
"author": "Netlogistik",
"license": "SEE LICENSE IN LICENSE.md",
"dependencies": {
"@types/dateformat": "^1.0.1",
"@types/lodash": "^4.14.37",
"body-parser": "^1.15.2",
"concurrently": "^3.1.0",
"dateformat": "^1.0.12",
"express": "^4.14.0",
"inversify": "^2.0.1",
"inversify-express-utils": "^2.0.2",
"knex": "^0.11.10",
"lodash": "^4.16.5",
"mssql": "^3.3.0",
"reflect-metadata": "^0.1.8",
"sqlite3": "^3.1.4"
},
"devDependencies": {
"@types/bluebird": "^3.0.35",
"@types/body-parser": "^0.0.33",
"@types/dotenv": "^2.0.18",
"@types/express": "^4.0.33",
"@types/gulp": "^3.8.32",
"@types/inversify": "^2.0.31",
"@types/jasmine": "^2.5.35",
"@types/knex": "0.0.35",
"@types/mssql": "^3.1.29",
"@types/sinon": "^1.16.31",
"dotenv": "^2.0.0",
"gulp": "^3.9.1",
"gulp-file": "^0.3.0",
"jasmine-core": "^2.5.2",
"karma": "^1.3.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-coverage": "^1.1.1",
"karma-es6-shim": "^1.0.0",
"karma-jasmine": "^1.1.0",
"karma-safari-launcher": "^1.0.0",
"karma-sinon": "^1.0.5",
"karma-typescript": "^2.1.5",
"nodemon": "^1.11.0",
"sinon": "^1.17.6",
"ts-node": "^1.7.0",
"typescript": "^2.1.4"
}
}
我的karma.conf.js
module.exports = function(config) {
config.set({
frameworks: ["jasmine", "karma-typescript", "sinon", "es6-shim"],
files: [
{ pattern: "src/server/ws/**/*.ts" }
],
exclude: [
"src/server/ws/**/*.controller.ts",
"src/server/ws/**/*.repository.ts"
],
preprocessors: {
"src/server/ws/**/*.ts": ["karma-typescript", "coverage"]
},
reporters: ["progress", "karma-typescript", "coverage"],
coverageReporter: {
reporters: [
{
type: "text-summary"
},
{
type: "html",
dir: "coverage/"
}
]
},
browsers: ["Chrome"]
});
};
这些是抛出编译器的错误
06 01 2017 17:18:04.887:ERROR [compiler.karma-typescript]: src/server/ws/user/user.controller.ts(180,26): error TS2304: Cannot find name 'Promise'.
06 01 2017 17:18:04.887:ERROR [compiler.karma-typescript]: src/server/ws/user/user.controller.ts(210,32): error TS2304: Cannot find name 'Promise'.
06 01 2017 17:18:04.887:ERROR [compiler.karma-typescript]: src/server/ws/user/user.repository.ts(23,69): error TS2304: Cannot find name 'Promise'.
06 01 2017 17:18:04.887:ERROR [compiler.karma-typescript]: src/server/ws/user/user.repository.ts(24,29): error TS2304: Cannot find name 'Promise'.
06 01 2017 17:18:04.887:ERROR [compiler.karma-typescript]: src/server/ws/user/user.repository.ts(25,30): error TS2304: Cannot find name 'Promise'.
06 01 2017 17:18:04.888:ERROR [compiler.karma-typescript]: src/server/ws/user/user.repository.ts(45,26): error TS2339: Property 'then' does not exist on type 'QueryBuilder'.
06 01 2017 17:18:04.888:ERROR [compiler.karma-typescript]: src/server/ws/user/user.repository.ts(81,29): error TS2304: Cannot find name 'Promise'.
06 01 2017 17:18:04.888:ERROR [compiler.karma-typescript]: src/server/ws/user/user.repository.ts(82,32): error TS2304: Cannot find name 'Promise'.
06 01 2017 17:18:04.888:ERROR [compiler.karma-typescript]: src/server/ws/user/user.repository.ts(83,33): error TS2304: Cannot find name 'Promise'.
06 01 2017 17:18:04.888:ERROR [compiler.karma-typescript]: src/server/ws/user/user.repository.ts(88,22): error TS2339: Property 'then' does not exist on type 'QueryBuilder'.
06 01 2017 17:18:04.888:ERROR [compiler.karma-typescript]: src/server/ws/user/user.repository.ts(102,16): error TS2304: Cannot find name 'Promise'.
06 01 2017 17:18:04.888:ERROR [compiler.karma-typescript]: src/server/ws/user/user.repository.ts(104,30): error TS2304: Cannot find name 'Promise'.
06 01 2017 17:18:04.888:ERROR [compiler.karma-typescript]: src/server/ws/user/user.repository.ts(106,31): error TS2304: Cannot find name 'Promise'.
06 01 2017 17:18:04.889:ERROR [compiler.karma-typescript]: src/server/ws/user/user.repository.ts(114,22): error TS2339: Property 'then' does not exist on type 'QueryBuilder'.
06 01 2017 17:18:04.889:ERROR [compiler.karma-typescript]: src/server/ws/user/user.repository.ts(119,51): error TS2339: Property 'find' does not exist on type 'User[]'.
06 01 2017 17:18:04.890:ERROR [compiler.karma-typescript]: src/server/ws/user/user.repository.ts(161,31): error TS2304: Cannot find name 'Promise'.
06 01 2017 17:18:04.891:ERROR [compiler.karma-typescript]: src/server/ws/user/user.repository.ts(162,30): error TS2304: Cannot find name 'Promise'.
06 01 2017 17:18:04.891:ERROR [compiler.karma-typescript]: src/server/ws/user/user.repository.ts(164,31): error TS2304: Cannot find name 'Promise'.
06 01 2017 17:18:04.891:ERROR [compiler.karma-typescript]: src/server/ws/user/user.repository.ts(171,22): error TS2339: Property 'then' does not exist on type 'QueryBuilder'.
06 01 2017 17:18:04.891:ERROR [compiler.karma-typescript]: src/server/ws/user/user.repository.ts(208,44): error TS2304: Cannot find name 'Promise'.
06 01 2017 17:18:04.892:ERROR [compiler.karma-typescript]: src/server/ws/user/user.repository.ts(209,30): error TS2304: Cannot find name 'Promise'.
06 01 2017 17:18:04.892:ERROR [compiler.karma-typescript]: src/server/ws/user/user.repository.ts(211,31): error TS2304: Cannot find name 'Promise'.
06 01 2017 17:18:04.892:ERROR [compiler.karma-typescript]: src/server/ws/user/user.repository.ts(214,22): error TS2339: Property 'then' does not exist on type 'QueryBuilder'.
06 01 2017 17:18:04.893:ERROR [compiler.karma-typescript]: src/server/ws/user/user.repository.ts(230,31): error TS2304: Cannot find name 'Promise'.
06 01 2017 17:18:04.893:ERROR [compiler.karma-typescript]: src/server/ws/user/user.repository.ts(231,30): error TS2304: Cannot find name 'Promise'.
06 01 2017 17:18:04.894:ERROR [compiler.karma-typescript]: src/server/ws/user/user.repository.ts(233,31): error TS2304: Cannot find name 'Promise'.
06 01 2017 17:18:04.894:ERROR [compiler.karma-typescript]: src/server/ws/user/user.repository.ts(241,26): error TS2339: Property 'then' does not exist on type 'QueryBuilder'.
06 01 2017 17:18:04.894:ERROR [compiler.karma-typescript]: src/server/ws/user/user.repository.ts(262,51): error TS2304: Cannot find name 'Promise'.
06 01 2017 17:18:04.894:ERROR [compiler.karma-typescript]: src/server/ws/user/user.repository.ts(263,32): error TS2304: Cannot find name 'Promise'.
06 01 2017 17:18:04.894:ERROR [compiler.karma-typescript]: src/server/ws/user/user.repository.ts(265,33): error TS2304: Cannot find name 'Promise'.
06 01 2017 17:18:04.894:ERROR [compiler.karma-typescript]: src/server/ws/user/user.repository.ts(268,22): error TS2339: Property 'then' does not exist on type 'QueryBuilder'.
06 01 2017 17:18:04.894:ERROR [compiler.karma-typescript]: src/server/ws/user/user.repository.ts(285,47): error TS2304: Cannot find name 'Promise'.
06 01 2017 17:18:04.895:ERROR [compiler.karma-typescript]: src/server/ws/user/user.repository.ts(286,32): error TS2304: Cannot find name 'Promise'.
06 01 2017 17:18:04.896:ERROR [compiler.karma-typescript]: src/server/ws/user/user.repository.ts(288,33): error TS2304: Cannot find name 'Promise'.
06 01 2017 17:18:04.896:ERROR [compiler.karma-typescript]: src/server/ws/user/user.repository.ts(296,26): error TS2339: Property 'then' does not exist on type 'QueryBuilder'.
06 01 2017 17:18:05.572:INFO [compiler.karma-typescript]: Compiled 118 files in 3409 ms.
06 01 2017 17:18:06.529:INFO [builtin-bundler.karma-typescript]: Bundled imports for 69 file(s) in 380 ms.
06 01 2017 17:18:07.446:WARN [karma]: No captured browser, open http://localhost:9876/
06 01 2017 17:18:07.454:INFO [karma]: Karma v1.3.0 server started at http://localhost:9876/
06 01 2017 17:18:07.454:INFO [launcher]: Launching browser Chrome with unlimited concurrency
06 01 2017 17:18:07.506:INFO [launcher]: Starting browser Chrome
06 01 2017 17:18:09.530:INFO [Chrome 55.0.2883 (Mac OS X 10.12.2)]: Connected on socket /#Q5le2XaT3wVYNPqcAAAA with id 2301486
Chrome 55.0.2883 (Mac OS X 10.12.2) ERROR
Uncaught Error: Not found: /Users/raansilrey/WebstormProjects/wep-backend/src/server/constants/types.ts
at node_modules/karma-typescript/lib/bundlers/builtin/commonjs.js:15
有人可以帮助我吗?
感谢。