【问题标题】:Only run coffeescript test for Node version 8 or greater仅对 Node 8 或更高版本运行 coffeescript 测试
【发布时间】:2019-02-17 14:39:55
【问题描述】:

我有一个 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 或更低版本中不可用,因此我希望在这些版本上运行时跳过此测试。

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

【问题讨论】:

  • 抱歉。附加信息已添加到问题中。
  • 正如答案所暗示的,promsify 是 polyfillable,并且有一个 polyfill,github.com/ljharb/util.promisify

标签: javascript node.js testing coffeescript


【解决方案1】:

您可以使用

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

据我了解,util.promisify

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

【讨论】:

  • 谢谢。我已经得到了polyfill。几周后它就可以投入生产了,所以我想在我的测试中准备好一些东西,直到那时我可以完全跳过测试,但如果可以的话,我更愿意在某些版本上运行它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-21
  • 2018-03-22
  • 1970-01-01
  • 2016-08-26
  • 2010-09-20
  • 2017-07-07
相关资源
最近更新 更多