mirror of
https://github.com/gchq/CyberChef
synced 2024-12-28 05:23:10 +00:00
Improved testing to account for race conditions
This commit is contained in:
parent
d1a0da3f8d
commit
37398188f9
2 changed files with 37 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -41,6 +41,7 @@ function setInput(browser, input, type=true) {
|
|||
}, [input]);
|
||||
browser.pause(100);
|
||||
}
|
||||
expectInput(browser, input);
|
||||
}
|
||||
|
||||
/** @function
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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}) {
|
||||
|
@ -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
|
||||
*
|
||||
|
@ -246,6 +279,7 @@ module.exports = {
|
|||
paste: paste,
|
||||
loadRecipe: loadRecipe,
|
||||
expectOutput: expectOutput,
|
||||
expectInput: expectInput,
|
||||
uploadFile: uploadFile,
|
||||
uploadFolder: uploadFolder
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue