From c7fc40be730a5a3617ad6c75cdb75cffc3c5ce76 Mon Sep 17 00:00:00 2001 From: vigneshshanmugam Date: Wed, 30 Jun 2021 20:30:16 -0700 Subject: [PATCH] fix: support --json flag for heartbeat 7.13 --- __tests__/cli.test.ts | 22 ++++++++++++---------- src/parse_args.ts | 1 + 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/__tests__/cli.test.ts b/__tests__/cli.test.ts index 1c5ec39d..c94c912f 100644 --- a/__tests__/cli.test.ts +++ b/__tests__/cli.test.ts @@ -41,19 +41,21 @@ describe('CLI', () => { expect(await cli.exitCode).toBe(1); }); - it('produce json output via --json flag', async () => { - const cli = new CLIMock([ - join(FIXTURES_DIR, 'fake.journey.ts'), - '--reporter', - 'json', - ]); - await cli.waitFor('fake journey'); - const output = cli.output(); - expect(JSON.parse(output).journey).toEqual({ + it('produce json output --json and reporter=json flag', async () => { + const output = async args => { + const cli = new CLIMock([join(FIXTURES_DIR, 'fake.journey.ts'), ...args]); + await cli.waitFor('fake journey'); + expect(await cli.exitCode).toBe(0); + return JSON.parse(cli.output()); + }; + expect((await output(['--reporter', 'json'])).journey).toEqual({ + id: 'fake journey', + name: 'fake journey', + }); + expect((await output(['--json'])).journey).toEqual({ id: 'fake journey', name: 'fake journey', }); - expect(await cli.exitCode).toBe(0); }); it('mimick heartbeat with `--rich-events` flag', async () => { diff --git a/src/parse_args.ts b/src/parse_args.ts index 48044a93..f6e98a07 100644 --- a/src/parse_args.ts +++ b/src/parse_args.ts @@ -38,6 +38,7 @@ program 'configuration path (default: synthetics.config.js)' ) .option('-s, --suite-params ', 'suite variables', '{}') + .option('-j, --json', 'output newline delimited JSON') .addOption( new Option('--reporter ', `output repoter format`).choices( Object.keys(reporters)