Initial commit

This commit is contained in:
Oliver 2021-12-02 13:13:17 -06:00
commit f8910e4f30
28 changed files with 3111 additions and 0 deletions

View file

@ -0,0 +1,72 @@
//
// test_runner.ts
//
// Written by: Oliver Akins (2019/11/17 - 2020/07/21)
//
import { TEST_CHANNEL, TEST_USER } from "../constants";
import { HANDLE_MESSAGE } from "../cmd_handler";
import { LOAD_CONFIG } from "../utils/Config";
import { tests } from "../utils/tests";
const config = LOAD_CONFIG();
var fail_count = 0;
export const run_tests = (silent: boolean): number => {
// Run through each test
for (var test of tests) {
let response = HANDLE_MESSAGE({
message: test.msg_meta.message,
level: test.msg_meta.level,
user: TEST_USER,
cooldown: false,
source: test.msg_meta.source,
channel: test.msg_meta.channel || TEST_CHANNEL,
test: true
});
// If the confirmation message is defined, trigger a confirmation
if (test.confirm_msg) {
response = HANDLE_MESSAGE({
message: test.confirm_msg.message,
level: test.confirm_msg.level,
user: TEST_USER,
cooldown: false,
source: test.confirm_msg.source,
channel: test.msg_meta.channel || TEST_CHANNEL,
test: true
});
};
// Compare outputs
if (test.expected_return != response) {
fail_count++;
if (!silent) {
console.log("=====================================================");
console.log(`Test ${test.id} failed`);
console.log(` Expected: "${test.expected_return}"`);
console.log(` Received: "${response}"`);
};
};
};
// Check if we are being silent
if (!silent && fail_count > 0) {
console.log("=====================================================");
};
// Output summary
console.log(`Tests: ${fail_count} tests failed out of ${tests.length} tests.`);
console.log(` ${Math.round(((tests.length - fail_count) / tests.length) * 100)}% passed`);
return fail_count;
};