Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(command-line-runner): add the ability to run a test from the command line WIP #71

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat(command-line-runner): add the ability to run a test from the com…
…mand line
  • Loading branch information
krishna-acondy committed Sep 26, 2020
commit f39ee885ac24ddc0f973407c194ebe4aa267a571
33 changes: 33 additions & 0 deletions src/test-runner/TestRunner.ts
Original file line number Diff line number Diff line change
@@ -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;
}