Karma + Angular1: window.angular.$$csp 不是函数
Karma + Angular1: window.angular.$$csp is not a function
我正在尝试使用 Karma and Jasmine, as well as karma-wiredep
为 Angular 1.6 应用程序编写测试以加载 Bower 依赖项 - 目前它只包含 Angular 1.6.3。当我尝试 运行 karma start
我能够看到依赖项加载但是 Chrome 和 PhantomJS 即使没有加载我的 application/test 代码也会失败所以我认为问题出在Karma 配置 - 日志确实显示 angular.js 正在加载。两者的错误与 PhantomJS 报告 WARNING: Tried to load angular more than once.
相似,但我没有在日志中看到这种情况。 Karma 的配置方式有问题吗?
Chrome 57.0.2987 (Mac OS X 10.12.3) ERROR
Uncaught TypeError: window.angular.$$csp is not a function
at bower_components/angular/angular.js:33345
PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
TypeError: undefined is not a constructor (evaluating 'window.angular.$$csp()')
at bower_components/angular/angular.js:33345
PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
TypeError: undefined is not a constructor (evaluating 'angular.module('ngAnimateMock', ['ng'])
.info({ angularVersion: '1.6.3' })')
at bower_components/angular-mocks/angular-mocks.js:800
karma.conf.js
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['wiredep', 'ng-scenario', 'jasmine'],
//you can configure wiredep from here (optional)
wiredep: {
dependencies: true, // default: true
devDependencies: true, // default: false
},
// list of files / patterns to load in the browser
files: [
],
// list of files to exclude
exclude: [
],
// 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,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_DEBUG,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
// browsers: ['Chrome', 'Firefox', 'Safari', 'PhantomJS', 'IE'],
browsers: ['Chrome'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: true,
// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity
})
}
bower.json
{
"name": "app-name",
"main": "script.js",
"version": "0.0.1",
"homepage": "",
"authors": [],
"description": "",
"keywords": [],
"license": "",
"ignore": [],
"dependencies": {
"angular": "^1.6.3"
},
"devDependencies": {
"angular-mocks": "~1.6.x"
}
}
chrome 日志输出
> karma start karma.conf.js
18 03 2017 15:45:22.180:DEBUG [config]: autoWatch set to false, because of singleRun
18 03 2017 15:45:22.185:DEBUG [plugin]: Loading karma-* from /path/to/app/node_modules
18 03 2017 15:45:22.187:DEBUG [plugin]: Loading plugin /path/to/app/node_modules/karma-babel-preprocessor.
18 03 2017 15:45:22.550:DEBUG [plugin]: Loading plugin /path/to/app/node_modules/karma-chrome-launcher.
18 03 2017 15:45:22.554:DEBUG [plugin]: Loading plugin /path/to/app/node_modules/karma-jasmine.
18 03 2017 15:45:22.555:DEBUG [plugin]: Loading plugin /path/to/app/node_modules/karma-ng-html2js-preprocessor.
18 03 2017 15:45:22.556:DEBUG [plugin]: Loading plugin /path/to/app/node_modules/karma-ng-scenario.
18 03 2017 15:45:22.556:DEBUG [plugin]: Loading plugin /path/to/app/node_modules/karma-phantomjs-launcher.
18 03 2017 15:45:22.586:DEBUG [plugin]: Loading plugin /path/to/app/node_modules/karma-wiredep.
18 03 2017 15:45:22.686:DEBUG [web-server]: Instantiating middleware
18 03 2017 15:45:22.764:INFO [karma]: Karma v1.5.0 server started at http://0.0.0.0:9876/
18 03 2017 15:45:22.764:INFO [launcher]: Launching browser Chrome with unlimited concurrency
18 03 2017 15:45:22.779:INFO [launcher]: Starting browser Chrome
18 03 2017 15:45:22.780:DEBUG [temp-dir]: Creating temp dir at /var/folders/84/81q1wl5d5k58flxbpcgqq78w0000gn/T/karma-67345543
18 03 2017 15:45:22.780:DEBUG [launcher]: /Applications/Google Chrome.app/Contents/MacOS/Google Chrome --user-data-dir=/var/folders/84/81q1wl5d5k58flxbpcgqq78w0000gn/T/karma-67345543 --no-default-browser-check --no-first-run --disable-default-apps --disable-popup-blocking --disable-translate --disable-background-timer-throttling --disable-device-discovery-notifications http://localhost:9876/?id=67345543
18 03 2017 15:45:23.538:DEBUG [web-server]: serving: /path/to/app/node_modules/karma/static/client.html
18 03 2017 15:45:23.557:DEBUG [web-server]: serving: /path/to/app/node_modules/karma/static/karma.js
18 03 2017 15:45:23.751:DEBUG [karma]: A browser has connected on socket 358rR6cCQQIt8Y11AAAA
18 03 2017 15:45:23.753:DEBUG [web-server]: serving: /path/to/app/node_modules/karma/static/favicon.ico
18 03 2017 15:45:23.762:DEBUG [web-server]: upgrade /socket.io/?EIO=3&transport=websocket&sid=358rR6cCQQIt8Y11AAAA
18 03 2017 15:45:23.808:INFO [Chrome 57.0.2987 (Mac OS X 10.12.3)]: Connected on socket 358rR6cCQQIt8Y11AAAA with id 67345543
18 03 2017 15:45:23.809:DEBUG [launcher]: Chrome (id 67345543) captured in 1.045 secs
18 03 2017 15:45:23.837:DEBUG [middleware:karma]: custom files null null null
18 03 2017 15:45:23.837:DEBUG [middleware:karma]: Serving static request /context.html
18 03 2017 15:45:23.839:DEBUG [web-server]: serving: /path/to/app/node_modules/karma/static/context.html
18 03 2017 15:45:23.856:DEBUG [middleware:source-files]: Requesting /base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js?916005cc407925f4764668d61d04888d59258f5d /
18 03 2017 15:45:23.856:DEBUG [middleware:source-files]: Fetching /path/to/app/node_modules/jasmine-core/lib/jasmine-core/jasmine.js
18 03 2017 15:45:23.857:DEBUG [web-server]: serving (cached): /path/to/app/node_modules/jasmine-core/lib/jasmine-core/jasmine.js
18 03 2017 15:45:23.859:DEBUG [middleware:source-files]: Requesting /base/node_modules/karma-jasmine/lib/boot.js?945a38bf4e45ad2770eb94868231905a04a0bd3e /
18 03 2017 15:45:23.859:DEBUG [middleware:source-files]: Fetching /path/to/app/node_modules/karma-jasmine/lib/boot.js
18 03 2017 15:45:23.859:DEBUG [middleware:source-files]: Requesting /base/node_modules/karma-jasmine/lib/adapter.js?7a813cc290d592e664331c573a1a796192cdd1ad /
18 03 2017 15:45:23.859:DEBUG [middleware:source-files]: Fetching /path/to/app/node_modules/karma-jasmine/lib/adapter.js
18 03 2017 15:45:23.860:DEBUG [middleware:source-files]: Requesting /base/node_modules/karma-ng-scenario/lib/angular-scenario.js?df746e558e332348ff12e0f08ddae4697abef3cd /
18 03 2017 15:45:23.860:DEBUG [middleware:source-files]: Fetching /path/to/app/node_modules/karma-ng-scenario/lib/angular-scenario.js
18 03 2017 15:45:23.861:DEBUG [web-server]: serving (cached): /path/to/app/node_modules/karma-jasmine/lib/boot.js
18 03 2017 15:45:23.861:DEBUG [web-server]: serving (cached): /path/to/app/node_modules/karma-jasmine/lib/adapter.js
18 03 2017 15:45:23.862:DEBUG [web-server]: serving (cached): /path/to/app/node_modules/karma-ng-scenario/lib/angular-scenario.js
18 03 2017 15:45:23.872:DEBUG [middleware:source-files]: Requesting /base/bower_components/angular-mocks/angular-mocks.js?428e663e720ed137f3931dc4e4079d00eb339620 /
18 03 2017 15:45:23.872:DEBUG [middleware:source-files]: Fetching /path/to/app/bower_components/angular-mocks/angular-mocks.js
18 03 2017 15:45:23.873:DEBUG [middleware:source-files]: Requesting /base/bower_components/angular/angular.js?367ccb6484896d3b163b691390f735bfca5cf17e /
18 03 2017 15:45:23.873:DEBUG [middleware:source-files]: Fetching /path/to/app/bower_components/angular/angular.js
18 03 2017 15:45:23.873:DEBUG [middleware:source-files]: Requesting /base/node_modules/karma-ng-scenario/lib/adapter.js?88d12e473235d74e75f0db6cbd01396f5aa58e7b /
18 03 2017 15:45:23.874:DEBUG [middleware:source-files]: Fetching /path/to/app/node_modules/karma-ng-scenario/lib/adapter.js
18 03 2017 15:45:23.875:DEBUG [web-server]: serving (cached): /path/to/app/bower_components/angular-mocks/angular-mocks.js
18 03 2017 15:45:23.877:DEBUG [web-server]: serving (cached): /path/to/app/bower_components/angular/angular.js
18 03 2017 15:45:23.890:DEBUG [web-server]: serving (cached): /path/to/app/node_modules/karma-ng-scenario/lib/adapter.js
18 03 2017 15:45:23.892:DEBUG [web-server]: serving: /path/to/app/node_modules/karma/static/context.js
Chrome 57.0.2987 (Mac OS X 10.12.3) ERROR
Uncaught TypeError: window.angular.$$csp is not a function
at bower_components/angular/angular.js:33345
18 03 2017 15:45:24.094:DEBUG [karma]: Run complete, exiting.
18 03 2017 15:45:24.094:DEBUG [launcher]: Disconnecting all browsers
18 03 2017 15:45:24.452:DEBUG [launcher]: Process Chrome exited with code 0
18 03 2017 15:45:24.452:DEBUG [temp-dir]: Cleaning temp dir /var/folders/84/81q1wl5d5k58flxbpcgqq78w0000gn/T/karma-67345543
18 03 2017 15:45:24.482:DEBUG [launcher]: Finished all browsers
phantomjs 日志输出
> karma start
18 03 2017 15:43:45.349:DEBUG [config]: autoWatch set to false, because of singleRun
18 03 2017 15:43:45.354:DEBUG [plugin]: Loading karma-* from /path/to/app/node_modules
18 03 2017 15:43:45.357:DEBUG [plugin]: Loading plugin /path/to/app/node_modules/karma-babel-preprocessor.
18 03 2017 15:43:45.735:DEBUG [plugin]: Loading plugin /path/to/app/node_modules/karma-chrome-launcher.
18 03 2017 15:43:45.739:DEBUG [plugin]: Loading plugin /path/to/app/node_modules/karma-jasmine.
18 03 2017 15:43:45.739:DEBUG [plugin]: Loading plugin /path/to/app/node_modules/karma-ng-html2js-preprocessor.
18 03 2017 15:43:45.740:DEBUG [plugin]: Loading plugin /path/to/app/node_modules/karma-ng-scenario.
18 03 2017 15:43:45.741:DEBUG [plugin]: Loading plugin /path/to/app/node_modules/karma-phantomjs-launcher.
18 03 2017 15:43:45.769:DEBUG [plugin]: Loading plugin /path/to/app/node_modules/karma-wiredep.
18 03 2017 15:43:45.880:DEBUG [web-server]: Instantiating middleware
18 03 2017 15:43:45.969:INFO [karma]: Karma v1.5.0 server started at http://0.0.0.0:9876/
18 03 2017 15:43:45.970:INFO [launcher]: Launching browser PhantomJS with unlimited concurrency
18 03 2017 15:43:45.980:INFO [launcher]: Starting browser PhantomJS
18 03 2017 15:43:45.981:DEBUG [temp-dir]: Creating temp dir at /var/folders/84/81q1wl5d5k58flxbpcgqq78w0000gn/T/karma-75656583
18 03 2017 15:43:45.984:DEBUG [launcher]: /path/to/app/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs /var/folders/84/81q1wl5d5k58flxbpcgqq78w0000gn/T/karma-75656583/capture.js
18 03 2017 15:43:47.236:DEBUG [web-server]: serving: /path/to/app/node_modules/karma/static/client.html
18 03 2017 15:43:47.246:DEBUG [web-server]: serving: /path/to/app/node_modules/karma/static/karma.js
18 03 2017 15:43:47.290:DEBUG [karma]: A browser has connected on socket qu27-ez-B1uzsqMHAAAA
18 03 2017 15:43:47.295:DEBUG [web-server]: upgrade /socket.io/?EIO=3&transport=websocket&sid=qu27-ez-B1uzsqMHAAAA
18 03 2017 15:43:47.330:INFO [PhantomJS 2.1.1 (Mac OS X 0.0.0)]: Connected on socket qu27-ez-B1uzsqMHAAAA with id 75656583
18 03 2017 15:43:47.331:DEBUG [launcher]: PhantomJS (id 75656583) captured in 1.361 secs
18 03 2017 15:43:47.334:DEBUG [phantomjs.launcher]:
18 03 2017 15:43:47.336:DEBUG [middleware:karma]: custom files null null null
18 03 2017 15:43:47.336:DEBUG [middleware:karma]: Serving static request /context.html
18 03 2017 15:43:47.337:DEBUG [web-server]: serving: /path/to/app/node_modules/karma/static/context.html
18 03 2017 15:43:47.340:DEBUG [middleware:source-files]: Requesting /base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js?916005cc407925f4764668d61d04888d59258f5d /
18 03 2017 15:43:47.340:DEBUG [middleware:source-files]: Fetching /path/to/app/node_modules/jasmine-core/lib/jasmine-core/jasmine.js
18 03 2017 15:43:47.341:DEBUG [web-server]: serving (cached): /path/to/app/node_modules/jasmine-core/lib/jasmine-core/jasmine.js
18 03 2017 15:43:47.342:DEBUG [middleware:source-files]: Requesting /base/bower_components/angular/angular.js?367ccb6484896d3b163b691390f735bfca5cf17e /
18 03 2017 15:43:47.342:DEBUG [middleware:source-files]: Fetching /path/to/app/bower_components/angular/angular.js
18 03 2017 15:43:47.342:DEBUG [middleware:source-files]: Requesting /base/node_modules/karma-jasmine/lib/boot.js?945a38bf4e45ad2770eb94868231905a04a0bd3e /
18 03 2017 15:43:47.343:DEBUG [middleware:source-files]: Fetching /path/to/app/node_modules/karma-jasmine/lib/boot.js
18 03 2017 15:43:47.343:DEBUG [middleware:source-files]: Requesting /base/node_modules/karma-jasmine/lib/adapter.js?7a813cc290d592e664331c573a1a796192cdd1ad /
18 03 2017 15:43:47.343:DEBUG [middleware:source-files]: Fetching /path/to/app/node_modules/karma-jasmine/lib/adapter.js
18 03 2017 15:43:47.343:DEBUG [middleware:source-files]: Requesting /base/node_modules/karma-ng-scenario/lib/angular-scenario.js?df746e558e332348ff12e0f08ddae4697abef3cd /
18 03 2017 15:43:47.343:DEBUG [middleware:source-files]: Fetching /path/to/app/node_modules/karma-ng-scenario/lib/angular-scenario.js
18 03 2017 15:43:47.343:DEBUG [middleware:source-files]: Requesting /base/node_modules/karma-ng-scenario/lib/adapter.js?88d12e473235d74e75f0db6cbd01396f5aa58e7b /
18 03 2017 15:43:47.343:DEBUG [middleware:source-files]: Fetching /path/to/app/node_modules/karma-ng-scenario/lib/adapter.js
18 03 2017 15:43:47.344:DEBUG [web-server]: serving (cached): /path/to/app/bower_components/angular/angular.js
18 03 2017 15:43:47.353:DEBUG [web-server]: serving (cached): /path/to/app/node_modules/karma-jasmine/lib/boot.js
18 03 2017 15:43:47.353:DEBUG [web-server]: serving (cached): /path/to/app/node_modules/karma-jasmine/lib/adapter.js
18 03 2017 15:43:47.353:DEBUG [web-server]: serving (cached): /path/to/app/node_modules/karma-ng-scenario/lib/angular-scenario.js
18 03 2017 15:43:47.360:DEBUG [web-server]: serving (cached): /path/to/app/node_modules/karma-ng-scenario/lib/adapter.js
18 03 2017 15:43:47.361:DEBUG [web-server]: serving: /path/to/app/node_modules/karma/static/context.js
18 03 2017 15:43:47.362:DEBUG [middleware:source-files]: Requesting /base/bower_components/angular-mocks/angular-mocks.js?428e663e720ed137f3931dc4e4079d00eb339620 /
18 03 2017 15:43:47.362:DEBUG [middleware:source-files]: Fetching /path/to/app/bower_components/angular-mocks/angular-mocks.js
18 03 2017 15:43:47.364:DEBUG [web-server]: serving (cached): /path/to/app/bower_components/angular-mocks/angular-mocks.js
18 03 2017 15:43:47.440:DEBUG [phantomjs.launcher]: WARNING: Tried to load angular more than once.
18 03 2017 15:43:47.441:DEBUG [phantomjs.launcher]: TypeError: undefined is not a constructor (evaluating 'window.angular.$$csp()')
18 03 2017 15:43:47.441:DEBUG [phantomjs.launcher]: http://localhost:9876/base/bower_components/angular/angular.js?367ccb6484896d3b163b691390f735bfca5cf17e:33345 in global code
18 03 2017 15:43:47.443:DEBUG [phantomjs.launcher]: TypeError: undefined is not a constructor (evaluating 'angular.module('ngAnimateMock', ['ng'])
.info({ angularVersion: '1.6.3' })')
http://localhost:9876/base/bower_components/angular-mocks/angular-mocks.js?428e663e720ed137f3931dc4e4079d00eb339620:800
PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
TypeError: undefined is not a constructor (evaluating 'window.angular.$$csp()')
at bower_components/angular/angular.js:33345
18 03 2017 15:43:47.453:DEBUG [karma]: Run complete, exiting.
18 03 2017 15:43:47.454:DEBUG [launcher]: Disconnecting all browsers
PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
TypeError: undefined is not a constructor (evaluating 'angular.module('ngAnimateMock', ['ng'])
.info({ angularVersion: '1.6.3' })')
at bower_components/angular-mocks/angular-mocks.js:800
18 03 2017 15:43:47.456:DEBUG [karma]: Run complete, exiting.
18 03 2017 15:43:47.456:DEBUG [launcher]: Disconnecting all browsers
18 03 2017 15:43:47.471:DEBUG [launcher]: Process PhantomJS exited with code 0
18 03 2017 15:43:47.471:DEBUG [temp-dir]: Cleaning temp dir /var/folders/84/81q1wl5d5k58flxbpcgqq78w0000gn/T/karma-75656583
18 03 2017 15:43:47.478:DEBUG [launcher]: Finished all browsers
我最终将问题追溯到 karma-ng-scenario
but was not able to resolve it - if I removed it then I was able to load angular without any errors however objects like browser
were not available in the tests. I noticed in the README they recommend using Protractor 以对新项目进行端到端测试,因此我最终将它与 Karma 一起实施以进行单元测试。
我正在尝试使用 Karma and Jasmine, as well as karma-wiredep
为 Angular 1.6 应用程序编写测试以加载 Bower 依赖项 - 目前它只包含 Angular 1.6.3。当我尝试 运行 karma start
我能够看到依赖项加载但是 Chrome 和 PhantomJS 即使没有加载我的 application/test 代码也会失败所以我认为问题出在Karma 配置 - 日志确实显示 angular.js 正在加载。两者的错误与 PhantomJS 报告 WARNING: Tried to load angular more than once.
相似,但我没有在日志中看到这种情况。 Karma 的配置方式有问题吗?
Chrome 57.0.2987 (Mac OS X 10.12.3) ERROR Uncaught TypeError: window.angular.$$csp is not a function at bower_components/angular/angular.js:33345
PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR TypeError: undefined is not a constructor (evaluating 'window.angular.$$csp()') at bower_components/angular/angular.js:33345
PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR TypeError: undefined is not a constructor (evaluating 'angular.module('ngAnimateMock', ['ng']) .info({ angularVersion: '1.6.3' })') at bower_components/angular-mocks/angular-mocks.js:800
karma.conf.js
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['wiredep', 'ng-scenario', 'jasmine'],
//you can configure wiredep from here (optional)
wiredep: {
dependencies: true, // default: true
devDependencies: true, // default: false
},
// list of files / patterns to load in the browser
files: [
],
// list of files to exclude
exclude: [
],
// 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,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_DEBUG,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
// browsers: ['Chrome', 'Firefox', 'Safari', 'PhantomJS', 'IE'],
browsers: ['Chrome'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: true,
// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity
})
}
bower.json
{
"name": "app-name",
"main": "script.js",
"version": "0.0.1",
"homepage": "",
"authors": [],
"description": "",
"keywords": [],
"license": "",
"ignore": [],
"dependencies": {
"angular": "^1.6.3"
},
"devDependencies": {
"angular-mocks": "~1.6.x"
}
}
chrome 日志输出
> karma start karma.conf.js
18 03 2017 15:45:22.180:DEBUG [config]: autoWatch set to false, because of singleRun
18 03 2017 15:45:22.185:DEBUG [plugin]: Loading karma-* from /path/to/app/node_modules
18 03 2017 15:45:22.187:DEBUG [plugin]: Loading plugin /path/to/app/node_modules/karma-babel-preprocessor.
18 03 2017 15:45:22.550:DEBUG [plugin]: Loading plugin /path/to/app/node_modules/karma-chrome-launcher.
18 03 2017 15:45:22.554:DEBUG [plugin]: Loading plugin /path/to/app/node_modules/karma-jasmine.
18 03 2017 15:45:22.555:DEBUG [plugin]: Loading plugin /path/to/app/node_modules/karma-ng-html2js-preprocessor.
18 03 2017 15:45:22.556:DEBUG [plugin]: Loading plugin /path/to/app/node_modules/karma-ng-scenario.
18 03 2017 15:45:22.556:DEBUG [plugin]: Loading plugin /path/to/app/node_modules/karma-phantomjs-launcher.
18 03 2017 15:45:22.586:DEBUG [plugin]: Loading plugin /path/to/app/node_modules/karma-wiredep.
18 03 2017 15:45:22.686:DEBUG [web-server]: Instantiating middleware
18 03 2017 15:45:22.764:INFO [karma]: Karma v1.5.0 server started at http://0.0.0.0:9876/
18 03 2017 15:45:22.764:INFO [launcher]: Launching browser Chrome with unlimited concurrency
18 03 2017 15:45:22.779:INFO [launcher]: Starting browser Chrome
18 03 2017 15:45:22.780:DEBUG [temp-dir]: Creating temp dir at /var/folders/84/81q1wl5d5k58flxbpcgqq78w0000gn/T/karma-67345543
18 03 2017 15:45:22.780:DEBUG [launcher]: /Applications/Google Chrome.app/Contents/MacOS/Google Chrome --user-data-dir=/var/folders/84/81q1wl5d5k58flxbpcgqq78w0000gn/T/karma-67345543 --no-default-browser-check --no-first-run --disable-default-apps --disable-popup-blocking --disable-translate --disable-background-timer-throttling --disable-device-discovery-notifications http://localhost:9876/?id=67345543
18 03 2017 15:45:23.538:DEBUG [web-server]: serving: /path/to/app/node_modules/karma/static/client.html
18 03 2017 15:45:23.557:DEBUG [web-server]: serving: /path/to/app/node_modules/karma/static/karma.js
18 03 2017 15:45:23.751:DEBUG [karma]: A browser has connected on socket 358rR6cCQQIt8Y11AAAA
18 03 2017 15:45:23.753:DEBUG [web-server]: serving: /path/to/app/node_modules/karma/static/favicon.ico
18 03 2017 15:45:23.762:DEBUG [web-server]: upgrade /socket.io/?EIO=3&transport=websocket&sid=358rR6cCQQIt8Y11AAAA
18 03 2017 15:45:23.808:INFO [Chrome 57.0.2987 (Mac OS X 10.12.3)]: Connected on socket 358rR6cCQQIt8Y11AAAA with id 67345543
18 03 2017 15:45:23.809:DEBUG [launcher]: Chrome (id 67345543) captured in 1.045 secs
18 03 2017 15:45:23.837:DEBUG [middleware:karma]: custom files null null null
18 03 2017 15:45:23.837:DEBUG [middleware:karma]: Serving static request /context.html
18 03 2017 15:45:23.839:DEBUG [web-server]: serving: /path/to/app/node_modules/karma/static/context.html
18 03 2017 15:45:23.856:DEBUG [middleware:source-files]: Requesting /base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js?916005cc407925f4764668d61d04888d59258f5d /
18 03 2017 15:45:23.856:DEBUG [middleware:source-files]: Fetching /path/to/app/node_modules/jasmine-core/lib/jasmine-core/jasmine.js
18 03 2017 15:45:23.857:DEBUG [web-server]: serving (cached): /path/to/app/node_modules/jasmine-core/lib/jasmine-core/jasmine.js
18 03 2017 15:45:23.859:DEBUG [middleware:source-files]: Requesting /base/node_modules/karma-jasmine/lib/boot.js?945a38bf4e45ad2770eb94868231905a04a0bd3e /
18 03 2017 15:45:23.859:DEBUG [middleware:source-files]: Fetching /path/to/app/node_modules/karma-jasmine/lib/boot.js
18 03 2017 15:45:23.859:DEBUG [middleware:source-files]: Requesting /base/node_modules/karma-jasmine/lib/adapter.js?7a813cc290d592e664331c573a1a796192cdd1ad /
18 03 2017 15:45:23.859:DEBUG [middleware:source-files]: Fetching /path/to/app/node_modules/karma-jasmine/lib/adapter.js
18 03 2017 15:45:23.860:DEBUG [middleware:source-files]: Requesting /base/node_modules/karma-ng-scenario/lib/angular-scenario.js?df746e558e332348ff12e0f08ddae4697abef3cd /
18 03 2017 15:45:23.860:DEBUG [middleware:source-files]: Fetching /path/to/app/node_modules/karma-ng-scenario/lib/angular-scenario.js
18 03 2017 15:45:23.861:DEBUG [web-server]: serving (cached): /path/to/app/node_modules/karma-jasmine/lib/boot.js
18 03 2017 15:45:23.861:DEBUG [web-server]: serving (cached): /path/to/app/node_modules/karma-jasmine/lib/adapter.js
18 03 2017 15:45:23.862:DEBUG [web-server]: serving (cached): /path/to/app/node_modules/karma-ng-scenario/lib/angular-scenario.js
18 03 2017 15:45:23.872:DEBUG [middleware:source-files]: Requesting /base/bower_components/angular-mocks/angular-mocks.js?428e663e720ed137f3931dc4e4079d00eb339620 /
18 03 2017 15:45:23.872:DEBUG [middleware:source-files]: Fetching /path/to/app/bower_components/angular-mocks/angular-mocks.js
18 03 2017 15:45:23.873:DEBUG [middleware:source-files]: Requesting /base/bower_components/angular/angular.js?367ccb6484896d3b163b691390f735bfca5cf17e /
18 03 2017 15:45:23.873:DEBUG [middleware:source-files]: Fetching /path/to/app/bower_components/angular/angular.js
18 03 2017 15:45:23.873:DEBUG [middleware:source-files]: Requesting /base/node_modules/karma-ng-scenario/lib/adapter.js?88d12e473235d74e75f0db6cbd01396f5aa58e7b /
18 03 2017 15:45:23.874:DEBUG [middleware:source-files]: Fetching /path/to/app/node_modules/karma-ng-scenario/lib/adapter.js
18 03 2017 15:45:23.875:DEBUG [web-server]: serving (cached): /path/to/app/bower_components/angular-mocks/angular-mocks.js
18 03 2017 15:45:23.877:DEBUG [web-server]: serving (cached): /path/to/app/bower_components/angular/angular.js
18 03 2017 15:45:23.890:DEBUG [web-server]: serving (cached): /path/to/app/node_modules/karma-ng-scenario/lib/adapter.js
18 03 2017 15:45:23.892:DEBUG [web-server]: serving: /path/to/app/node_modules/karma/static/context.js
Chrome 57.0.2987 (Mac OS X 10.12.3) ERROR
Uncaught TypeError: window.angular.$$csp is not a function
at bower_components/angular/angular.js:33345
18 03 2017 15:45:24.094:DEBUG [karma]: Run complete, exiting.
18 03 2017 15:45:24.094:DEBUG [launcher]: Disconnecting all browsers
18 03 2017 15:45:24.452:DEBUG [launcher]: Process Chrome exited with code 0
18 03 2017 15:45:24.452:DEBUG [temp-dir]: Cleaning temp dir /var/folders/84/81q1wl5d5k58flxbpcgqq78w0000gn/T/karma-67345543
18 03 2017 15:45:24.482:DEBUG [launcher]: Finished all browsers
phantomjs 日志输出
> karma start
18 03 2017 15:43:45.349:DEBUG [config]: autoWatch set to false, because of singleRun
18 03 2017 15:43:45.354:DEBUG [plugin]: Loading karma-* from /path/to/app/node_modules
18 03 2017 15:43:45.357:DEBUG [plugin]: Loading plugin /path/to/app/node_modules/karma-babel-preprocessor.
18 03 2017 15:43:45.735:DEBUG [plugin]: Loading plugin /path/to/app/node_modules/karma-chrome-launcher.
18 03 2017 15:43:45.739:DEBUG [plugin]: Loading plugin /path/to/app/node_modules/karma-jasmine.
18 03 2017 15:43:45.739:DEBUG [plugin]: Loading plugin /path/to/app/node_modules/karma-ng-html2js-preprocessor.
18 03 2017 15:43:45.740:DEBUG [plugin]: Loading plugin /path/to/app/node_modules/karma-ng-scenario.
18 03 2017 15:43:45.741:DEBUG [plugin]: Loading plugin /path/to/app/node_modules/karma-phantomjs-launcher.
18 03 2017 15:43:45.769:DEBUG [plugin]: Loading plugin /path/to/app/node_modules/karma-wiredep.
18 03 2017 15:43:45.880:DEBUG [web-server]: Instantiating middleware
18 03 2017 15:43:45.969:INFO [karma]: Karma v1.5.0 server started at http://0.0.0.0:9876/
18 03 2017 15:43:45.970:INFO [launcher]: Launching browser PhantomJS with unlimited concurrency
18 03 2017 15:43:45.980:INFO [launcher]: Starting browser PhantomJS
18 03 2017 15:43:45.981:DEBUG [temp-dir]: Creating temp dir at /var/folders/84/81q1wl5d5k58flxbpcgqq78w0000gn/T/karma-75656583
18 03 2017 15:43:45.984:DEBUG [launcher]: /path/to/app/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs /var/folders/84/81q1wl5d5k58flxbpcgqq78w0000gn/T/karma-75656583/capture.js
18 03 2017 15:43:47.236:DEBUG [web-server]: serving: /path/to/app/node_modules/karma/static/client.html
18 03 2017 15:43:47.246:DEBUG [web-server]: serving: /path/to/app/node_modules/karma/static/karma.js
18 03 2017 15:43:47.290:DEBUG [karma]: A browser has connected on socket qu27-ez-B1uzsqMHAAAA
18 03 2017 15:43:47.295:DEBUG [web-server]: upgrade /socket.io/?EIO=3&transport=websocket&sid=qu27-ez-B1uzsqMHAAAA
18 03 2017 15:43:47.330:INFO [PhantomJS 2.1.1 (Mac OS X 0.0.0)]: Connected on socket qu27-ez-B1uzsqMHAAAA with id 75656583
18 03 2017 15:43:47.331:DEBUG [launcher]: PhantomJS (id 75656583) captured in 1.361 secs
18 03 2017 15:43:47.334:DEBUG [phantomjs.launcher]:
18 03 2017 15:43:47.336:DEBUG [middleware:karma]: custom files null null null
18 03 2017 15:43:47.336:DEBUG [middleware:karma]: Serving static request /context.html
18 03 2017 15:43:47.337:DEBUG [web-server]: serving: /path/to/app/node_modules/karma/static/context.html
18 03 2017 15:43:47.340:DEBUG [middleware:source-files]: Requesting /base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js?916005cc407925f4764668d61d04888d59258f5d /
18 03 2017 15:43:47.340:DEBUG [middleware:source-files]: Fetching /path/to/app/node_modules/jasmine-core/lib/jasmine-core/jasmine.js
18 03 2017 15:43:47.341:DEBUG [web-server]: serving (cached): /path/to/app/node_modules/jasmine-core/lib/jasmine-core/jasmine.js
18 03 2017 15:43:47.342:DEBUG [middleware:source-files]: Requesting /base/bower_components/angular/angular.js?367ccb6484896d3b163b691390f735bfca5cf17e /
18 03 2017 15:43:47.342:DEBUG [middleware:source-files]: Fetching /path/to/app/bower_components/angular/angular.js
18 03 2017 15:43:47.342:DEBUG [middleware:source-files]: Requesting /base/node_modules/karma-jasmine/lib/boot.js?945a38bf4e45ad2770eb94868231905a04a0bd3e /
18 03 2017 15:43:47.343:DEBUG [middleware:source-files]: Fetching /path/to/app/node_modules/karma-jasmine/lib/boot.js
18 03 2017 15:43:47.343:DEBUG [middleware:source-files]: Requesting /base/node_modules/karma-jasmine/lib/adapter.js?7a813cc290d592e664331c573a1a796192cdd1ad /
18 03 2017 15:43:47.343:DEBUG [middleware:source-files]: Fetching /path/to/app/node_modules/karma-jasmine/lib/adapter.js
18 03 2017 15:43:47.343:DEBUG [middleware:source-files]: Requesting /base/node_modules/karma-ng-scenario/lib/angular-scenario.js?df746e558e332348ff12e0f08ddae4697abef3cd /
18 03 2017 15:43:47.343:DEBUG [middleware:source-files]: Fetching /path/to/app/node_modules/karma-ng-scenario/lib/angular-scenario.js
18 03 2017 15:43:47.343:DEBUG [middleware:source-files]: Requesting /base/node_modules/karma-ng-scenario/lib/adapter.js?88d12e473235d74e75f0db6cbd01396f5aa58e7b /
18 03 2017 15:43:47.343:DEBUG [middleware:source-files]: Fetching /path/to/app/node_modules/karma-ng-scenario/lib/adapter.js
18 03 2017 15:43:47.344:DEBUG [web-server]: serving (cached): /path/to/app/bower_components/angular/angular.js
18 03 2017 15:43:47.353:DEBUG [web-server]: serving (cached): /path/to/app/node_modules/karma-jasmine/lib/boot.js
18 03 2017 15:43:47.353:DEBUG [web-server]: serving (cached): /path/to/app/node_modules/karma-jasmine/lib/adapter.js
18 03 2017 15:43:47.353:DEBUG [web-server]: serving (cached): /path/to/app/node_modules/karma-ng-scenario/lib/angular-scenario.js
18 03 2017 15:43:47.360:DEBUG [web-server]: serving (cached): /path/to/app/node_modules/karma-ng-scenario/lib/adapter.js
18 03 2017 15:43:47.361:DEBUG [web-server]: serving: /path/to/app/node_modules/karma/static/context.js
18 03 2017 15:43:47.362:DEBUG [middleware:source-files]: Requesting /base/bower_components/angular-mocks/angular-mocks.js?428e663e720ed137f3931dc4e4079d00eb339620 /
18 03 2017 15:43:47.362:DEBUG [middleware:source-files]: Fetching /path/to/app/bower_components/angular-mocks/angular-mocks.js
18 03 2017 15:43:47.364:DEBUG [web-server]: serving (cached): /path/to/app/bower_components/angular-mocks/angular-mocks.js
18 03 2017 15:43:47.440:DEBUG [phantomjs.launcher]: WARNING: Tried to load angular more than once.
18 03 2017 15:43:47.441:DEBUG [phantomjs.launcher]: TypeError: undefined is not a constructor (evaluating 'window.angular.$$csp()')
18 03 2017 15:43:47.441:DEBUG [phantomjs.launcher]: http://localhost:9876/base/bower_components/angular/angular.js?367ccb6484896d3b163b691390f735bfca5cf17e:33345 in global code
18 03 2017 15:43:47.443:DEBUG [phantomjs.launcher]: TypeError: undefined is not a constructor (evaluating 'angular.module('ngAnimateMock', ['ng'])
.info({ angularVersion: '1.6.3' })')
http://localhost:9876/base/bower_components/angular-mocks/angular-mocks.js?428e663e720ed137f3931dc4e4079d00eb339620:800
PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
TypeError: undefined is not a constructor (evaluating 'window.angular.$$csp()')
at bower_components/angular/angular.js:33345
18 03 2017 15:43:47.453:DEBUG [karma]: Run complete, exiting.
18 03 2017 15:43:47.454:DEBUG [launcher]: Disconnecting all browsers
PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
TypeError: undefined is not a constructor (evaluating 'angular.module('ngAnimateMock', ['ng'])
.info({ angularVersion: '1.6.3' })')
at bower_components/angular-mocks/angular-mocks.js:800
18 03 2017 15:43:47.456:DEBUG [karma]: Run complete, exiting.
18 03 2017 15:43:47.456:DEBUG [launcher]: Disconnecting all browsers
18 03 2017 15:43:47.471:DEBUG [launcher]: Process PhantomJS exited with code 0
18 03 2017 15:43:47.471:DEBUG [temp-dir]: Cleaning temp dir /var/folders/84/81q1wl5d5k58flxbpcgqq78w0000gn/T/karma-75656583
18 03 2017 15:43:47.478:DEBUG [launcher]: Finished all browsers
我最终将问题追溯到 karma-ng-scenario
but was not able to resolve it - if I removed it then I was able to load angular without any errors however objects like browser
were not available in the tests. I noticed in the README they recommend using Protractor 以对新项目进行端到端测试,因此我最终将它与 Karma 一起实施以进行单元测试。