From f39ee885ac24ddc0f973407c194ebe4aa267a571 Mon Sep 17 00:00:00 2001 From: Krishna Acondy Date: Sat, 26 Sep 2020 13:57:33 +0100 Subject: [PATCH] feat(command-line-runner): add the ability to run a test from the command line --- src/test-runner/TestRunner.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/test-runner/TestRunner.ts diff --git a/src/test-runner/TestRunner.ts b/src/test-runner/TestRunner.ts new file mode 100644 index 0000000..f1cfefb --- /dev/null +++ b/src/test-runner/TestRunner.ts @@ -0,0 +1,33 @@ +import { Test } from "../types"; +import chalk from "chalk"; +import SASjs from "@sasjs/adapter/node"; + +export const getConfiguredAdapter = async () => { + const config = await fetch("config.json").then((res) => res.json()); + console.log(config); + const sasjs = new SASjs(config.sasJsConfig); + return sasjs; +} + +export const runTest = async (currentTest: Test, context: any) => { + const { title, beforeTest, afterTest, assertion } = currentTest; + + console.log(chalk.blueBright(`Running test: ${chalk.cyanBright(title)}`)); + + const beforeTestFunction = beforeTest ? beforeTest : () => Promise.resolve(); + const afterTestFunction = afterTest ? afterTest : () => Promise.resolve(); + + await beforeTestFunction(); + + const startTime = new Date().valueOf(); + const response = await test(context); + const result = assertion(response, context); + const endTime = new Date().valueOf(); + const executionTime = (endTime - startTime) / 1000; + + console.log(result ? chalk.greenBright(`\u2714 Test passed! [${executionTime.toFixed(2)}s]`) : chalk.redBright(`\u2718 Test failed. [${executionTime.toFixed(2)}s]`)); + + await afterTestFunction(); + + return !!result; +} \ No newline at end of file