首页 > 解决方案 > 仅对 Node 8 或更高版本运行 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在 Node 版本 7 或更低版本中不可用,因此我希望在这些版本上运行时跳过此测试。

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

标签: javascriptnode.jstestingcoffeescript

解决方案


您可以在脚本中获取节点的版本

process.versions.node 

据我了解, util.promisify

不要跳过测试,而是为该函数找到一个 polyfill。


推荐阅读