【发布时间】:2019-04-30 04:54:48
【问题描述】:
我有一个名为 archive.spec.coffee 的咖啡脚本文件。
开头是:
describe 'Archive', ->
所有测试都在描述范围内。
我想使用 http 调用检查软件版本,根据具体情况,我想执行或跳过测试。
我认为我需要做这样的事情,但到目前为止它不起作用:
req = https.get {host: "https://path/to/endpoint"}
if(req.version == 1.2.3)
this.skip
else
describe 'Archive', ->
谁能告诉我如何正确地做到这一点?
其他信息
我想出了这个:
beforeEach ->
req = request.get {
url: 'https://path/to/endpoint',
auth: {
user: 'admin',
pass: 'password'
},
json: true
},
(err, res, body) ->
version = body.responseData.devices[0].versions[0].version
if (version.indexOf('1.2.3') == -1)
done()
else
this.skip()
describe 'Archive', ->
我现在的问题是,如果版本是 1.2.3,version.indexOf('1.2.3') 返回 0,则输入 else 但不会跳过测试。
最新更新
现在我想出了这个:
before (done) ->
req = request.get {
url: 'https://path/to/endpoint',
auth: {
user: 'admin',
pass: 'password'
},
json: true
},
(err, res, body) ->
version = body.responseData.devices[0].versions[0].version
if (version.indexOf('1.2.3') != -1)
skip = true
done()
else
done()
describe 'Archive', ->
it 'my_test', ->
if (skip)
this.skip()
如果我使用 1.2.3 版进行测试,我可以看到在 before 函数中跳过设置为 true。 done() 返回 my_test 但 if (skip) 是 false。显然这是因为 skip 在不同的函数中设置为 true。如何获取它以便之前将 skip 的值返回给我的测试?
【问题讨论】:
-
这听起来更像是通过环境变量而不是 HTTP 调用解决的问题。这能解决你的问题吗?
-
可能。您能否详细说明如何做到这一点?
标签: javascript coffeescript mocha.js