import { Ecanna } from "src" export const getEcanna = (): Ecanna => { if (typeof process.env.EcannaGO_IP === "undefined") { throw "Undefined environment variable: EcannaGO_IP" } if (typeof process.env.EcannaGO_PORT === "undefined") { throw "Undefined environment variable: EcannaGO_PORT" } const ecanna: Ecanna = new Ecanna( process.env.EcannaGO_IP, parseInt(process.env.EcannaGO_PORT) ) return ecanna } export enum Matcher { toBe, toEqual, toContain, toMatch, toThrow, Get } export const createTests = (tests_spec: any[]): void => { for (const [testName, promise, preprocess, matcher, expected] of tests_spec) { test(testName, async (): Promise => { if (matcher == Matcher.toBe) { expect(preprocess(await promise())).toBe(expected()) } if (matcher == Matcher.toEqual) { expect(preprocess(await promise())).toEqual(expected()) } if (matcher == Matcher.toContain) { expect(preprocess(await promise())).toEqual(expect.arrayContaining(expected())) } if (matcher == Matcher.toMatch) { expect(preprocess(await promise())).toMatch(expected()) } if (matcher == Matcher.toThrow) { await expect(preprocess(promise())).rejects.toThrow(expected()) } if (matcher == Matcher.Get) { expected().value = preprocess(await promise()) expect(true).toBe(true) } }) } }