Skip to content

Commit

Permalink
Fix prefix generation and add new options (#412)
Browse files Browse the repository at this point in the history
* fix: 🐛 fix prefix gen

when dirs have special characters, fix the prefix generation

* feat: ✨ Added custom prefix seed

* feat: New singlePrefix option

start indexing into test cases at root levle

* fix: 🐛 Fix test failures

* fix: 🐛 Fix Test

* fix: 🔧 Change pnpm version

* refactor: 🔧 Update CI versions

* fix: 🐛 pkg manager version AGAIN
  • Loading branch information
timbrinded authored May 22, 2024
1 parent de2c14b commit d4269d3
Show file tree
Hide file tree
Showing 45 changed files with 8,107 additions and 6,014 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
- uses: pnpm/action-setup@v4
with:
version: 8
version: 9.1.2
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20.11.1
node-version: 20.12.2
cache: pnpm
- name: Setup Pages
uses: actions/configure-pages@v3
Expand Down
54 changes: 27 additions & 27 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
- uses: pnpm/action-setup@v4
with:
version: 8
version: 9.1.2
- uses: actions/setup-node@v4
with:
node-version: 20.11.1
node-version: 20.12.2
cache: "pnpm"
- run: pnpm install
- run: pnpm run build
Expand All @@ -25,12 +25,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
- uses: pnpm/action-setup@v4
with:
version: 8
version: 9.1.2
- uses: actions/setup-node@v4
with:
node-version: 20.11.1
node-version: 20.12.2
cache: "pnpm"
- run: pnpm install
- run: pnpm run lint
Expand All @@ -39,12 +39,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
- uses: pnpm/action-setup@v4
with:
version: 8
version: 9.1.2
- uses: actions/setup-node@v4
with:
node-version: 20.11.1
node-version: 20.12.2
cache: "pnpm"
- run: pnpm install
- run: pnpm run fmt
Expand All @@ -54,12 +54,12 @@ jobs:
needs: ["build"]
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
- uses: pnpm/action-setup@v4
with:
version: 8
version: 9.1.2
- uses: actions/setup-node@v4
with:
node-version: 20.11.1
node-version: 20.12.2
cache: "pnpm"
- uses: oven-sh/setup-bun@v1
with:
Expand All @@ -81,12 +81,12 @@ jobs:
- uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- uses: pnpm/action-setup@v3
- uses: pnpm/action-setup@v4
with:
version: "latest"
version: 9.1.2
- uses: actions/setup-node@v4
with:
node-version: 20.11.1
node-version: 20.12.2
cache: "pnpm"
- name: Build like before
run: |
Expand Down Expand Up @@ -116,12 +116,12 @@ jobs:
- uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- uses: pnpm/action-setup@v3
- uses: pnpm/action-setup@v4
with:
version: "latest"
version: 9.1.2
- uses: actions/setup-node@v4
with:
node-version: 20.11.1
node-version: 20.12.2
cache: "pnpm"
- name: Build like before
run: |
Expand All @@ -148,12 +148,12 @@ jobs:
suite: ["chopsticks", "multi_chopsticks", "chopsticks_round"]
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
- uses: pnpm/action-setup@v4
with:
version: 8
version: 9.1.2
- uses: actions/setup-node@v4
with:
node-version: 20.11.1
node-version: 20.12.2
cache: "pnpm"
- name: Build like before
run: |
Expand Down Expand Up @@ -186,12 +186,12 @@ jobs:
suite: ["eth_test", "viem_test"]
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
- uses: pnpm/action-setup@v4
with:
version: 8
version: 9.1.2
- uses: actions/setup-node@v4
with:
node-version: 20.11.1
node-version: 20.12.2
cache: "pnpm"
- name: Build like before
run: |
Expand All @@ -217,12 +217,12 @@ jobs:
suite: ["zombie_test", "zombie_multi_para"]
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
- uses: pnpm/action-setup@v4
with:
version: 8
version: 9.1.2
- uses: actions/setup-node@v4
with:
node-version: 20.11.1
node-version: 20.12.2
cache: "pnpm"
- uses: oven-sh/setup-bun@v1
with:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/manual-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ jobs:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.branch }}
- uses: pnpm/action-setup@v3
- uses: pnpm/action-setup@v4
with:
version: 8
version: 9.1.2
- uses: actions/setup-node@v4
with:
node-version: 20.11.1
node-version: 20.12.2
cache: "pnpm"
- run: pnpm install
- run: pnpm run build
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
- uses: pnpm/action-setup@v4
with:
version: 8
version: 9.1.2
- uses: actions/setup-node@v4
with:
node-version: 20.11.1
node-version: 20.12.2
cache: "pnpm"
- run: pnpm install
- run: pnpm run build
Expand Down
Binary file removed bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "module",
"version": "0.3.0",
"private": true,
"packageManager": "pnpm@7.23.0",
"packageManager": "pnpm@9.1.2",
"description": "Testing framework for the Moon family of projects",
"scripts": {
"build": "pnpm -r --filter='./packages/**' run build",
Expand Down
7 changes: 1 addition & 6 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@
"node": ">=20",
"pnpm": ">=7"
},
"files": [
"dist",
"bin",
"*.d.ts",
"*.mjs"
],
"files": ["dist", "bin", "*.d.ts", "*.mjs"],
"scripts": {
"clean": "rm -rf dist && rm -rf node_modules",
"build": "pnpm exec rm -rf dist && tsup src --format esm --no-splitting --sourcemap && pnpm generate-types",
Expand Down
40 changes: 32 additions & 8 deletions packages/cli/src/cmds/entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ dotenv.config();

configSetup(process.argv);

export type RunCommandArgs = { envName: string; GrepTest?: string; subDirectory?: string };
export type RunCommandArgs = {
envName: string;
GrepTest?: string;
subDirectory?: string;
};

yargs(hideBin(process.argv))
.wrap(null)
Expand Down Expand Up @@ -124,17 +128,37 @@ yargs(hideBin(process.argv))
await runNetworkCmd(argv);
}
)
.command<{ suitesRootDir: string }>(
.command<{
suitesRootDir: string;
prefixPhrase?: string;
singlePrefix: boolean;
}>(
"derive <suitesRootDir>",
"Derive test IDs based on positional order in the directory tree",
(yargs) => {
return yargs.positional("suitesRootDir", {
describe: "Root directory of the suites",
type: "string",
});
return yargs
.positional("suitesRootDir", {
describe: "Root directory of the suites",
type: "string",
})
.option("prefixPhrase", {
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 (argv) => {
await deriveTestIds(argv.suitesRootDir);
async ({ suitesRootDir, prefixPhrase, singlePrefix }) => {
await deriveTestIds({
rootDir: suitesRootDir,
prefixPhrase,
singlePrefix,
});
}
)
.demandCommand(1)
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/cmds/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ async function mainMenu(config?: MoonwallConfig) {
message: "Enter the root testSuites directory to process:",
default: "suites",
});
await deriveTestIds(rootDir);
await deriveTestIds({ rootDir });

await inquirer.prompt({
name: "test complete",
Expand Down
55 changes: 36 additions & 19 deletions packages/cli/src/internal/deriveTestIds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@ import fs from "node:fs";
import inquirer from "inquirer";
import path from "node:path";

export async function deriveTestIds(rootDir: string) {
interface DeriveTestIdsOptions {
rootDir: string;
singlePrefix?: boolean;
prefixPhrase?: string;
}

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

const { rootDir, singlePrefix } = params;

try {
await fs.promises.access(rootDir, fs.constants.R_OK);
} catch (error) {
Expand All @@ -20,9 +28,14 @@ export async function deriveTestIds(rootDir: string) {

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

for (const dir of topLevelDirs) {
const prefix = generatePrefix(dir, usedPrefixes);
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 Expand Up @@ -55,26 +68,30 @@ function getTopLevelDirs(rootDir: string): string[] {
.filter((dir) => fs.statSync(path.join(rootDir, dir)).isDirectory());
}

function generatePrefix(directory: string, usedPrefixes: Set<string>): string {
let prefix = directory[0].toUpperCase();
function generatePrefix(directory: string, usedPrefixes: Set<string>, rootPrefix?: string): string {
const sanitizedDir = directory.replace(/[-_ ]/g, "").toUpperCase();
let prefix = rootPrefix ?? sanitizedDir[0];

if (usedPrefixes.has(prefix)) {
const match = directory.match(/[-_](\w)/);
if (match) {
// if directory name has a '-' or '_'
prefix += match[1].toUpperCase();
} else {
prefix = directory[1].toUpperCase();
}
let additionalIndex = 1;
while (usedPrefixes.has(prefix) && additionalIndex < sanitizedDir.length) {
prefix += rootPrefix?.[additionalIndex] ?? sanitizedDir[additionalIndex];
additionalIndex++;
}

let numericSuffix = 0;
while (usedPrefixes.has(prefix)) {
const charCode = prefix.charCodeAt(1);
if (charCode >= 90) {
// If it's Z, wrap around to A
prefix = `${String.fromCharCode(prefix.charCodeAt(0) + 1)}A`;
if (numericSuffix < 10) {
numericSuffix++;
prefix = sanitizedDir[0] + numericSuffix.toString();
} else {
prefix = prefix[0] + String.fromCharCode(charCode + 1);
let lastChar = prefix.slice(-1).charCodeAt(0);
if (lastChar >= 90) {
// 'Z'
lastChar = 65; // 'A'
} else {
lastChar++;
}
prefix = sanitizedDir[0] + String.fromCharCode(lastChar);
}
}

Expand Down
7 changes: 1 addition & 6 deletions packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,7 @@
"node": ">=20",
"pnpm": ">=7"
},
"files": [
"dist",
"bin",
"*.d.ts",
"*.mjs"
],
"files": ["dist", "bin", "*.d.ts", "*.mjs"],
"scripts": {
"clean": "rm -rf dist && rm -rf node_modules",
"build": "rm -rf dist && tsup src --format esm --no-splitting --sourcemap && pnpm generate-types",
Expand Down
7 changes: 1 addition & 6 deletions packages/util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,7 @@
"node": ">=20",
"pnpm": ">=7"
},
"files": [
"dist",
"bin",
"*.d.ts",
"*.mjs"
],
"files": ["dist", "bin", "*.d.ts", "*.mjs"],
"scripts": {
"clean": "rm -rf dist && rm -rf node_modules",
"build": "pnpm exec rm -rf dist && tsup src --format esm --no-splitting --sourcemap && pnpm generate-types",
Expand Down
Loading

0 comments on commit d4269d3

Please sign in to comment.