仅对节点版本8或更高版本运行coffeescript测试

时间:2018-09-12 21:44:50

标签: javascript node.js testing coffeescript

我有一个CoffeeScript测试,仅在Node版本为8或更高版本时才能运行。对于任何较低的版本号,我想跳过测试。

文件的扩展名为.spec.coffee,并且测试采用以下结构:

it.skip'测试名称'--

# __dirname is the 'test/' folder, so go up then find the SDK path
path = path.join __dirname, '..', 'folder1', 'folder2'

# run `npm run tstest`
exec = util.promisify(process.exec)
return exec 'npm run test', cwd: path
  .then (data) ->
    expect(data.stderr).to.eql ''
    expect(data.stdout).to.exist

据我了解,util.promisify在节点版本7或更低版​​本中不可用,因此我希望在这些版本上运行时跳过此测试。

这可能吗,如果可以,我该怎么办?

1 个答案:

答案 0 :(得分:2)

您可以使用

在脚本中获取节点的版本
process.versions.node 
  

据我所知,util.promisify

与其跳过测试,不如为该函数找到一个polyfill。