Skip to content

Commit 3739818

Browse files
committed
Improved testing to account for race conditions
1 parent d1a0da3 commit 3739818

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

tests/browser/02_ops.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ function bakeOp(browser, opName, input, args=[]) {
430430
*/
431431
function testOp(browser, opName, input, output, args=[]) {
432432
bakeOp(browser, opName, input, args);
433-
utils.expectOutput(browser, output);
433+
utils.expectOutput(browser, output, true);
434434
}
435435

436436
/** @function

tests/browser/browserUtils.js

+36-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ function setInput(browser, input, type=true) {
4141
}, [input]);
4242
browser.pause(100);
4343
}
44+
expectInput(browser, input);
4445
}
4546

4647
/** @function
@@ -49,6 +50,11 @@ function setInput(browser, input, type=true) {
4950
* @param {Browser} browser - Nightwatch client
5051
*/
5152
function bake(browser) {
53+
browser
54+
// Ensure we're not currently busy
55+
.waitForElementNotVisible("#output-loader", 5000)
56+
.expect.element("#bake span").text.to.equal("BAKE!");
57+
5258
browser
5359
.click("#bake")
5460
.waitForElementNotVisible("#stale-indicator", 5000)
@@ -162,7 +168,6 @@ function loadRecipe(browser, opName, input, args) {
162168
throw new Error("Invalid operation type. Must be string or array of strings. Received: " + typeof(opName));
163169
}
164170

165-
clear(browser);
166171
setInput(browser, input, false);
167172
browser
168173
.urlHash("recipe=" + recipeConfig)
@@ -174,8 +179,18 @@ function loadRecipe(browser, opName, input, args) {
174179
*
175180
* @param {Browser} browser - Nightwatch client
176181
* @param {string|RegExp} expected - The expected output value
182+
* @param {boolean} [waitNotNull=false] - Wait for the output to not be empty before testing the value
177183
*/
178-
function expectOutput(browser, expected) {
184+
function expectOutput(browser, expected, waitNotNull=false) {
185+
if (waitNotNull && expected !== "") {
186+
browser.waitUntil(async function() {
187+
const output = await this.execute(function() {
188+
return window.app.manager.output.outputEditorView.state.doc.toString();
189+
});
190+
return output.length;
191+
}, 1000);
192+
}
193+
179194
browser.execute(expected => {
180195
return window.app.manager.output.outputEditorView.state.doc.toString();
181196
}, [expected], function({value}) {
@@ -187,6 +202,24 @@ function expectOutput(browser, expected) {
187202
});
188203
}
189204

205+
/** @function
206+
* Tests whether the input matches a given value
207+
*
208+
* @param {Browser} browser - Nightwatch client
209+
* @param {string|RegExp} expected - The expected input value
210+
*/
211+
function expectInput(browser, expected) {
212+
browser.execute(expected => {
213+
return window.app.manager.input.inputEditorView.state.doc.toString();
214+
}, [expected], function({value}) {
215+
if (expected instanceof RegExp) {
216+
browser.expect(value).match(expected);
217+
} else {
218+
browser.expect(value).to.be.equal(expected);
219+
}
220+
});
221+
}
222+
190223
/** @function
191224
* Uploads a file using the #open-file input
192225
*
@@ -246,6 +279,7 @@ module.exports = {
246279
paste: paste,
247280
loadRecipe: loadRecipe,
248281
expectOutput: expectOutput,
282+
expectInput: expectInput,
249283
uploadFile: uploadFile,
250284
uploadFolder: uploadFolder
251285
};

0 commit comments

Comments
 (0)