mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 23:06:16 -04:00
OperationErrors now bubble up to the top of the API.
Added test functionality for node api refactor TestRegister into class
This commit is contained in:
parent
e50758f0a6
commit
5fb50a1759
6 changed files with 194 additions and 30 deletions
|
@ -5,37 +5,49 @@
|
|||
* ensure that they will get run by the frontend.
|
||||
*
|
||||
* @author tlwr [toby@toby.codes]
|
||||
* @copyright Crown Copyright 2017
|
||||
* @author d98762625 [d98762625@gmail.com]
|
||||
* @copyright Crown Copyright 2018
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import Chef from "../src/core/Chef";
|
||||
|
||||
(function() {
|
||||
/**
|
||||
* Object to store and run the list of tests.
|
||||
*
|
||||
* @class
|
||||
* @constructor
|
||||
*/
|
||||
function TestRegister() {
|
||||
this.tests = [];
|
||||
}
|
||||
/**
|
||||
* Object to store and run the list of tests.
|
||||
*
|
||||
* @class
|
||||
* @constructor
|
||||
*/
|
||||
class TestRegister {
|
||||
|
||||
/**
|
||||
* initialise with no tests
|
||||
*/
|
||||
constructor() {
|
||||
this.tests = [];
|
||||
this.apiTests = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a list of tests to the register.
|
||||
*
|
||||
* @param {Object[]} tests
|
||||
*/
|
||||
TestRegister.prototype.addTests = function(tests) {
|
||||
addTests(tests) {
|
||||
this.tests = this.tests.concat(tests);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a list of api tests to the register
|
||||
* @param {Object[]} tests
|
||||
*/
|
||||
addApiTests(tests) {
|
||||
this.apiTests = this.apiTests.concat(tests);
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs all the tests in the register.
|
||||
*/
|
||||
TestRegister.prototype.runTests = function() {
|
||||
runTests () {
|
||||
return Promise.all(
|
||||
this.tests.map(function(test, i) {
|
||||
const chef = new Chef();
|
||||
|
@ -81,12 +93,29 @@ import Chef from "../src/core/Chef";
|
|||
});
|
||||
})
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Run all api related tests and wrap results in report format
|
||||
*/
|
||||
runApiTests() {
|
||||
return Promise.all(this.apiTests.map(async function(test, i) {
|
||||
const result = {
|
||||
test: test,
|
||||
status: null,
|
||||
output: null,
|
||||
};
|
||||
try {
|
||||
await test.run();
|
||||
result.status = "passing";
|
||||
} catch (e) {
|
||||
result.status = "erroring";
|
||||
result.output = e.message;
|
||||
}
|
||||
return result;
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
// Singleton TestRegister, keeping things simple and obvious.
|
||||
global.TestRegister = global.TestRegister || new TestRegister();
|
||||
})();
|
||||
|
||||
export default global.TestRegister;
|
||||
|
||||
// Export an instance to make a singleton
|
||||
export default new TestRegister();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue