diff --git a/packages/cli/src/cmds/entrypoint.ts b/packages/cli/src/cmds/entrypoint.ts index 6453be35..b4f51c6c 100755 --- a/packages/cli/src/cmds/entrypoint.ts +++ b/packages/cli/src/cmds/entrypoint.ts @@ -128,7 +128,11 @@ yargs(hideBin(process.argv)) await runNetworkCmd(argv); } ) - .command<{ suitesRootDir: string; prefixPhrase?: string }>( + .command<{ + suitesRootDir: string; + prefixPhrase?: string; + singlePrefix: boolean; + }>( "derive ", "Derive test IDs based on positional order in the directory tree", (yargs) => { @@ -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) diff --git a/packages/cli/src/internal/deriveTestIds.ts b/packages/cli/src/internal/deriveTestIds.ts index f237da46..0cfe8d23 100644 --- a/packages/cli/src/internal/deriveTestIds.ts +++ b/packages/cli/src/internal/deriveTestIds.ts @@ -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 = new Set(); - const { rootDir } = params; - const prefixDepth = params.prefixDepth ?? 1; + const { rootDir, singlePrefix } = params; try { await fs.promises.access(rootDir, fs.constants.R_OK); @@ -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({ diff --git a/test/suites/derive/folder1 copy 3/test_apis.ts b/test/suites/derive/folder1 copy 3/test_apis.ts index b9c72de8..d537b234 100644 --- a/test/suites/derive/folder1 copy 3/test_apis.ts +++ b/test/suites/derive/folder1 copy 3/test_apis.ts @@ -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 }) => { diff --git a/test/suites/derive/folder1 copy 3/test_basic.ts b/test/suites/derive/folder1 copy 3/test_basic.ts index 3af3cc53..c02bfca2 100644 --- a/test/suites/derive/folder1 copy 3/test_basic.ts +++ b/test/suites/derive/folder1 copy 3/test_basic.ts @@ -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 }) => { diff --git a/test/suites/derive/folder1 copy 3/test_contextMethods.ts b/test/suites/derive/folder1 copy 3/test_contextMethods.ts index 0485d964..fab2add1 100644 --- a/test/suites/derive/folder1 copy 3/test_contextMethods.ts +++ b/test/suites/derive/folder1 copy 3/test_contextMethods.ts @@ -1,7 +1,7 @@ import { describeSuite, expect } from "@moonwall/cli"; describeSuite({ - id: "FO03", + id: "D0203", title: "New Test Suite", foundationMethods: "read_only", testCases: ({ it }) => { diff --git a/test/suites/derive/folder1 copy/test_apis.ts b/test/suites/derive/folder1 copy/folder1 copy 3/test_apis.ts similarity index 96% rename from test/suites/derive/folder1 copy/test_apis.ts rename to test/suites/derive/folder1 copy/folder1 copy 3/test_apis.ts index 2c9c149d..351646eb 100644 --- a/test/suites/derive/folder1 copy/test_apis.ts +++ b/test/suites/derive/folder1 copy/folder1 copy 3/test_apis.ts @@ -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 }) => { diff --git a/test/suites/derive/folder1 copy/test_basic.ts b/test/suites/derive/folder1 copy/folder1 copy 3/test_basic.ts similarity index 98% rename from test/suites/derive/folder1 copy/test_basic.ts rename to test/suites/derive/folder1 copy/folder1 copy 3/test_basic.ts index d02ffa5b..69d62dd7 100644 --- a/test/suites/derive/folder1 copy/test_basic.ts +++ b/test/suites/derive/folder1 copy/folder1 copy 3/test_basic.ts @@ -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 }) => { diff --git a/test/suites/derive/folder1 copy/test_contextMethods.ts b/test/suites/derive/folder1 copy/folder1 copy 3/test_contextMethods.ts similarity index 96% rename from test/suites/derive/folder1 copy/test_contextMethods.ts rename to test/suites/derive/folder1 copy/folder1 copy 3/test_contextMethods.ts index ebb96a45..344d8f84 100644 --- a/test/suites/derive/folder1 copy/test_contextMethods.ts +++ b/test/suites/derive/folder1 copy/folder1 copy 3/test_contextMethods.ts @@ -1,7 +1,7 @@ import { describeSuite, expect } from "@moonwall/cli"; describeSuite({ - id: "F03", + id: "D010103", title: "New Test Suite", foundationMethods: "read_only", testCases: ({ it }) => { diff --git a/test/suites/derive/folder1 copy/folder1 copy 4/test_apis.ts b/test/suites/derive/folder1 copy/folder1 copy 4/test_apis.ts new file mode 100644 index 00000000..bded03bf --- /dev/null +++ b/test/suites/derive/folder1 copy/folder1 copy 4/test_apis.ts @@ -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"); + }, + }); + }, +}); diff --git a/test/suites/derive/folder1 copy/folder1 copy 4/test_basic.ts b/test/suites/derive/folder1 copy/folder1 copy 4/test_basic.ts new file mode 100644 index 00000000..ec2f256b --- /dev/null +++ b/test/suites/derive/folder1 copy/folder1 copy 4/test_basic.ts @@ -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"); + }, + }); + }, +}); diff --git a/test/suites/derive/folder1 copy/folder1 copy 4/test_contextMethods.ts b/test/suites/derive/folder1 copy/folder1 copy 4/test_contextMethods.ts new file mode 100644 index 00000000..50dec5a7 --- /dev/null +++ b/test/suites/derive/folder1 copy/folder1 copy 4/test_contextMethods.ts @@ -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; + }, + }); + }, +}); diff --git a/test/suites/derive/folder1copy2/test_apis.ts b/test/suites/derive/folder1copy2/test_apis.ts index 9732395b..561f3275 100644 --- a/test/suites/derive/folder1copy2/test_apis.ts +++ b/test/suites/derive/folder1copy2/test_apis.ts @@ -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 }) => { diff --git a/test/suites/derive/folder1copy2/test_basic.ts b/test/suites/derive/folder1copy2/test_basic.ts index b875fbe4..729dafc5 100644 --- a/test/suites/derive/folder1copy2/test_basic.ts +++ b/test/suites/derive/folder1copy2/test_basic.ts @@ -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 }) => { diff --git a/test/suites/derive/folder1copy2/test_contextMethods.ts b/test/suites/derive/folder1copy2/test_contextMethods.ts index 26381d60..4920d703 100644 --- a/test/suites/derive/folder1copy2/test_contextMethods.ts +++ b/test/suites/derive/folder1copy2/test_contextMethods.ts @@ -1,7 +1,7 @@ import { describeSuite, expect } from "@moonwall/cli"; describeSuite({ - id: "FOL03", + id: "D0303", title: "New Test Suite", foundationMethods: "read_only", testCases: ({ it }) => { diff --git a/test/suites/derive/folder2/test_jimbo.ts b/test/suites/derive/folder2/test_jimbo.ts index cf3b5124..8fb5a565 100644 --- a/test/suites/derive/folder2/test_jimbo.ts +++ b/test/suites/derive/folder2/test_jimbo.ts @@ -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 }) => { diff --git a/test/suites/derive/folder2/test_suiteMethods.ts b/test/suites/derive/folder2/test_suiteMethods.ts index 6e4185cd..24aaae7e 100644 --- a/test/suites/derive/folder2/test_suiteMethods.ts +++ b/test/suites/derive/folder2/test_suiteMethods.ts @@ -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 }) => {