It runs very well with Chrome (karma-chrome-launcher), but I can not configure it to run with PhantomJS (karma-phantomjs-launcher). I get following error:
ng test --browsers PhantomJS --single-run --code-coverage
10% building modules 1/1 modules 0 active22 12 2017 09:57:32.489:INFO [karma]: Karma v1.7.1 server started at http://0.0.0.0:9876/
22 12 2017 09:57:32.489:INFO [launcher]: Launching browser PhantomJS with unlimited concurrency
22 12 2017 09:57:32.505:INFO [launcher]: Starting browser PhantomJS
10% building modules 2/3 modules 1 active ...frontend\src\polyfills.ts(node:10452) DeprecationWarning: loaderUtils.parseQuery() received a non-string value which can be problematic, see https://github.com/webpack/loader-utils/issues/56
parseQuery() will be replaced with getOptions() in the next major version of loader-utils.
22 12 2017 09:57:55.991:INFO [PhantomJS 2.1.1 (Windows 7 0.0.0)]: Connected on socket s8C0IxgvYAI_EOalAAAA with id 95541114
PhantomJS 2.1.1 (Windows 7 0.0.0) ERROR
SyntaxError: Use of reserved word 'class'
at http://localhost:9876/_karma_webpack_/vendor.bundle.js:1489
PhantomJS 2.1.1 (Windows 7 0.0.0) ERROR
SyntaxError: Use of reserved word 'class'
at http://localhost:9876/_karma_webpack_/vendor.bundle.js:1489
I'm not the maintainer so I can't speak with authority, but I will mention two things:
PhantomJS is not as modern a browser, so you might have the right amount of babel transforms in your build -> test pipeline.
Better yet... don't use PhantomJS at all (it's bad and it's not gonna get maintained anymore). So I'd recommend using Jest and it's typed wrapper friend TsJest which is way faster than Karma, easier to set up than Karma, and more reliable than PhantomJS because it runs the tests in NodeJS (I believe).
It runs very well with Chrome (karma-chrome-launcher), but I can not configure it to run with PhantomJS (karma-phantomjs-launcher). I get following error:
10% building modules 1/1 modules 0 active22 12 2017 09:57:32.489:INFO [karma]: Karma v1.7.1 server started at http://0.0.0.0:9876/ 22 12 2017 09:57:32.489:INFO [launcher]: Launching browser PhantomJS with unlimited concurrency 22 12 2017 09:57:32.505:INFO [launcher]: Starting browser PhantomJS 10% building modules 2/3 modules 1 active ...frontend\src\polyfills.ts(node:10452) DeprecationWarning: loaderUtils.parseQuery() received a non-string value which can be problematic, see https://github.com/webpack/loader-utils/issues/56 parseQuery() will be replaced with getOptions() in the next major version of loader-utils. 22 12 2017 09:57:55.991:INFO [PhantomJS 2.1.1 (Windows 7 0.0.0)]: Connected on socket s8C0IxgvYAI_EOalAAAA with id 95541114 PhantomJS 2.1.1 (Windows 7 0.0.0) ERROR SyntaxError: Use of reserved word 'class' at http://localhost:9876/_karma_webpack_/vendor.bundle.js:1489 PhantomJS 2.1.1 (Windows 7 0.0.0) ERROR SyntaxError: Use of reserved word 'class' at http://localhost:9876/_karma_webpack_/vendor.bundle.js:1489
PhantomJS 2.1.1 (Windows 7 0.0.0) ERROR SyntaxError: Use of reserved word 'class' at http://localhost:9876/_karma_webpack_/vendor.bundle.js:1489 PhantomJS 2.1.1 (Windows 7 0.0.0) ERROR SyntaxError: Use of reserved word 'class' at http://localhost:9876/_karma_webpack_/vendor.bundle.js:1489
PhantomJS 2.1.1 (Windows 7 0.0.0) ERROR TypeError: undefined is not an object (evaluating 'modules[moduleId].call') at http://localhost:9876/_karma_webpack_/inline.bundle.js:55 PhantomJS 2.1.1 (Windows 7 0.0.0) ERROR TypeError: undefined is not an object (evaluating 'modules[moduleId].call') at http://localhost:9876/_karma_webpack_/inline.bundle.js:55
PhantomJS 2.1.1 (Windows 7 0.0.0) ERROR TypeError: undefined is not an object (evaluating 'modules[moduleId].call') at http://localhost:9876/_karma_webpack_/inline.bundle.js:55 PhantomJS 2.1.1 (Windows 7 0.0.0) ERROR TypeError: undefined is not an object (evaluating 'modules[moduleId].call') at http://localhost:9876/_karma_webpack_/inline.bundle.js:55
I have following dependencies in package.json: "dependencies": { "@angular-devkit/schematics": "0.0.34", "@angular/animations": "~4.4.6", "@angular/cdk": "2.0.0-beta.12", "@angular/common": "~4.4.6", "@angular/compiler": "~4.4.6", "@angular/core": "~4.4.6", "@angular/flex-layout": "2.0.0-beta.9", "@angular/forms": "~4.4.6", "@angular/http": "~4.4.6", "@angular/material": "2.0.0-beta.12", "@angular/platform-browser": "~4.4.6", "@angular/platform-browser-dynamic": "~4.4.6", "@angular/router": "~4.4.6", "@ngx-translate/core": "~8.0.0", "core-js": "~2.4.1", "fluent-ffmpeg": "~2.1.2", "intl": "~1.2.5", "lodash": "~4.17.4", "md2": "0.0.29", "ng2-google-charts": "~3.3.0", "rxjs": "~5.5.3", "zone.js": "~0.8.18" }, "devDependencies": { "@angular/cli": "1.4.9", "@angular/compiler-cli": "~4.4.6", "@angular/language-service": "~4.4.6", "@types/jasmine": "~2.5.53", "@types/jasminewd2": "~2.0.2", "@types/node": "~6.0.60", "codelyzer": "~3.1.1", "jasmine-core": "~2.6.2", "jasmine-spec-reporter": "~4.1.0", "karma": "~1.7.0", "karma-chrome-launcher": "~2.1.1", "karma-cli": "~1.0.1", "karma-coverage-istanbul-reporter": "~1.2.1", "karma-jasmine": "~1.1.1", "karma-jasmine-html-reporter": "~0.2.2", "karma-junit-reporter": "~1.2.0", "karma-phantomjs-launcher": "~1.0.4", "phantomjs-prebuilt": "~2.1.16", "protractor": "~5.1.2", "ts-node": "~3.2.0", "tslint": "~5.7.0", "typescript": "~2.4.2" }