Merge branch 'master' into parse-ethernet-frame

This commit is contained in:
Ted Kruijff 2024-06-24 12:37:00 +03:00 committed by GitHub
commit 68f69d690f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
60 changed files with 4295 additions and 2238 deletions

View file

@ -236,7 +236,7 @@ module.exports = {
// testOp(browser, "OR", "test input", "test_output");
// testOp(browser, "Object Identifier to Hex", "test input", "test_output");
testOpHtml(browser, "Offset checker", "test input\n\nbest input", ".hl5", "est input");
// testOp(browser, "Optical Character Recognition", "test input", "test_output");
testOpFile(browser, "Optical Character Recognition", "files/testocr.png", false, /This is a lot of 12 point text to test the/, [], 10000);
// testOp(browser, "PEM to Hex", "test input", "test_output");
// testOp(browser, "PGP Decrypt", "test input", "test_output");
// testOp(browser, "PGP Decrypt and Verify", "test input", "test_output");
@ -408,7 +408,7 @@ module.exports = {
* @param {Browser} browser - Nightwatch client
* @param {string|Array<string>} opName - name of operation to be tested, array for multiple ops
* @param {string} input - input text for test
* @param {Array<string>|Array<Array<string>>} args - arguments, nested if multiple ops
* @param {Array<string>|Array<Array<string>>} [args=[]] - arguments, nested if multiple ops
*/
function bakeOp(browser, opName, input, args=[]) {
browser.perform(function() {
@ -425,12 +425,12 @@ function bakeOp(browser, opName, input, args=[]) {
* @param {Browser} browser - Nightwatch client
* @param {string|Array<string>} opName - name of operation to be tested, array for multiple ops
* @param {string} input - input text
* @param {string} output - expected output
* @param {Array<string>|Array<Array<string>>} args - arguments, nested if multiple ops
* @param {string|RegExp} output - expected output
* @param {Array<string>|Array<Array<string>>} [args=[]] - arguments, nested if multiple ops
*/
function testOp(browser, opName, input, output, args=[]) {
bakeOp(browser, opName, input, args);
utils.expectOutput(browser, output);
utils.expectOutput(browser, output, true);
}
/** @function
@ -440,8 +440,8 @@ function testOp(browser, opName, input, output, args=[]) {
* @param {string|Array<string>} opName - name of operation to be tested array for multiple ops
* @param {string} input - input text
* @param {string} cssSelector - CSS selector for HTML output
* @param {string} output - expected output
* @param {Array<string>|Array<Array<string>>} args - arguments, nested if multiple ops
* @param {string|RegExp} output - expected output
* @param {Array<string>|Array<Array<string>>} [args=[]] - arguments, nested if multiple ops
*/
function testOpHtml(browser, opName, input, cssSelector, output, args=[]) {
bakeOp(browser, opName, input, args);
@ -459,9 +459,9 @@ function testOpHtml(browser, opName, input, cssSelector, output, args=[]) {
* @param {Browser} browser - Nightwatch client
* @param {string|Array<string>} opName - name of operation to be tested array for multiple ops
* @param {string} filename - filename of image file from samples directory
* @param {Array<string>|Array<Array<string>>} args - arguments, nested if multiple ops
* @param {Array<string>|Array<Array<string>>} [args=[]] - arguments, nested if multiple ops
*/
function testOpImage(browser, opName, filename, args) {
function testOpImage(browser, opName, filename, args=[]) {
browser.perform(function() {
console.log(`Current test: ${opName}`);
});
@ -481,11 +481,12 @@ function testOpImage(browser, opName, filename, args) {
* @param {Browser} browser - Nightwatch client
* @param {string|Array<string>} opName - name of operation to be tested array for multiple ops
* @param {string} filename - filename of file from samples directory
* @param {string} cssSelector - CSS selector for HTML output
* @param {string} output - expected output
* @param {Array<string>|Array<Array<string>>} args - arguments, nested if multiple ops
* @param {string|boolean} cssSelector - CSS selector for HTML output or false for normal text output
* @param {string|RegExp} output - expected output
* @param {Array<string>|Array<Array<string>>} [args=[]] - arguments, nested if multiple ops
* @param {number} [waitWindow=1000] - The number of milliseconds to wait for the output to be correct
*/
function testOpFile(browser, opName, filename, cssSelector, output, args) {
function testOpFile(browser, opName, filename, cssSelector, output, args=[], waitWindow=1000) {
browser.perform(function() {
console.log(`Current test: ${opName}`);
});
@ -494,9 +495,14 @@ function testOpFile(browser, opName, filename, cssSelector, output, args) {
browser.pause(100).waitForElementVisible("#stale-indicator", 5000);
utils.bake(browser);
if (typeof output === "string") {
if (!cssSelector) {
// Text output
utils.expectOutput(browser, output, true, waitWindow);
} else if (typeof output === "string") {
// HTML output - string match
browser.expect.element("#output-html " + cssSelector).text.that.equals(output);
} else if (output instanceof RegExp) {
// HTML output - RegEx match
browser.expect.element("#output-html " + cssSelector).text.that.matches(output);
}
}

View file

@ -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,19 @@ 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
* @param {number} [waitWindow=1000] - The number of milliseconds to wait for the output to be correct
*/
function expectOutput(browser, expected) {
function expectOutput(browser, expected, waitNotNull=false, waitWindow=1000) {
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;
}, waitWindow);
}
browser.execute(expected => {
return window.app.manager.output.outputEditorView.state.doc.toString();
}, [expected], function({value}) {
@ -187,6 +203,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 +280,7 @@ module.exports = {
paste: paste,
loadRecipe: loadRecipe,
expectOutput: expectOutput,
expectInput: expectInput,
uploadFile: uploadFile,
uploadFolder: uploadFolder
};