mirror of
https://github.com/gchq/CyberChef
synced 2024-12-29 14:03:10 +00:00
Tidied up test runner. Passing tests are no longer printed to the console.
This commit is contained in:
parent
148dcbb0c5
commit
772c6bbba5
3 changed files with 35 additions and 29 deletions
|
@ -48,6 +48,7 @@ class TestRegister {
|
||||||
* Runs all the tests in the register.
|
* Runs all the tests in the register.
|
||||||
*/
|
*/
|
||||||
runTests () {
|
runTests () {
|
||||||
|
console.log("Running tests...");
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
this.tests.map(function(test, i) {
|
this.tests.map(function(test, i) {
|
||||||
const chef = new Chef();
|
const chef = new Chef();
|
||||||
|
@ -103,6 +104,8 @@ class TestRegister {
|
||||||
* Run all api related tests and wrap results in report format
|
* Run all api related tests and wrap results in report format
|
||||||
*/
|
*/
|
||||||
runApiTests() {
|
runApiTests() {
|
||||||
|
console.log("Running tests...");
|
||||||
|
|
||||||
return Promise.all(this.apiTests.map(async function(test, i) {
|
return Promise.all(this.apiTests.map(async function(test, i) {
|
||||||
const result = {
|
const result = {
|
||||||
test: test,
|
test: test,
|
||||||
|
|
|
@ -15,59 +15,63 @@
|
||||||
* @param {string} status
|
* @param {string} status
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
const statusToIcon = function statusToIcon(status) {
|
function statusToIcon(status) {
|
||||||
const icons = {
|
return {
|
||||||
erroring: "🔥",
|
erroring: "🔥",
|
||||||
failing: "❌",
|
failing: "❌",
|
||||||
passing: "✔️️",
|
passing: "✔️️",
|
||||||
};
|
}[status] || "?";
|
||||||
return icons[status] || "?";
|
}
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Displays a given test result in the console.
|
|
||||||
* Counts test statuses.
|
* Counts test statuses.
|
||||||
*
|
*
|
||||||
* @param {Object} testStatusCounts
|
* @param {Object} testStatus
|
||||||
* @param {Object} testResult
|
* @param {Object} testResult
|
||||||
*/
|
*/
|
||||||
function handleTestResult(testStatus, testResult) {
|
function handleTestResult(testStatus, testResult) {
|
||||||
testStatus.allTestsPassing = testStatus.allTestsPassing && testResult.status === "passing";
|
testStatus.allTestsPassing = testStatus.allTestsPassing && testResult.status === "passing";
|
||||||
const newCount = (testStatus.counts[testResult.status] || 0) + 1;
|
testStatus.counts[testResult.status] = (testStatus.counts[testResult.status] || 0) + 1;
|
||||||
testStatus.counts[testResult.status] = newCount;
|
|
||||||
testStatus.counts.total += 1;
|
testStatus.counts.total += 1;
|
||||||
console.log([
|
|
||||||
statusToIcon(testResult.status),
|
|
||||||
testResult.test.name
|
|
||||||
].join(" "));
|
|
||||||
|
|
||||||
if (testResult.output) {
|
|
||||||
console.log(
|
|
||||||
testResult.output
|
|
||||||
.trim()
|
|
||||||
.replace(/^/, "\t")
|
|
||||||
.replace(/\n/g, "\n\t")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log each test result, count tests and failures. Log test suite run duration.
|
* Log each test result, count tests and failures.
|
||||||
*
|
*
|
||||||
* @param {Object} testStatus - object describing test run data
|
* @param {Object} testStatus - object describing test run data
|
||||||
* @param {Object[]} results - results from TestRegister
|
* @param {Object[]} results - results from TestRegister
|
||||||
*/
|
*/
|
||||||
export function logTestReport(testStatus, results) {
|
export function logTestReport(testStatus, results) {
|
||||||
results.forEach(r => handleTestResult(testStatus, r));
|
console.log("Tests completed.");
|
||||||
console.log("\n");
|
|
||||||
|
|
||||||
|
results.forEach(r => handleTestResult(testStatus, r));
|
||||||
|
|
||||||
|
console.log();
|
||||||
for (const testStatusCount in testStatus.counts) {
|
for (const testStatusCount in testStatus.counts) {
|
||||||
const count = testStatus.counts[testStatusCount];
|
const count = testStatus.counts[testStatusCount];
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
console.log(testStatusCount.toUpperCase(), count);
|
console.log(testStatusCount.toUpperCase() + "\t" + count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
console.log();
|
||||||
|
|
||||||
|
// Print error messages for tests that didn't pass
|
||||||
|
results.filter(res => res.status !== "passing").forEach(testResult => {
|
||||||
|
console.log([
|
||||||
|
statusToIcon(testResult.status),
|
||||||
|
testResult.test.name
|
||||||
|
].join(" "));
|
||||||
|
|
||||||
|
if (testResult.output) {
|
||||||
|
console.log(
|
||||||
|
testResult.output
|
||||||
|
.trim()
|
||||||
|
.replace(/^/, "\t")
|
||||||
|
.replace(/\n/g, "\n\t")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
console.log();
|
||||||
|
|
||||||
process.exit(testStatus.allTestsPassing ? 0 : 1);
|
process.exit(testStatus.allTestsPassing ? 0 : 1);
|
||||||
}
|
}
|
||||||
|
@ -81,4 +85,3 @@ export function setLongTestFailure() {
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}, 60 * 1000);
|
}, 60 * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -906,7 +906,7 @@ smothering ampersand abreast
|
||||||
}),
|
}),
|
||||||
|
|
||||||
it("to unix timestamp", () => {
|
it("to unix timestamp", () => {
|
||||||
assert.strictEqual(chef.toUNIXTimestamp("04-01-2001").toString(), "986083200 (Sun 1 April 2001 00:00:00 UTC)");
|
assert.strictEqual(chef.toUNIXTimestamp("2001-04-01").toString(), "986083200 (Sun 1 April 2001 00:00:00 UTC)");
|
||||||
}),
|
}),
|
||||||
|
|
||||||
it("Translate DateTime format", () => {
|
it("Translate DateTime format", () => {
|
||||||
|
|
Loading…
Reference in a new issue