Improved testing to account for race conditions

This commit is contained in:
n1474335 2024-05-16 14:29:32 +01:00
parent d1a0da3f8d
commit 37398188f9
No known key found for this signature in database
GPG key ID: D15457B7B4AF3F37
2 changed files with 37 additions and 3 deletions

View file

@ -430,7 +430,7 @@ function bakeOp(browser, opName, input, args=[]) {
*/ */
function testOp(browser, opName, input, output, args=[]) { function testOp(browser, opName, input, output, args=[]) {
bakeOp(browser, opName, input, args); bakeOp(browser, opName, input, args);
utils.expectOutput(browser, output); utils.expectOutput(browser, output, true);
} }
/** @function /** @function

View file

@ -41,6 +41,7 @@ function setInput(browser, input, type=true) {
}, [input]); }, [input]);
browser.pause(100); browser.pause(100);
} }
expectInput(browser, input);
} }
/** @function /** @function
@ -49,6 +50,11 @@ function setInput(browser, input, type=true) {
* @param {Browser} browser - Nightwatch client * @param {Browser} browser - Nightwatch client
*/ */
function bake(browser) { function bake(browser) {
browser
// Ensure we're not currently busy
.waitForElementNotVisible("#output-loader", 5000)
.expect.element("#bake span").text.to.equal("BAKE!");
browser browser
.click("#bake") .click("#bake")
.waitForElementNotVisible("#stale-indicator", 5000) .waitForElementNotVisible("#stale-indicator", 5000)
@ -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)); throw new Error("Invalid operation type. Must be string or array of strings. Received: " + typeof(opName));
} }
clear(browser);
setInput(browser, input, false); setInput(browser, input, false);
browser browser
.urlHash("recipe=" + recipeConfig) .urlHash("recipe=" + recipeConfig)
@ -174,8 +179,18 @@ function loadRecipe(browser, opName, input, args) {
* *
* @param {Browser} browser - Nightwatch client * @param {Browser} browser - Nightwatch client
* @param {string|RegExp} expected - The expected output value * @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 => { browser.execute(expected => {
return window.app.manager.output.outputEditorView.state.doc.toString(); return window.app.manager.output.outputEditorView.state.doc.toString();
}, [expected], function({value}) { }, [expected], function({value}) {
@ -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 /** @function
* Uploads a file using the #open-file input * Uploads a file using the #open-file input
* *
@ -246,6 +279,7 @@ module.exports = {
paste: paste, paste: paste,
loadRecipe: loadRecipe, loadRecipe: loadRecipe,
expectOutput: expectOutput, expectOutput: expectOutput,
expectInput: expectInput,
uploadFile: uploadFile, uploadFile: uploadFile,
uploadFolder: uploadFolder uploadFolder: uploadFolder
}; };