我正在为 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
[email protected] 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 有关系。如何让测试在终端中通过?我错过了什么吗?任何解决方法?
稳定PhantomJS不支持ES6,不再在发展,如果可能的话迁移到木偶戏,其通过PhantomJS在很大程度上启发。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句