Initial attempt for e2e tests

- Add node code for e2e tests. This is a first take to try running
  these tests via actions.
- Relates to #401
This commit is contained in:
Janne Valkealahti
2022-05-06 13:41:10 +01:00
parent 8a23518b84
commit 3743a7f32d
17 changed files with 6844 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
import 'jest-extended';
import waitForExpect from 'wait-for-expect';
import { Cli } from 'spring-shell-e2e';
import { nativeDesc, jarDesc, jarCommand, nativeCommand, jarOptions } from '../src/utils';
// all buildin commands
describe('builtin commands', () => {
let cli: Cli;
let command: string;
let options: string[] = [];
/**
* test for version command returns expected info
*/
const versionReturnsInfoDesc = 'version returns info';
const versionCommand = ['version'];
const versionReturnsInfo = async (cli: Cli) => {
cli.run();
await waitForExpect(async () => {
const screen = cli.screen();
expect(screen).toEqual(expect.arrayContaining([expect.stringContaining('Build Version')]));
});
await expect(cli.exitCode()).resolves.toBe(0);
};
beforeEach(async () => {
waitForExpect.defaults.timeout = 3000;
waitForExpect.defaults.interval = 100;
}, 300000);
afterEach(async () => {
cli?.dispose();
}, 100000);
/**
* native commands
*/
describe(nativeDesc, () => {
beforeAll(() => {
command = nativeCommand;
});
it(versionReturnsInfoDesc, async () => {
cli = new Cli({
command: command,
options: [...options, ...versionCommand]
});
await versionReturnsInfo(cli);
});
});
/**
* fatjar commands
*/
describe(jarDesc, () => {
beforeAll(() => {
command = jarCommand;
options = jarOptions;
});
it(versionReturnsInfoDesc, async () => {
cli = new Cli({
command: command,
options: [...options, ...versionCommand]
});
await versionReturnsInfo(cli);
});
});
});

View File

@@ -0,0 +1,91 @@
import 'jest-extended';
import waitForExpect from 'wait-for-expect';
import { Cli } from 'spring-shell-e2e';
import { nativeDesc, jarDesc, jarCommand, nativeCommand, jarOptions } from '../src/utils';
// all flow commands
describe('flow commands', () => {
let cli: Cli;
let command: string;
let options: string[] = [];
/**
* test for flow conditional field2 skips field1
*/
const flowConditionalField2SkipsFields1Desc = 'flow conditional field2 skips field1';
const flowConditionalCommand = ['flow', 'conditional'];
const flowConditionalField2SkipsFields1 = async (cli: Cli) => {
cli.run();
await waitForExpect(async () => {
const screen = cli.screen();
expect(screen).toEqual(expect.arrayContaining([expect.stringContaining('Single1')]));
});
await cli.keyDown();
await waitForExpect(async () => {
const screen = cli.screen();
expect(screen).toEqual(expect.arrayContaining([expect.stringContaining('> Field2')]));
});
await cli.keyEnter();
await waitForExpect(async () => {
const screen = cli.screen();
expect(screen).toEqual(
expect.arrayContaining([expect.stringContaining('? Field2 [Default defaultField2Value]')])
);
});
await cli.keyEnter();
await waitForExpect(async () => {
const screen = cli.screen();
expect(screen).toEqual(expect.arrayContaining([expect.stringContaining('Field2 defaultField2Value')]));
});
await expect(cli.exitCode()).resolves.toBe(0);
};
beforeEach(async () => {
waitForExpect.defaults.timeout = 3000;
waitForExpect.defaults.interval = 100;
}, 300000);
afterEach(async () => {
cli?.dispose();
}, 100000);
/**
* native commands
*/
describe(nativeDesc, () => {
beforeAll(() => {
command = nativeCommand;
});
it(flowConditionalField2SkipsFields1Desc, async () => {
cli = new Cli({
command: command,
options: [...options, ...flowConditionalCommand]
});
await flowConditionalField2SkipsFields1(cli);
});
});
/**
* fatjar commands
*/
describe(jarDesc, () => {
beforeAll(() => {
command = jarCommand;
options = jarOptions;
});
it(flowConditionalField2SkipsFields1Desc, async () => {
cli = new Cli({
command: command,
options: [...options, ...flowConditionalCommand]
});
await flowConditionalField2SkipsFields1(cli);
});
});
});