javascript - 仅对 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 或更低版本中不可用,因此我希望在这些版本上运行时跳过此测试。
这可能吗?如果可以,我该怎么做?
解决方案
您可以在脚本中获取节点的版本
process.versions.node
据我了解, util.promisify
不要跳过测试,而是为该函数找到一个 polyfill。
推荐阅读
- c# - 模拟服务和网络位置的问题
- css - 无法将 css 应用于 React className
- ios - 在自定义过渡期间使用 .scaleAspectFill 内容模式为图像视图的比例设置动画
- javascript - 如何检查鼠标光标是否超过某个 x 坐标?
- python - 为什么从 IronPython 调用 Python 时命令窗口会闪烁打开和关闭?
- vim - Neovim scp 不提示输入密码
- git - Git fetch 或 Git pull 来更新 Web 服务器上的文件?
- javascript - 如何从javascript中的API字符串中确定多个不同大小的子字符串
- javascript - 使用 Javascript 计算小时和分钟的差异并将结果填充到另一个字段中
- perl - perl 函数定义因未初始化值而失败