I just created a basic Angular project and had the same (or similar) issue with PhantomJS integration.
PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
SyntaxError: Unexpected token 'const'
at webpack:///src/app/app.component.ts:1:0 <- src/test.ts:63184
Our team got it to work and here's what we tossed in our documentation:
PhantomJS is a headless (aka, no GUI) browser that can be used for automated testing.
Currently, PhantomJS has a limitation in that it only supports the ES5 standard.
npm install -g phantomjs-prebuilt
npm install --save-dev karma-phantomjs-launcher
- in karma.conf.js
- add
require('karma-phantomjs-launcher')
to the plugins section
- add
PhantomJS
to the browsers
npm install --save intl
- in src/polyfill.ts
- add
import 'intl';
(uncomment at the bottom)
- add
import "core-js/client/shim";
to the Evergreen requirements section
- In src/tsconfig.spec.json (or whatever typescript config is used for tests)
Assuming all goes well, testing should work.
Some examples on how to trigger a test run:
ng test --browsers PhantomJS --singleRun true
./node_modules/karma/bin/karma start ./karma.conf.js --browsers PhantomJS --singleRun true
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…