Skip to content

Commit

Permalink
test: add command to get command list
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasgmagalhaes committed May 19, 2023
1 parent 0379652 commit 2d68aee
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 18 deletions.
8 changes: 7 additions & 1 deletion e2e/README.md
Expand Up @@ -12,7 +12,13 @@ yarn e2e
Repeating, this is a slower testing process, to testing only what you want run:

```shell
yarn jest ./e2e/toReturn --config=./e2e/jest.config.ts
yarn e2e --file
```

To list all files run:

```shell
yarn e2e --list
```

### Tests structure
Expand Down
10 changes: 6 additions & 4 deletions e2e/and/test1.spec.ts
Expand Up @@ -2,9 +2,11 @@

describe("testing todoInCascade", () => {
it("test should pass", async () => {
await command("sendMultiple 829873348309155851")
.should.respond("hello")
.and.inChannel("829873348309155851")
.respond("hello2");
// await command("sendMultiple 829873348309155851")
// .should.respond("hello")
// .and.inChannel("829873348309155851")
// .respond("hello2");

await command("hello").should.respond("Hello!!").and.respond("Hello!!");
});
});
18 changes: 13 additions & 5 deletions e2e/pipeline.ts
Expand Up @@ -37,8 +37,9 @@ function buildProject() {

async function main() {
console.log(`Environment: ${chalk.cyan(testUtils.env())}`);
const isToListFiles = process.argv.includes("--list");

if (shouldBuild()) {
if (!isToListFiles && shouldBuild()) {
console.log("Building project... ");
buildProject();
console.log("Done\n");
Expand All @@ -48,9 +49,11 @@ async function main() {

let exitCode = 0;
let _testsPass = true;
console.log(chalk.cyanBright("logging example bot..."));

await login();
if (!isToListFiles) {
console.log(chalk.cyanBright("logging example bot..."));
await login();
}

try {
console.log(chalk.green(" Done\n"));
Expand All @@ -60,7 +63,12 @@ async function main() {
.filter((el: any) => !isNaN(el));

const timer = new Stopwatch();
for (const [fileObj, testFn] of generator) {
for (const [fileObj, command, testFn] of generator) {
if (isToListFiles) {
process.stdout.write(`${command}\n`);
continue;
}

if (selectedTests.length === 0 || selectedTests.includes(fileObj.id.toString())) {
timer.start();
const output = await testFn();
Expand Down Expand Up @@ -91,7 +99,7 @@ async function main() {
exitCode = 1;
} finally {
console.log("\n");
if (_testsPass) {
if (_testsPass && !isToListFiles) {
console.log(`${chalk.bgGreen(" SUCCESS ")}: All tests passed`);
}
}
Expand Down
22 changes: 16 additions & 6 deletions e2e/testUtils.ts
Expand Up @@ -56,12 +56,7 @@ namespace testUtils {
*/
export function runCLI(command: string, setConfig = true) {
return new Promise<CliOutput>((resolve) => {
const con = `node ./bin/corde ${
setConfig ? "--config ./e2e/corde.config.ts" : ""
} ${command}`;

// con += " ";
// con += testUtils.env();
const con = injectCommand(command, setConfig);

process.stdout.write(`Running: ${chalk.magenta(con)}`);

Expand All @@ -71,6 +66,21 @@ namespace testUtils {
});
}

/**
* @internal
*/
export function buildCommand(folderName: string, testFileName: string) {
const preCommand = buildCommandWithConfigPath(folderName, testFileName);
return injectCommand(preCommand);
}

/**
* @internal
*/
export function injectCommand(preCommand: string, setConfig = true) {
return `node ./bin/corde ${setConfig ? "--config ./e2e/corde.config.ts" : ""} ${preCommand}`;
}

// Duplicated code from ../tests/testHelper
// Due to jest types not being found in e2e folder (and can not to avoid types conflict)

Expand Down
5 changes: 3 additions & 2 deletions e2e/tests.ts
Expand Up @@ -5,21 +5,22 @@ import testUtils from "./testUtils";
import { CliOutput, ITestFile, TestModule } from "./types";

function* createTestFunctionsGenerator(): Generator<
[ITestFile, () => Promise<CliOutput>],
[ITestFile, string, () => Promise<CliOutput>],
void,
unknown
> {
for (const testCase of testCases) {
const command = testUtils.buildCommand(testCase.folder, testCase.testFile);
yield [
testCase,
command,
async () => {
if (testCase.isRequiredFunction) {
const module: TestModule = await import(
path.resolve(process.cwd(), "./e2e", testCase.folder, testCase.testFile)
);
return module.testFn();
}
const command = testUtils.buildCommandWithConfigPath(testCase.folder, testCase.testFile);
return testUtils.runCLI(command);
},
];
Expand Down

0 comments on commit 2d68aee

Please sign in to comment.