From b0897763df4147e6c946589df8be8620b2b1cb2e Mon Sep 17 00:00:00 2001 From: Pawfa Date: Wed, 14 Apr 2021 11:26:00 +0200 Subject: [PATCH] feat: Argument outFile takes an extension --- README.md | 4 ++-- src/utils/define-args.ts | 2 +- src/utils/write-report.ts | 2 +- test/run.test.ts | 7 ++++++- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c387f03..6d2e365 100644 --- a/README.md +++ b/README.md @@ -49,13 +49,13 @@ $ judge-d verify --help ``` ``` -Verify contracts +It verifies contracts and generates HTML report if outFile is provided Options: --url Url to judge-d instance [string] [required] --serviceName Service name [string] [required] --serviceVersion Service version [string] [required] --environment Environment name [string] [required] - --outFile Path with HTML report filename [string] + --outFile Path with HTML report filename, ex. report.html [string] ``` diff --git a/src/utils/define-args.ts b/src/utils/define-args.ts index cdf8b72..b9edb5a 100644 --- a/src/utils/define-args.ts +++ b/src/utils/define-args.ts @@ -61,7 +61,7 @@ export function defineArgs( }, outFile: { type: 'string', - describe: 'Path with HTML report filename', + describe: 'Path with HTML report filename, ex. report.html', }, }); }) diff --git a/src/utils/write-report.ts b/src/utils/write-report.ts index 41d24aa..3cc3ec2 100644 --- a/src/utils/write-report.ts +++ b/src/utils/write-report.ts @@ -6,5 +6,5 @@ export function writeReport(outFile: string, htmlReport: string) { if (!fs.existsSync(pathToReportDir)) { fs.mkdirSync(pathToReportDir, { recursive: true }); } - fs.writeFileSync(`${outFile}.html`, htmlReport); + fs.writeFileSync(outFile, htmlReport); } diff --git a/test/run.test.ts b/test/run.test.ts index d708903..32fefc1 100644 --- a/test/run.test.ts +++ b/test/run.test.ts @@ -68,6 +68,7 @@ describe('run', () => { mocked(axios.get).mockResolvedValueOnce({ data: validationResultsMock, }); + mocked(ejs.renderFile).mockResolvedValueOnce('report content'); const processMock = processMockFactory.build({ argv: [ @@ -83,7 +84,7 @@ describe('run', () => { '--environment', 'DEMO', '--outFile', - './report/dredd/contract-tests-report', + './report/dredd/contract-tests-report.html', ], }); @@ -104,6 +105,10 @@ describe('run', () => { expect(ejs.renderFile).toHaveBeenCalledWith(pathToTemplate, { validationResults: validationResultsMock, }); + expect(fs.writeFileSync).toHaveBeenCalledWith( + './report/dredd/contract-tests-report.html', + 'report content' + ); expect(processMock.exit).not.toHaveBeenCalled(); });