|
| 1 | +import 'jest-extended'; |
| 2 | +import waitForExpect from 'wait-for-expect'; |
| 3 | +import { Cli } from 'spring-shell-e2e'; |
| 4 | +import { |
| 5 | + nativeDesc, |
| 6 | + jarDesc, |
| 7 | + jarCommand, |
| 8 | + nativeCommand, |
| 9 | + jarOptions, |
| 10 | + waitForExpectDefaultTimeout, |
| 11 | + waitForExpectDefaultInterval, |
| 12 | + testTimeout |
| 13 | +} from '../src/utils'; |
| 14 | + |
| 15 | +// e2e default value commands |
| 16 | +describe('e2e commands default-value', () => { |
| 17 | + let cli: Cli; |
| 18 | + let command: string; |
| 19 | + let options: string[] = []; |
| 20 | + |
| 21 | + /** |
| 22 | + * testDefaultValue |
| 23 | + */ |
| 24 | + const annoDefaultWithoutArgReturnsHiDesc = 'default without arg returns hi (anno)'; |
| 25 | + const annoDefaultWithoutArgCommand = ['e2e anno default-value']; |
| 26 | + const annoDefaultWithoutArgReturnsHi = async (cli: Cli) => { |
| 27 | + cli.run(); |
| 28 | + await waitForExpect(async () => { |
| 29 | + const screen = cli.screen(); |
| 30 | + expect(screen).toEqual(expect.arrayContaining([expect.stringContaining('Hello hi')])); |
| 31 | + }); |
| 32 | + await expect(cli.exitCode()).resolves.toBe(0); |
| 33 | + }; |
| 34 | + |
| 35 | + /** |
| 36 | + * testDefaultValueRegistration |
| 37 | + */ |
| 38 | + const regDefaultWithoutArgReturnsHiDesc = 'default without arg returns hi (reg)'; |
| 39 | + const regDefaultWithoutArgCommand = ['e2e reg default-value']; |
| 40 | + const regOptionalWithoutArgReturnsHi = async (cli: Cli) => { |
| 41 | + cli.run(); |
| 42 | + await waitForExpect(async () => { |
| 43 | + const screen = cli.screen(); |
| 44 | + expect(screen).toEqual(expect.arrayContaining([expect.stringContaining('Hello hi')])); |
| 45 | + }); |
| 46 | + await expect(cli.exitCode()).resolves.toBe(0); |
| 47 | + }; |
| 48 | + |
| 49 | + /** |
| 50 | + * testDefaultValue |
| 51 | + */ |
| 52 | + const annoDefaultWithArgReturnsFooDesc = 'default with arg returns foo (anno)'; |
| 53 | + const annoDefaultWithArgCommand = ['e2e anno default-value --arg1 foo']; |
| 54 | + const annoDefaultWithArgReturnsFoo = async (cli: Cli) => { |
| 55 | + cli.run(); |
| 56 | + await waitForExpect(async () => { |
| 57 | + const screen = cli.screen(); |
| 58 | + expect(screen).toEqual(expect.arrayContaining([expect.stringContaining('Hello foo')])); |
| 59 | + }); |
| 60 | + await expect(cli.exitCode()).resolves.toBe(0); |
| 61 | + }; |
| 62 | + |
| 63 | + /** |
| 64 | + * testDefaultValueRegistration |
| 65 | + */ |
| 66 | + const regDefaultWithArgReturnsFooDesc = 'default with arg returns foo (reg)'; |
| 67 | + const regDefaultWithArgCommand = ['e2e reg optional-value --arg1 foo']; |
| 68 | + const regDefaultWithArgReturnsFoo = async (cli: Cli) => { |
| 69 | + cli.run(); |
| 70 | + await waitForExpect(async () => { |
| 71 | + const screen = cli.screen(); |
| 72 | + expect(screen).toEqual(expect.arrayContaining([expect.stringContaining('Hello foo')])); |
| 73 | + }); |
| 74 | + await expect(cli.exitCode()).resolves.toBe(0); |
| 75 | + }; |
| 76 | + |
| 77 | + beforeEach(async () => { |
| 78 | + waitForExpect.defaults.timeout = waitForExpectDefaultTimeout; |
| 79 | + waitForExpect.defaults.interval = waitForExpectDefaultInterval; |
| 80 | + }, testTimeout); |
| 81 | + |
| 82 | + afterEach(async () => { |
| 83 | + cli?.dispose(); |
| 84 | + }, testTimeout); |
| 85 | + |
| 86 | + /** |
| 87 | + * fatjar commands |
| 88 | + */ |
| 89 | + describe(jarDesc, () => { |
| 90 | + beforeAll(() => { |
| 91 | + command = jarCommand; |
| 92 | + options = jarOptions; |
| 93 | + }); |
| 94 | + |
| 95 | + it( |
| 96 | + annoDefaultWithoutArgReturnsHiDesc, |
| 97 | + async () => { |
| 98 | + cli = new Cli({ |
| 99 | + command: command, |
| 100 | + options: [...options, ...annoDefaultWithoutArgCommand] |
| 101 | + }); |
| 102 | + await annoDefaultWithoutArgReturnsHi(cli); |
| 103 | + }, |
| 104 | + testTimeout |
| 105 | + ); |
| 106 | + |
| 107 | + it( |
| 108 | + regDefaultWithoutArgReturnsHiDesc, |
| 109 | + async () => { |
| 110 | + cli = new Cli({ |
| 111 | + command: command, |
| 112 | + options: [...options, ...regDefaultWithoutArgCommand] |
| 113 | + }); |
| 114 | + await regOptionalWithoutArgReturnsHi(cli); |
| 115 | + }, |
| 116 | + testTimeout |
| 117 | + ); |
| 118 | + |
| 119 | + it( |
| 120 | + annoDefaultWithArgReturnsFooDesc, |
| 121 | + async () => { |
| 122 | + cli = new Cli({ |
| 123 | + command: command, |
| 124 | + options: [...options, ...annoDefaultWithArgCommand] |
| 125 | + }); |
| 126 | + await annoDefaultWithArgReturnsFoo(cli); |
| 127 | + }, |
| 128 | + testTimeout |
| 129 | + ); |
| 130 | + |
| 131 | + it( |
| 132 | + regDefaultWithArgReturnsFooDesc, |
| 133 | + async () => { |
| 134 | + cli = new Cli({ |
| 135 | + command: command, |
| 136 | + options: [...options, ...regDefaultWithArgCommand] |
| 137 | + }); |
| 138 | + await regDefaultWithArgReturnsFoo(cli); |
| 139 | + }, |
| 140 | + testTimeout |
| 141 | + ); |
| 142 | + }); |
| 143 | + |
| 144 | + /** |
| 145 | + * native commands |
| 146 | + */ |
| 147 | + describe(nativeDesc, () => { |
| 148 | + beforeAll(() => { |
| 149 | + command = nativeCommand; |
| 150 | + options = []; |
| 151 | + }); |
| 152 | + |
| 153 | + it( |
| 154 | + annoDefaultWithoutArgReturnsHiDesc, |
| 155 | + async () => { |
| 156 | + cli = new Cli({ |
| 157 | + command: command, |
| 158 | + options: [...options, ...annoDefaultWithoutArgCommand] |
| 159 | + }); |
| 160 | + await annoDefaultWithoutArgReturnsHi(cli); |
| 161 | + }, |
| 162 | + testTimeout |
| 163 | + ); |
| 164 | + |
| 165 | + it( |
| 166 | + regDefaultWithoutArgReturnsHiDesc, |
| 167 | + async () => { |
| 168 | + cli = new Cli({ |
| 169 | + command: command, |
| 170 | + options: [...options, ...regDefaultWithoutArgCommand] |
| 171 | + }); |
| 172 | + await regOptionalWithoutArgReturnsHi(cli); |
| 173 | + }, |
| 174 | + testTimeout |
| 175 | + ); |
| 176 | + |
| 177 | + it( |
| 178 | + annoDefaultWithArgReturnsFooDesc, |
| 179 | + async () => { |
| 180 | + cli = new Cli({ |
| 181 | + command: command, |
| 182 | + options: [...options, ...annoDefaultWithArgCommand] |
| 183 | + }); |
| 184 | + await annoDefaultWithArgReturnsFoo(cli); |
| 185 | + }, |
| 186 | + testTimeout |
| 187 | + ); |
| 188 | + |
| 189 | + it( |
| 190 | + regDefaultWithArgReturnsFooDesc, |
| 191 | + async () => { |
| 192 | + cli = new Cli({ |
| 193 | + command: command, |
| 194 | + options: [...options, ...regDefaultWithArgCommand] |
| 195 | + }); |
| 196 | + await regDefaultWithArgReturnsFoo(cli); |
| 197 | + }, |
| 198 | + testTimeout |
| 199 | + ); |
| 200 | + }); |
| 201 | +}); |
0 commit comments