diff options
author | Brandon Millman <brandon.millman@gmail.com> | 2018-02-28 03:51:05 +0800 |
---|---|---|
committer | Brandon Millman <brandon.millman@gmail.com> | 2018-02-28 03:51:05 +0800 |
commit | 9c8501a84e92faf3ef015ae8ab4d1da9354f9a9d (patch) | |
tree | 8ad8e3af292e7af68cab2f20e852dee6982682c0 /packages/sra-report/src/index.ts | |
parent | bb157eefc622148d7ab3f49b3b94df274deccedb (diff) | |
download | dexon-sol-tools-9c8501a84e92faf3ef015ae8ab4d1da9354f9a9d.tar dexon-sol-tools-9c8501a84e92faf3ef015ae8ab4d1da9354f9a9d.tar.gz dexon-sol-tools-9c8501a84e92faf3ef015ae8ab4d1da9354f9a9d.tar.bz2 dexon-sol-tools-9c8501a84e92faf3ef015ae8ab4d1da9354f9a9d.tar.lz dexon-sol-tools-9c8501a84e92faf3ef015ae8ab4d1da9354f9a9d.tar.xz dexon-sol-tools-9c8501a84e92faf3ef015ae8ab4d1da9354f9a9d.tar.zst dexon-sol-tools-9c8501a84e92faf3ef015ae8ab4d1da9354f9a9d.zip |
Refactor environment factory and promisify newman
Diffstat (limited to 'packages/sra-report/src/index.ts')
-rw-r--r-- | packages/sra-report/src/index.ts | 87 |
1 files changed, 13 insertions, 74 deletions
diff --git a/packages/sra-report/src/index.ts b/packages/sra-report/src/index.ts index 58734182e..d273d74a4 100644 --- a/packages/sra-report/src/index.ts +++ b/packages/sra-report/src/index.ts @@ -2,23 +2,18 @@ import { assert } from '@0xproject/assert'; import { Schema, schemas } from '@0xproject/json-schemas'; +import { promisify } from '@0xproject/utils'; import chalk from 'chalk'; 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 kovanTokensEnvironmentJSON from '../postman_configs/environments/kovan_tokens.postman_environment.json'; -import * as mainnetTokensEnvironmentJSON from '../postman_configs/environments/mainnet_tokens.postman_environment.json'; +import { postmanEnvironmentFactory } from './postman_environment_factory'; import { utils } from './utils'; -interface GlobalsValue { - key: string; - value: string; - enabled: boolean; - type: string; -} +const newmanRunAsync = promisify<void>(newman.run); const DEFAULT_NETWORK_ID = 1; const SUPPORTED_NETWORK_IDS = [1, 42]; @@ -58,72 +53,16 @@ if (!_.includes(SUPPORTED_NETWORK_IDS, args.networkId)) { utils.log(`${chalk.bold(`Supported network ids:`)} ${SUPPORTED_NETWORK_IDS}`); process.exit(1); } -// run newman -newman.run( - { + +const mainAsync = async () => { + const newmanRunOptions = { collection: sraReportCollectionJSON, reporters: 'cli', - globals: createGlobals(args.url, _.values(schemas)), - environment: getEnvironment(args.networkId), - }, - (err: Error) => { - if (err) { - throw err; - } - utils.log('collection run complete!'); - }, -); -function createGlobals(url: string, schemaList: Schema[]) { - const urlGlobalsValue = { - key: 'url', - value: args.url, - enabled: true, - type: 'text', - }; - const schemaGlobalsValues = _.compact( - _.map(schemaList, (schema: Schema) => { - if (_.isUndefined(schema.id)) { - return undefined; - } else { - return { - key: convertSchemaIdToKey(schema.id), - value: JSON.stringify(schema), - enabled: true, - type: 'text', - }; - } - }), - ); - const schemaKeys = _.map(schemaGlobalsValues, (globalsValue: GlobalsValue) => { - return globalsValue.key; - }); - const schemaKeysGlobalsValue = { - key: 'schemaKeys', - value: JSON.stringify(schemaKeys), - enabled: true, - type: 'text', - }; - const globalsValues = _.concat(schemaGlobalsValues, urlGlobalsValue, schemaKeysGlobalsValue); - const globals = { - values: globalsValues, + globals: postmanEnvironmentFactory.createGlobalEnvironment(args.url), + environment: postmanEnvironmentFactory.createNetworkEnvironment(args.networkId), }; - return globals; -} -function convertSchemaIdToKey(schemaId: string) { - let result = schemaId; - if (_.startsWith(result, '/')) { - result = result.substr(1); - } - result = `${result}Schema`; - return result; -} -function getEnvironment(networkId: number) { - switch (networkId) { - case 1: - return mainnetTokensEnvironmentJSON; - case 42: - return kovanTokensEnvironmentJSON; - default: - return {}; - } -} + await newmanRunAsync(newmanRunOptions); +}; + +mainAsync() + .catch(err => utils.log); |