From b08374f0ba2d1c163f1c8d75a06f642101e1e15d Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Mon, 12 Mar 2018 11:00:08 -0700 Subject: Add scaffolding for sra-report collection unit tests --- packages/sra-report/src/globals.d.ts | 25 +++++++++++++++++++++++-- packages/sra-report/src/index.ts | 5 ++--- packages/sra-report/src/utils.ts | 4 ++++ 3 files changed, 29 insertions(+), 5 deletions(-) (limited to 'packages/sra-report/src') diff --git a/packages/sra-report/src/globals.d.ts b/packages/sra-report/src/globals.d.ts index 0d3beb446..1efa4fe6d 100644 --- a/packages/sra-report/src/globals.d.ts +++ b/packages/sra-report/src/globals.d.ts @@ -1,6 +1,27 @@ +declare module 'dirty-chai'; + declare module 'newman' { - // tslint:disable-next-line:completed-docs - export function run(options: any, callback?: () => void): void; + export interface NewmanRunSummary { + run: NewmanRun; + } + export interface NewmanRun { + executions: NewmanRunExecution[]; + } + export interface NewmanRunExecution { + item: NewmanRunExecutionItem; + assertions: NewmanRunExecutionAssertion[]; + } + export interface NewmanRunExecutionItem { + name: string; + } + export interface NewmanRunExecutionAssertion { + assertion: string; + error: NewmanRunExecutionAssertionError; + } + export interface NewmanRunExecutionAssertionError { + message: string; + } + export function run(options: any, callback?: (err: Error | null, summary: NewmanRunSummary) => void): void; } declare module '*.json' { diff --git a/packages/sra-report/src/index.ts b/packages/sra-report/src/index.ts index d23549916..022464d28 100644 --- a/packages/sra-report/src/index.ts +++ b/packages/sra-report/src/index.ts @@ -7,12 +7,11 @@ import * as _ from 'lodash'; import * as newman from 'newman'; import * as yargs from 'yargs'; -import * as sraReportCollectionJSON from '../postman_configs/collections/sra_report.postman_collection.json'; +import * as sraReportCollectionJSON from '../../postman_collections/sra_report.postman_collection.json'; import { postmanEnvironmentFactory } from './postman_environment_factory'; import { utils } from './utils'; -const newmanRunAsync = promisify(newman.run); const DEFAULT_NETWORK_ID = 1; const SUPPORTED_NETWORK_IDS = [1, 3, 4, 42]; @@ -97,6 +96,6 @@ const mainAsync = async () => { exportEnvironment: args.exportEnvironment, ...newmanReporterOptions, }; - await newmanRunAsync(newmanRunOptions); + await utils.newmanRunAsync(newmanRunOptions); }; mainAsync().catch(utils.log); diff --git a/packages/sra-report/src/utils.ts b/packages/sra-report/src/utils.ts index 5423cabd9..57c1b5af3 100644 --- a/packages/sra-report/src/utils.ts +++ b/packages/sra-report/src/utils.ts @@ -1,5 +1,9 @@ +import { promisify } from '@0xproject/utils'; +import { NewmanRunSummary, run as newmanRun } from 'newman'; + export const utils = { log(...args: any[]): void { console.log(...args); // tslint:disable-line:no-console }, + newmanRunAsync: promisify(newmanRun), }; -- cgit