From 0e37989a6f4b6244ed5fc71f3bed506b335d9bb4 Mon Sep 17 00:00:00 2001 From: Janne Valkealahti Date: Thu, 2 Jun 2022 09:58:16 +0100 Subject: [PATCH] e2e test for required option value --- .../test/sample-e2e-required-value.test.ts | 118 ++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 e2e/spring-shell-e2e-tests/test/sample-e2e-required-value.test.ts diff --git a/e2e/spring-shell-e2e-tests/test/sample-e2e-required-value.test.ts b/e2e/spring-shell-e2e-tests/test/sample-e2e-required-value.test.ts new file mode 100644 index 00000000..dad30998 --- /dev/null +++ b/e2e/spring-shell-e2e-tests/test/sample-e2e-required-value.test.ts @@ -0,0 +1,118 @@ +import 'jest-extended'; +import waitForExpect from 'wait-for-expect'; +import { Cli } from 'spring-shell-e2e'; +import { + nativeDesc, + jarDesc, + jarCommand, + nativeCommand, + jarOptions, + waitForExpectDefaultTimeout, + waitForExpectDefaultInterval, + testTimeout +} from '../src/utils'; + +describe('e2e commands required-value', () => { + let cli: Cli; + let command: string; + let options: string[] = []; + + const annoRequiredWithoutArgReturnsErrorDesc = 'required without arg returns error (anno)'; + const annoRequiredWithoutArgCommand = ['e2e anno required-value']; + const annoRequiredWithoutArgReturnsError = async (cli: Cli) => { + cli.run(); + await waitForExpect(async () => { + const screen = cli.screen(); + expect(screen).toEqual(expect.arrayContaining([expect.stringContaining('Missing option')])); + }); + await expect(cli.exitCode()).resolves.toBe(2); + }; + + const regRequiredWithoutArgReturnsErrorDesc = 'required without arg returns error (reg)'; + const regRequiredWithoutArgCommand = ['e2e reg required-value']; + const regRequiredWithoutArgReturnsError = async (cli: Cli) => { + cli.run(); + await waitForExpect(async () => { + const screen = cli.screen(); + expect(screen).toEqual(expect.arrayContaining([expect.stringContaining('Missing option')])); + }); + await expect(cli.exitCode()).resolves.toBe(2); + }; + + beforeEach(async () => { + waitForExpect.defaults.timeout = waitForExpectDefaultTimeout; + waitForExpect.defaults.interval = waitForExpectDefaultInterval; + }, testTimeout); + + afterEach(async () => { + cli?.dispose(); + }, testTimeout); + + /** + * fatjar commands + */ + describe(jarDesc, () => { + beforeAll(() => { + command = jarCommand; + options = jarOptions; + }); + + it( + annoRequiredWithoutArgReturnsErrorDesc, + async () => { + cli = new Cli({ + command: command, + options: [...options, ...annoRequiredWithoutArgCommand] + }); + await annoRequiredWithoutArgReturnsError(cli); + }, + testTimeout + ); + + it( + regRequiredWithoutArgReturnsErrorDesc, + async () => { + cli = new Cli({ + command: command, + options: [...options, ...regRequiredWithoutArgCommand] + }); + await regRequiredWithoutArgReturnsError(cli); + }, + testTimeout + ); + }); + + /** + * native commands + */ + describe(nativeDesc, () => { + beforeAll(() => { + command = nativeCommand; + options = []; + }); + + it( + annoRequiredWithoutArgReturnsErrorDesc, + async () => { + cli = new Cli({ + command: command, + options: [...options, ...annoRequiredWithoutArgCommand] + }); + await annoRequiredWithoutArgReturnsError(cli); + }, + testTimeout + ); + + it( + regRequiredWithoutArgReturnsErrorDesc, + async () => { + cli = new Cli({ + command: command, + options: [...options, ...regRequiredWithoutArgCommand] + }); + await regRequiredWithoutArgReturnsError(cli); + }, + testTimeout + ); + }); +});