Update e2e tests

- Add new e2e group to samples which can be used
  with particular tests.
- Relates #401
This commit is contained in:
Janne Valkealahti
2022-05-15 16:29:48 +01:00
parent ee21619885
commit 7224ee31de
5 changed files with 484 additions and 2 deletions

View File

@@ -44,7 +44,7 @@ describe('builtin commands', () => {
/**
* fatjar commands
*/
describe(jarDesc, () => {
describe(jarDesc, () => {
beforeAll(() => {
command = jarCommand;
options = jarOptions;

View File

@@ -90,7 +90,7 @@ describe('flow commands', () => {
/**
* native commands
*/
describe(nativeDesc, () => {
describe(nativeDesc, () => {
beforeAll(() => {
command = nativeCommand;
options = [];

View File

@@ -0,0 +1,201 @@
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';
// e2e default value commands
describe('e2e commands default-value', () => {
let cli: Cli;
let command: string;
let options: string[] = [];
/**
* testDefaultValue
*/
const annoDefaultWithoutArgReturnsHiDesc = 'default without arg returns hi (anno)';
const annoDefaultWithoutArgCommand = ['e2e anno default-value'];
const annoDefaultWithoutArgReturnsHi = async (cli: Cli) => {
cli.run();
await waitForExpect(async () => {
const screen = cli.screen();
expect(screen).toEqual(expect.arrayContaining([expect.stringContaining('Hello hi')]));
});
await expect(cli.exitCode()).resolves.toBe(0);
};
/**
* testDefaultValueRegistration
*/
const regDefaultWithoutArgReturnsHiDesc = 'default without arg returns hi (reg)';
const regDefaultWithoutArgCommand = ['e2e reg default-value'];
const regOptionalWithoutArgReturnsHi = async (cli: Cli) => {
cli.run();
await waitForExpect(async () => {
const screen = cli.screen();
expect(screen).toEqual(expect.arrayContaining([expect.stringContaining('Hello hi')]));
});
await expect(cli.exitCode()).resolves.toBe(0);
};
/**
* testDefaultValue
*/
const annoDefaultWithArgReturnsFooDesc = 'default with arg returns foo (anno)';
const annoDefaultWithArgCommand = ['e2e anno default-value --arg1 foo'];
const annoDefaultWithArgReturnsFoo = async (cli: Cli) => {
cli.run();
await waitForExpect(async () => {
const screen = cli.screen();
expect(screen).toEqual(expect.arrayContaining([expect.stringContaining('Hello foo')]));
});
await expect(cli.exitCode()).resolves.toBe(0);
};
/**
* testDefaultValueRegistration
*/
const regDefaultWithArgReturnsFooDesc = 'default with arg returns foo (reg)';
const regDefaultWithArgCommand = ['e2e reg optional-value --arg1 foo'];
const regDefaultWithArgReturnsFoo = async (cli: Cli) => {
cli.run();
await waitForExpect(async () => {
const screen = cli.screen();
expect(screen).toEqual(expect.arrayContaining([expect.stringContaining('Hello foo')]));
});
await expect(cli.exitCode()).resolves.toBe(0);
};
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(
annoDefaultWithoutArgReturnsHiDesc,
async () => {
cli = new Cli({
command: command,
options: [...options, ...annoDefaultWithoutArgCommand]
});
await annoDefaultWithoutArgReturnsHi(cli);
},
testTimeout
);
it(
regDefaultWithoutArgReturnsHiDesc,
async () => {
cli = new Cli({
command: command,
options: [...options, ...regDefaultWithoutArgCommand]
});
await regOptionalWithoutArgReturnsHi(cli);
},
testTimeout
);
it(
annoDefaultWithArgReturnsFooDesc,
async () => {
cli = new Cli({
command: command,
options: [...options, ...annoDefaultWithArgCommand]
});
await annoDefaultWithArgReturnsFoo(cli);
},
testTimeout
);
it(
regDefaultWithArgReturnsFooDesc,
async () => {
cli = new Cli({
command: command,
options: [...options, ...regDefaultWithArgCommand]
});
await regDefaultWithArgReturnsFoo(cli);
},
testTimeout
);
});
/**
* native commands
*/
describe(nativeDesc, () => {
beforeAll(() => {
command = nativeCommand;
options = [];
});
it(
annoDefaultWithoutArgReturnsHiDesc,
async () => {
cli = new Cli({
command: command,
options: [...options, ...annoDefaultWithoutArgCommand]
});
await annoDefaultWithoutArgReturnsHi(cli);
},
testTimeout
);
it(
regDefaultWithoutArgReturnsHiDesc,
async () => {
cli = new Cli({
command: command,
options: [...options, ...regDefaultWithoutArgCommand]
});
await regOptionalWithoutArgReturnsHi(cli);
},
testTimeout
);
it(
annoDefaultWithArgReturnsFooDesc,
async () => {
cli = new Cli({
command: command,
options: [...options, ...annoDefaultWithArgCommand]
});
await annoDefaultWithArgReturnsFoo(cli);
},
testTimeout
);
it(
regDefaultWithArgReturnsFooDesc,
async () => {
cli = new Cli({
command: command,
options: [...options, ...regDefaultWithArgCommand]
});
await regDefaultWithArgReturnsFoo(cli);
},
testTimeout
);
});
});

View File

@@ -0,0 +1,201 @@
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';
// e2e optional value commands
describe('e2e commands optional-value', () => {
let cli: Cli;
let command: string;
let options: string[] = [];
/**
* testOptionalValue
*/
const annoOptionalWithoutArgReturnsNullDesc = 'optional without arg returns null (anno)';
const annoOptionalWithoutArgCommand = ['e2e anno optional-value'];
const annoOptionalWithoutArgReturnsNull = async (cli: Cli) => {
cli.run();
await waitForExpect(async () => {
const screen = cli.screen();
expect(screen).toEqual(expect.arrayContaining([expect.stringContaining('Hello null')]));
});
await expect(cli.exitCode()).resolves.toBe(0);
};
/**
* testOptionalValueRegistration
*/
const regOptionalWithoutArgReturnsNullDesc = 'optional without arg returns null (reg)';
const regOptionalWithoutArgCommand = ['e2e reg optional-value'];
const regOptionalWithoutArgReturnsNull = async (cli: Cli) => {
cli.run();
await waitForExpect(async () => {
const screen = cli.screen();
expect(screen).toEqual(expect.arrayContaining([expect.stringContaining('Hello null')]));
});
await expect(cli.exitCode()).resolves.toBe(0);
};
/**
* testOptionalValue
*/
const annoOptionalWithArgReturnsNullDesc = 'optional with arg returns hi (anno)';
const annoOptionalWithArgCommand = ['e2e anno optional-value --arg1 hi'];
const annoOptionalWithArgReturnsNull = async (cli: Cli) => {
cli.run();
await waitForExpect(async () => {
const screen = cli.screen();
expect(screen).toEqual(expect.arrayContaining([expect.stringContaining('Hello hi')]));
});
await expect(cli.exitCode()).resolves.toBe(0);
};
/**
* testOptionalValueRegistration
*/
const regOptionalWithArgReturnsHiDesc = 'optional with arg returns hi (reg)';
const regOptionalWithArgCommand = ['e2e reg optional-value --arg1 hi'];
const regOptionalWithArgReturnsHi = async (cli: Cli) => {
cli.run();
await waitForExpect(async () => {
const screen = cli.screen();
expect(screen).toEqual(expect.arrayContaining([expect.stringContaining('Hello hi')]));
});
await expect(cli.exitCode()).resolves.toBe(0);
};
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(
annoOptionalWithoutArgReturnsNullDesc,
async () => {
cli = new Cli({
command: command,
options: [...options, ...annoOptionalWithoutArgCommand]
});
await annoOptionalWithoutArgReturnsNull(cli);
},
testTimeout
);
it(
regOptionalWithoutArgReturnsNullDesc,
async () => {
cli = new Cli({
command: command,
options: [...options, ...regOptionalWithoutArgCommand]
});
await regOptionalWithoutArgReturnsNull(cli);
},
testTimeout
);
it(
annoOptionalWithArgReturnsNullDesc,
async () => {
cli = new Cli({
command: command,
options: [...options, ...annoOptionalWithArgCommand]
});
await annoOptionalWithArgReturnsNull(cli);
},
testTimeout
);
it(
regOptionalWithArgReturnsHiDesc,
async () => {
cli = new Cli({
command: command,
options: [...options, ...regOptionalWithArgCommand]
});
await regOptionalWithArgReturnsHi(cli);
},
testTimeout
);
});
/**
* native commands
*/
describe(nativeDesc, () => {
beforeAll(() => {
command = nativeCommand;
options = [];
});
it(
annoOptionalWithoutArgReturnsNullDesc,
async () => {
cli = new Cli({
command: command,
options: [...options, ...annoOptionalWithoutArgCommand]
});
await annoOptionalWithoutArgReturnsNull(cli);
},
testTimeout
);
it(
regOptionalWithoutArgReturnsNullDesc,
async () => {
cli = new Cli({
command: command,
options: [...options, ...regOptionalWithoutArgCommand]
});
await regOptionalWithoutArgReturnsNull(cli);
},
testTimeout
);
it(
annoOptionalWithArgReturnsNullDesc,
async () => {
cli = new Cli({
command: command,
options: [...options, ...annoOptionalWithArgCommand]
});
await annoOptionalWithArgReturnsNull(cli);
},
testTimeout
);
it(
regOptionalWithArgReturnsHiDesc,
async () => {
cli = new Cli({
command: command,
options: [...options, ...regOptionalWithArgCommand]
});
await regOptionalWithArgReturnsHi(cli);
},
testTimeout
);
});
});

View File

@@ -0,0 +1,80 @@
/*
* Copyright 2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.shell.samples.standard;
import org.springframework.context.annotation.Bean;
import org.springframework.shell.command.CommandRegistration;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
import org.springframework.shell.standard.ShellOption;
/**
* Commands used for e2e test.
*
* @author Janne Valkealahti
*/
@ShellComponent
public class E2ECommands {
@ShellMethod(key = "e2e anno optional-value")
public String testOptionalValue(
@ShellOption(defaultValue = ShellOption.NULL) String arg1
) {
return "Hello " + arg1;
}
@Bean
public CommandRegistration testOptionalValueRegistration() {
return CommandRegistration.builder()
.command("e2e", "reg", "optional-value")
.group("E2E Commands")
.withOption()
.longNames("arg1")
.and()
.withTarget()
.function(ctx -> {
String arg1 = ctx.getOptionValue("arg1");
return "Hello " + arg1;
})
.and()
.build();
}
@ShellMethod(key = "e2e anno default-value")
public String testDefaultValue(
@ShellOption(defaultValue = "hi") String arg1
) {
return "Hello " + arg1;
}
@Bean
public CommandRegistration testDefaultValueRegistration() {
return CommandRegistration.builder()
.command("e2e", "reg", "default-value")
.group("E2E Commands")
.withOption()
.longNames("arg1")
.defaultValue("hi")
.and()
.withTarget()
.function(ctx -> {
String arg1 = ctx.getOptionValue("arg1");
return "Hello " + arg1;
})
.and()
.build();
}
}