根据标题,我正在尝试测试使用ES6 JS编写的一些AMD模块,并在nodejs上运行。
我首先尝试了Intern:即使在nodejs中启用了--harmony
,但我最终面对了Intern的依赖链,在例如Istanbul,esprima和其他位置无法启用Harmony(我为此打开了一个issue)。
然后我转向mocha,在这里我被困住了...奇怪的是。我为nodejs和mocha本身都启用了Harmony,这是package.json
测试脚本:
"test": "node --harmony node_modules\\mocha\\bin\\mocha tests --harmony --recursive"
我在命令提示符中运行 npm test my_test_folder
命令。然而,一些 ES6 构造(例如 const
)可以正常通过,但它在解构赋值时卡住了。以下是输出的前几行:
const { log, dir } = require('../consoleLogger.js');
^
SyntaxError: Unexpected token {
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
[...continues...]
我也查阅了这个 SO讨论串,并听说过转换器,但我不确定它们是否可行,现在我正在尝试让转换器在这种情况下起作用。
有什么想法可以解决这个问题,而不需要改变代码中散布的所有ES6位? TA。