ES6:测试在浏览器中通过,使用 phantomJS 失败,"Can't find variable: Reflect"

ES6: Tests pass in browser, fail with phantomJS, "Can't find variable: Reflect"

我正在为一个 js 库重写 ES6。

class VerbalExpression extends RegExp {
    // snipped for brevity
}

/**
 * Alias for the constructor
 * @return {VerbalExpression} new instance of VerbalExpression
 */
function instantiate() {
    return new VerbalExpression();
}

// UMD (Universal Module Definition)
// https://github.com/umdjs/umd
if (typeof module !== 'undefined' && module.exports) { // CommonJS
    module.exports = instantiate;
} else if (typeof define === 'function' && define.amd) { // AMD Module
    define('VerEx', [], () => VerbalExpression);
} else { // Browser
    this.VerEx = instantiate;
}

当我 运行 在浏览器中进行测试时,它们都通过了。

但是,当我 运行 在终端中进行测试时,出现错误。

❯ npm test

verbal-expressions@0.3.0 test /Users/shreyasminocha/dev/open source/JSVerbalExpressions
grunt test

Running "qunit:files" (qunit) task
Testing test/index.html FFFFFFFFFFFFFFFFFFFF
>> something
>> Message: Died on test #1 global code@file:///Users/shreyasminocha/dev/open%20source/JSVerbalExpressions/test/tests.js:7:5: Can't find variable: Reflect
>> Actual: null
>> Expected: undefined
>> ExtendableBuiltin@file:///Users/shreyasminocha/dev/open%20source/JSVerbalExpressions/dist/verbalexpressions.js:11:31
>> VerbalExpression@file:///Users/shreyasminocha/dev/open%20source/JSVerbalExpressions/dist/verbalexpressions.js:59:130
>> instantiate@file:///Users/shreyasminocha/dev/open%20source/JSVerbalExpressions/dist/verbalexpressions.js:588:32
>> somethingTest@file:///Users/shreyasminocha/dev/open%20source/JSVerbalExpressions/test/tests.js:8:26

...

Warning: 20 tests completed with 20 failed, 0 skipped, and 0 todo.
20 assertions (in 91ms), passed: 0, failed: 20 Use --force to continue.

注意:我运行在编译后的es6代码上进行测试,也就是说,我在运行之前运行 babel测试。

我猜这与 PhantomJS 有关。如何让测试在终端中通过?我错过了什么吗?有什么解决方法吗?

Stable PhantomJS 不支持 ES6 且不再处于开发阶段,如果可能请迁移到 puppeteer,它深受 PhantomJS 的启发。