【问题标题】:Supporting JS runtimes with PhantomJS使用 PhantomJS 支持 JS 运行时
【发布时间】:2018-01-20 13:52:41
【问题描述】:

这里是 PhantomJS 新手,尝试将 PhantomJS 与 Karma 一起使用,以便我可以在 Jenkins 上运行浏览器测试。

我在使用 PhantomJS 时遇到了这个明显的错误

PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
  SyntaxError: Expected an identifier but found 'handlePageRequest' instead
  at public/app.js:45

当像这样使用 let 变量声明时:

 let handlePageRequest = {};

如何让 PhantomJS 像最新版本的 Chrome 或 Mozilla 那样解释 JavaScript?

【问题讨论】:

    标签: javascript jenkins phantomjs karma-runner mocha-phantomjs


    【解决方案1】:

    我刚刚使用 Babel 优化和转译了我们的代码,现在我猜它可以正常工作了。

    这是我用来转译和优化的:

        gulp.task('bundle-prod', ['clean'], function (cb) {
    
          // this takes all the js files in public dir, except for those in public/lib
          // minifies them
          // concatenates them
          // then writes the concatenated file to app-production.js
          // so in production, all our angular.js javascript code is in one file
    
          pump([
              gulp.src(['public/**/*.js','!public/lib/**/*'], {}),
              babel({
                ignore: ['public/lib/**/*'],
                comments: false,
                minified: true,
                plugins: ['transform-remove-console'],
                presets: ['env']
              }),
              concat('public/dist/app-production.js'),
              gulp.dest('.')
            ],
            cb
          );
    
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-19
      • 2013-05-20
      • 1970-01-01
      • 1970-01-01
      • 2013-09-13
      • 1970-01-01
      • 1970-01-01
      • 2011-08-03
      相关资源
      最近更新 更多