Skip to content

Commit

Permalink
Improved testing to account for race conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
n1474335 committed May 16, 2024
1 parent d1a0da3 commit 3739818
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
2 changes: 1 addition & 1 deletion tests/browser/02_ops.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ function bakeOp(browser, opName, input, args=[]) {
*/
function testOp(browser, opName, input, output, args=[]) {
bakeOp(browser, opName, input, args);
utils.expectOutput(browser, output);
utils.expectOutput(browser, output, true);
}

/** @function
Expand Down
38 changes: 36 additions & 2 deletions tests/browser/browserUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function setInput(browser, input, type=true) {
}, [input]);
browser.pause(100);
}
expectInput(browser, input);
}

/** @function
Expand All @@ -49,6 +50,11 @@ function setInput(browser, input, type=true) {
* @param {Browser} browser - Nightwatch client
*/
function bake(browser) {
browser
// Ensure we're not currently busy
.waitForElementNotVisible("#output-loader", 5000)
.expect.element("#bake span").text.to.equal("BAKE!");

browser
.click("#bake")
.waitForElementNotVisible("#stale-indicator", 5000)
Expand Down Expand Up @@ -162,7 +168,6 @@ function loadRecipe(browser, opName, input, args) {
throw new Error("Invalid operation type. Must be string or array of strings. Received: " + typeof(opName));
}

clear(browser);
setInput(browser, input, false);
browser
.urlHash("recipe=" + recipeConfig)
Expand All @@ -174,8 +179,18 @@ function loadRecipe(browser, opName, input, args) {
*
* @param {Browser} browser - Nightwatch client
* @param {string|RegExp} expected - The expected output value
* @param {boolean} [waitNotNull=false] - Wait for the output to not be empty before testing the value
*/
function expectOutput(browser, expected) {
function expectOutput(browser, expected, waitNotNull=false) {
if (waitNotNull && expected !== "") {
browser.waitUntil(async function() {
const output = await this.execute(function() {
return window.app.manager.output.outputEditorView.state.doc.toString();
});
return output.length;
}, 1000);
}

browser.execute(expected => {
return window.app.manager.output.outputEditorView.state.doc.toString();
}, [expected], function({value}) {
Expand All @@ -187,6 +202,24 @@ function expectOutput(browser, expected) {
});
}

/** @function
* Tests whether the input matches a given value
*
* @param {Browser} browser - Nightwatch client
* @param {string|RegExp} expected - The expected input value
*/
function expectInput(browser, expected) {
browser.execute(expected => {
return window.app.manager.input.inputEditorView.state.doc.toString();
}, [expected], function({value}) {
if (expected instanceof RegExp) {
browser.expect(value).match(expected);
} else {
browser.expect(value).to.be.equal(expected);
}
});
}

/** @function
* Uploads a file using the #open-file input
*
Expand Down Expand Up @@ -246,6 +279,7 @@ module.exports = {
paste: paste,
loadRecipe: loadRecipe,
expectOutput: expectOutput,
expectInput: expectInput,
uploadFile: uploadFile,
uploadFolder: uploadFolder
};

0 comments on commit 3739818

Please sign in to comment.