【发布时间】:2018-12-20 20:02:22
【问题描述】:
我正在 TestCafe 中创建测试。目标是让测试用 Gherkin 编写。我查看了一些集成了 Cucumber 和 TestCafe 的 GitHub 存储库,但我正在尝试不同的角度。
我想使用 Gherkin 解析器并跳过 Cucumber。相反,我将创建自己的实现来运行测试步骤。但目前我一直试图让 TestCafe 运行测试。
如果我是正确的,问题是 TestCafe 正在运行我的测试文件,然后在任何地方都看不到任何装置或测试。这是正确的,因为 Gherkin 解析器正在使用流 API(它使用单独的 Go 进程来解析功能文件)来传递数据,这意味着在我当前的代码中,当 TestCafe 退出时,Promise 仍然处于未决状态。或者,如果我删除 end 回调尚未发生。
我的分析正确吗?如果是,我如何从流中获取所有数据并创建测试以便 TestCafe 运行它?
gherkin_executor.js
var Gherkin = require('gherkin');
console.log('start')
const getParsedGherkin = new Promise((resolve, reject) => {
let stream = Gherkin.fromPaths(['file.feature'])
let data = []
stream.on('data', (chunk) => {
if(chunk.hasOwnProperty('source')){
data.push({source: chunk.source, name: null, pickles: []})
}
else if (chunk.hasOwnProperty('gherkinDocument')){
data[data.length-1].name = chunk.gherkinDocument.feature.name
}
else {
data[data.length-1].pickles.push(chunk.pickle)
}
})
stream.on('end', () => {
resolve(data)
})
})
let data = getParsedGherkin.then((data) => {return data})
console.log(data)
function createTests(data){
for(let feature of data){
fixture(feature.name)
for(let testcase of feature.pickles){
test(testcase.name, async t => {
console.log('test')
})
}
}
}
file.feature
Feature: A test feature
Scenario: A test case
Given some data
When doing some action
Then there is some result
【问题讨论】:
标签: javascript asynchronous promise async-await testcafe