Skip to content

Commit

Permalink
feat: New singlePrefix option
Browse files Browse the repository at this point in the history
start indexing into test cases at root levle
  • Loading branch information
timbrinded committed May 13, 2024
1 parent 052e6c0 commit c83cfa5
Show file tree
Hide file tree
Showing 16 changed files with 137 additions and 20 deletions.
20 changes: 17 additions & 3 deletions packages/cli/src/cmds/entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ yargs(hideBin(process.argv))
await runNetworkCmd(argv);
}
)
.command<{ suitesRootDir: string; prefixPhrase?: string }>(
.command<{
suitesRootDir: string;
prefixPhrase?: string;
singlePrefix: boolean;
}>(
"derive <suitesRootDir>",
"Derive test IDs based on positional order in the directory tree",
(yargs) => {
Expand All @@ -141,10 +145,20 @@ yargs(hideBin(process.argv))
describe: "Root phrase to generate prefixes from (e.g. DEV)",
alias: "p",
type: "string",
})
.option("singlePrefix", {
describe: "Use a single prefix for all suites, instead of deriving from folder names",
alias: "l",
default: false,
type: "boolean",
});
},
async ({ suitesRootDir, prefixPhrase }) => {
await deriveTestIds({ rootDir: suitesRootDir, prefixPhrase });
async ({ suitesRootDir, prefixPhrase, singlePrefix }) => {
await deriveTestIds({
rootDir: suitesRootDir,
prefixPhrase,
singlePrefix,
});
}
)
.demandCommand(1)
Expand Down
16 changes: 10 additions & 6 deletions packages/cli/src/internal/deriveTestIds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ import path from "node:path";

interface DeriveTestIdsOptions {
rootDir: string;
prefixDepth?: number;
singlePrefix?: boolean;
prefixPhrase?: string;
}

export async function deriveTestIds(params: DeriveTestIdsOptions) {
const usedPrefixes: Set<string> = new Set();

const { rootDir } = params;
const prefixDepth = params.prefixDepth ?? 1;
const { rootDir, singlePrefix } = params;

try {
await fs.promises.access(rootDir, fs.constants.R_OK);
Expand All @@ -29,9 +28,14 @@ export async function deriveTestIds(params: DeriveTestIdsOptions) {

const foldersToRename: { prefix: string; dir: string }[] = [];

for (const dir of topLevelDirs) {
const prefix = generatePrefix(dir, usedPrefixes, params.prefixPhrase);
foldersToRename.push({ prefix, dir });
if (singlePrefix) {
const prefix = generatePrefix(rootDir, usedPrefixes, params.prefixPhrase);
foldersToRename.push({ prefix, dir: "." });
} else {
for (const dir of topLevelDirs) {
const prefix = generatePrefix(dir, usedPrefixes, params.prefixPhrase);
foldersToRename.push({ prefix, dir });
}
}

const result = await inquirer.prompt({
Expand Down
2 changes: 1 addition & 1 deletion test/suites/derive/folder1 copy 3/test_apis.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { beforeAll, describeSuite, expect } from "@moonwall/cli";

describeSuite({
id: "FO01",
id: "D0201",
title: "Tests that are using the production APIs",
foundationMethods: "read_only",
testCases: ({ context, it }) => {
Expand Down
2 changes: 1 addition & 1 deletion test/suites/derive/folder1 copy 3/test_basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect, describeSuite, beforeAll } from "@moonwall/cli";
import { setupLogger } from "@moonwall/util";

describeSuite({
id: "FO02",
id: "D0202",
title: "This is a timbo test suite",
foundationMethods: "read_only",
testCases: ({ it, log }) => {
Expand Down
2 changes: 1 addition & 1 deletion test/suites/derive/folder1 copy 3/test_contextMethods.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describeSuite, expect } from "@moonwall/cli";

describeSuite({
id: "FO03",
id: "D0203",
title: "New Test Suite",
foundationMethods: "read_only",
testCases: ({ it }) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { beforeAll, describeSuite, expect } from "@moonwall/cli";

describeSuite({
id: "F01",
id: "D010101",
title: "Tests that are using the production APIs",
foundationMethods: "read_only",
testCases: ({ context, it }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect, describeSuite, beforeAll } from "@moonwall/cli";
import { setupLogger } from "@moonwall/util";

describeSuite({
id: "F02",
id: "D010102",
title: "This is a timbo test suite",
foundationMethods: "read_only",
testCases: ({ it, log }) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describeSuite, expect } from "@moonwall/cli";

describeSuite({
id: "F03",
id: "D010103",
title: "New Test Suite",
foundationMethods: "read_only",
testCases: ({ it }) => {
Expand Down
24 changes: 24 additions & 0 deletions test/suites/derive/folder1 copy/folder1 copy 4/test_apis.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { beforeAll, describeSuite, expect } from "@moonwall/cli";

describeSuite({
id: "D010201",
title: "Tests that are using the production APIs",
foundationMethods: "read_only",
testCases: ({ context, it }) => {
it({
id: "T01",
title: "Passing Test",
test: async () => {
expect(true).to.be.true;
},
});

it({
id: "T02",
title: "another passing test",
test: () => {
expect("true").to.contain("true");
},
});
},
});
50 changes: 50 additions & 0 deletions test/suites/derive/folder1 copy/folder1 copy 4/test_basic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { expect, describeSuite, beforeAll } from "@moonwall/cli";
import { setupLogger } from "@moonwall/util";

describeSuite({
id: "D010202",
title: "This is a timbo test suite",
foundationMethods: "read_only",
testCases: ({ it, log }) => {
const anotherLogger = setupLogger("additional");

beforeAll(() => {
log("Test suite setup");
});

it({
id: "T01",
title: "This is a bool test case",
test: () => {
expect(true).to.be.true;
},
});

it({
id: "T02",
title: "This is a number test case",
test: () => {
anotherLogger("Test case log");
expect(1_332_323_221).to.be.greaterThan(1000000);
},
});

it({
id: "T03",
title: "This is a string test case",
test: () => {
expect("Home is where the heart is").to.contains("heart");
},
});

it({
id: "T04",
title: "This is a failing error test case",
test: () => {
expect(() => {
throw new Error("ERROR THROWN");
}).to.throw("ERROR THROWN");
},
});
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { describeSuite, expect } from "@moonwall/cli";

describeSuite({
id: "D010203",
title: "New Test Suite",
foundationMethods: "read_only",
testCases: ({ it }) => {
it({
id: "T01",
title: "Passing Test",
test: () => {
expect(true).to.be.true;
},
});

it({
id: "T02",
title: "Skipped test",
modifier: "skip",
test: () => {
expect(false).to.be.true;
},
});
},
});
2 changes: 1 addition & 1 deletion test/suites/derive/folder1copy2/test_apis.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { beforeAll, describeSuite, expect } from "@moonwall/cli";

describeSuite({
id: "FOL01",
id: "D0301",
title: "Tests that are using the production APIs",
foundationMethods: "read_only",
testCases: ({ context, it }) => {
Expand Down
2 changes: 1 addition & 1 deletion test/suites/derive/folder1copy2/test_basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect, describeSuite, beforeAll } from "@moonwall/cli";
import { setupLogger } from "@moonwall/util";

describeSuite({
id: "FOL02",
id: "D0302",
title: "This is a timbo test suite",
foundationMethods: "read_only",
testCases: ({ it, log }) => {
Expand Down
2 changes: 1 addition & 1 deletion test/suites/derive/folder1copy2/test_contextMethods.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describeSuite, expect } from "@moonwall/cli";

describeSuite({
id: "FOL03",
id: "D0303",
title: "New Test Suite",
foundationMethods: "read_only",
testCases: ({ it }) => {
Expand Down
2 changes: 1 addition & 1 deletion test/suites/derive/folder2/test_jimbo.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect, describeSuite, beforeAll } from "@moonwall/cli";

describeSuite({
id: "FOLD01",
id: "D0401",
title: "This is a jimbo test suite",
foundationMethods: "read_only",
testCases: ({ it, log }) => {
Expand Down
2 changes: 1 addition & 1 deletion test/suites/derive/folder2/test_suiteMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { describeSuite, expect } from "@moonwall/cli";
import { setTimeout } from "node:timers/promises";

describeSuite({
id: "FOLD02",
id: "D0402",
title: "New Test Suite",
foundationMethods: "read_only",
testCases: ({ it }) => {
Expand Down

0 comments on commit c83cfa5

Please sign in to comment.