Skip to content

Commit

Permalink
Merge branch 'main' into feat/echo-server
Browse files Browse the repository at this point in the history
  • Loading branch information
Nishchit14 committed Aug 4, 2023
2 parents baa84df + 7a50389 commit 34fa6a3
Show file tree
Hide file tree
Showing 19 changed files with 1,016 additions and 481 deletions.
3 changes: 2 additions & 1 deletion packages/firecamp-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@
"@oclif/core": "^2.8.5",
"@oclif/plugin-help": "^5.2.9",
"@oclif/plugin-plugins": "^2.4.7",
"boxen": "^7.1.0",
"cli-table3": "^0.6.3",
"figlet": "^1.6.0",
"figures": "^5.0.0",
"fs-extra": "^11.1.1",
"kleur": "^4.1.5",
"load-json-file": "^7.0.1",
"ora": "^6.3.1",
"pretty-bytes": "^6.1.0",
"pretty-ms": "^8.0.0",
"react-fast-compare": "^3.2.2"
},
"devDependencies": {
Expand Down
104 changes: 104 additions & 0 deletions packages/firecamp-cli/src/commands/collection/run.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { Args, Command, Flags } from '@oclif/core'
import { loadJsonFile } from 'load-json-file';
import c from 'kleur';
import figlet from 'figlet'
//@ts-ignore https://github.com/egoist/tsup/issues/760
import Runner, { ERunnerEvents, IRunnerOptions } from '@firecamp/collection-runner'
import _RestExecutor from '@firecamp/rest-executor';
//@ts-ignore //TODO: rest-executor is commonjs lib while runner is esm. we'll move all lib in esm in future
const RestExecutor = _RestExecutor.default
import CliReporter from '../../reporters/cli.js'
/**
* Run command example
* ./bin/dev run ../../test/data/FirecampRestEchoServer.firecamp_collection.json
*/
export default class Run extends Command {
static description = 'Run Firecamp Collection'

static examples = [
'<%= config.bin %> <%= command.id %> ./echo.firecamp_collection.json',
]

static flags = {
'environment': Flags.string({ char: 'e', description: 'Provide a path to a Firecamp Environment file' }),
'globals': Flags.string({ char: 'g', description: 'Provide a path to a Firecamp Globals file' }),
'iteration-count': Flags.string({ char: 'n', description: 'Set the number of iterations for the collection run' }),
// 'iteration-data': Flags.string({ char: 'd', description: 'Provide the data file to be used for iterations. (should be JSON or CSV) file to use for iterations JSON or CSV' }),
'delay-request': Flags.integer({ description: 'Set the extent of delay between requests in milliseconds (default: 0)' }),
// timeout: Flags.integer({ description: 'Set a timeout for collection run in milliseconds (default: 0)' }),
// 'timeout-request': Flags.integer({ description: 'Set a timeout for requests in milliseconds (default: 0)' }),
}

static args = {
path: Args.string({ description: 'provide the collection path' }),
}

public async run(): Promise<void> {
const { args, flags } = await this.parse(Run)
const { path } = args
if (!path) {
this.logError('The collection path is missing')
return
}
const {
environment,
globals,
"iteration-count": iterationCount,
"iteration-data": iterationData,
timeout,
"delay-request": delayRequest,
"timeout-request": timeoutRequest,
} = flags;

// const _filepath = new URL(`../../../${path}`, import.meta.url).pathname
loadJsonFile(path)
.then(async (collection) => {

let envObj = { values: [] };
let globalObj = { values: [] };
if (environment) {
try {
envObj = await loadJsonFile(environment)
} catch (e: any) {
this.logError('could not load environment', e, 1)
}
}

if (globals) {
try {
globalObj = await loadJsonFile(globals)
} catch (e: any) {
this.logError('could not load globals', e);
}
}
// this.logJson(collection);
const options: IRunnerOptions = {
getExecutor: () => new RestExecutor(),
environment: envObj.values || [],
globals: globalObj.values || []
}
if (iterationCount) options.iterationCount = +iterationCount;
if (iterationData) options.iterationData = iterationData;
if (timeout) options.timeout = +timeout;
if (delayRequest) options.delayRequest = +delayRequest;
if (timeoutRequest) options.timeoutRequest = +timeoutRequest;

this.log(c.gray(figlet.textSync("Firecamp")));

const runner = new Runner(collection, options);
const emitter = runner.run()
new CliReporter(emitter);
})
.catch(e => {
// console.error(e)
if (e.code == 'ENOENT') this.logError(`Error: could not load collection file`, e, 1);
else this.logError('The collection file is not valid', null, 1);
})
}

logError(title: string, e?: any, exitCode?: number) {
if (title) this.logToStderr(`${c.red('Error')}: ${title}`);
if (e?.message) this.logToStderr(` `, e.message);
if (Number.isInteger(exitCode)) process.exit(exitCode);
}
}
79 changes: 0 additions & 79 deletions packages/firecamp-cli/src/commands/run.ts

This file was deleted.

49 changes: 0 additions & 49 deletions packages/firecamp-cli/src/commands/table.ts

This file was deleted.

79 changes: 0 additions & 79 deletions packages/firecamp-cli/src/helper/reporter.ts

This file was deleted.

Loading

0 comments on commit 34fa6a3

Please sign in to comment.