PhantomJS for Angular 4

问题描述 投票:1回答:2

我热衷于使用gitlab的CI / CD设置我的项目。我试图在移动之前设置phantomJS测试:

  1. 我在现有的ng项目中运行了npm i -D phantomjs-prebuilt karma-phantomjs-launcher
  2. 我跑了npm i -s intl
  3. 我编辑了我的karma.conf.js文件,包括: require('karma-phantomjs-launcher'), //... browsers: ['Chrome', 'PhantonJS'],
  4. 我编辑了polyfills.js文件,取消注释: import 'core-js/es6/symbol'; import 'core-js/es6/object'; import 'core-js/es6/function'; import 'core-js/es6/parse-int'; import 'core-js/es6/parse-float'; import 'core-js/es6/number'; import 'core-js/es6/math'; import 'core-js/es6/string'; import 'core-js/es6/date'; import 'core-js/es6/array'; import 'core-js/es6/regexp'; import 'core-js/es6/map'; import 'core-js/es6/weak-map'; import 'core-js/es6/set'; //... import 'intl'; // Run `npm install --save intl`. /** * Need to import at least one locale-data with intl. */ import 'intl/locale-data/jsonp/en';

现在,我应该准备好接受我的考试...或者我想。但我得到:

ng test --browser PhantomJS --watch false

27 07 2017 17:36:52.088:INFO [PhantomJS 2.1.1 (Windows 8 0.0.0)]: Connected on socket dyKzQygLaKO5BjSRAAAA with id 32293
707
PhantomJS 2.1.1 (Windows 8 0.0.0) ERROR
  SyntaxError: Use of reserved word 'let' in strict mode
  at http://localhost:9876/_karma_webpack_/main.bundle.js:663
PhantomJS 2.1.1 (Windows 8 0.0.0) ERROR
  SyntaxError: Use of reserved word 'let' in strict mode
  at http://localhost:9876/_karma_webpack_/main.bundle.js:663

PhantomJS 2.1.1 (Windows 8 0.0.0) ERROR
  SyntaxError: Use of reserved word 'let' in strict mode
  at http://localhost:9876/_karma_webpack_/main.bundle.js:663
angular phantomjs
2个回答
1
投票

它确实与PhantomJS不支持ES2015有关。但是,您不必等待PhantomJS 2.5:您只需要安装和配置相应的polyfill。

通过遵循https://stackoverflow.com/a/42692195/1501787中的步骤,您可以使用ES2015运行PhantomJS而不会出现问题。我已经在Angular 4应用程序中进行了测试,它运行得很好。


0
投票

如果你使用tsconfig.json,你应该检查你的target: "es5"

PhantomJS还不了解ES2015,而let关键字是本规范的一部分。 PhantomJS团队plans to release在2.5版本中支持ES2015。

© www.soinside.com 2019 - 2024. All rights reserved.