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

1
e2e/spring-shell-e2e-tests/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
node_modules

View File

@@ -0,0 +1,5 @@
# dont care about typings
types/
# for test data
test/data/

View File

@@ -0,0 +1,11 @@
{
"printWidth": 120,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": true,
"arrowParens": "avoid",
"parser": "typescript"
}

View File

@@ -0,0 +1,12 @@
module.exports = {
clearMocks: true,
moduleFileExtensions: ['js', 'ts'],
testEnvironment: 'node',
testMatch: ['**/*.test.ts'],
testRunner: 'jest-circus/runner',
transform: {
'^.+\\.ts$': 'ts-jest'
},
verbose: true,
setupFilesAfterEnv: ['jest-extended', '@alex_neo/jest-expect-message']
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,39 @@
{
"name": "spring-shell-e2e-tests",
"version": "2.1.0",
"description": "e2e tests for spring-shell",
"main": "index.js",
"scripts": {
"format": "prettier --write **/*.ts",
"format-check": "prettier --check **/*.ts",
"test": "jest"
},
"repository": {
"type": "git",
"url": "git+https://github.com/spring-projects/spring-shell.git"
},
"author": "",
"license": "MIT",
"bugs": {
"url": "https://github.com/spring-projects/spring-shell/issues"
},
"homepage": "https://github.com/spring-projects/spring-shell",
"devDependencies": {
"@actions/io": "^1.1.2",
"@alex_neo/jest-expect-message": "^1.0.5",
"@types/jest": "^27.4.1",
"@types/jest-expect-message": "^1.0.3",
"@types/lodash": "^4.14.172",
"@types/node": "^15.6.0",
"jest": "^27.5.1",
"jest-circus": "^27.5.1",
"jest-extended": "^2.0.0",
"prettier": "^2.3.0",
"ts-jest": "^27.1.3",
"typescript": "^4.6.2",
"wait-for-expect": "^3.0.2"
},
"dependencies": {
"spring-shell-e2e": "file:../spring-shell-e2e"
}
}

View File

@@ -0,0 +1,18 @@
import * as os from 'os';
import * as path from 'path';
export const tempDir = path.join(__dirname, 'spring-shell', 'temp');
export const isWindows = os.platform() === 'win32';
export const cliPathRelative = isWindows
? '..\\..\\spring-shell-samples\\target\\spring-shell-samples.exe'
: '../../spring-shell-samples/target/spring-shell-samples';
export const jarPathRelative = isWindows
? '..\\..\\spring-shell-samples\\target\\spring-shell-samples-2.1.0-SNAPSHOT-exec.jar'
: '../../spring-shell-samples/target/spring-shell-samples-2.1.0-SNAPSHOT-exec.jar';
export const cliPath = path.resolve(cliPathRelative);
export const jarPath = path.resolve(jarPathRelative);
export const nativeDesc = 'native';
export const jarDesc = 'jar';
export const jarCommand = 'java';
export const nativeCommand = cliPath;
export const jarOptions = ['-jar', jarPath];

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);
});
});
});

View File

@@ -0,0 +1,19 @@
{
"compilerOptions": {
"target": "es2019",
"module": "commonjs",
"outDir": "./lib",
"rootDirs": ["./src", "./test"],
"strict": true,
"baseUrl": ".",
"noImplicitAny": false,
"paths": {
"*": ["./types/*"]
},
"esModuleInterop": true,
"lib": [
"es2019"
]
},
"exclude": ["node_modules", "**/*.test.ts"]
}