Skip to content

Commit

Permalink
add sub-directory option (#387)
Browse files Browse the repository at this point in the history
  • Loading branch information
timbrinded authored Feb 22, 2024
1 parent e52b29b commit cac3d9f
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 15 deletions.
8 changes: 8 additions & 0 deletions .changeset/odd-owls-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@moonwall/types": patch
"@moonwall/util": patch
"@moonwall/cli": patch
"@moonwall/tests": patch
---

gov fix
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
**/node_modules/
**/dist/
**/.tsup/
test/html/*
*.sqlite
**/*.log
Expand Down
17 changes: 15 additions & 2 deletions packages/cli/src/cmds/entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ dotenv.config();

configSetup(process.argv);

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

yargs(hideBin(process.argv))
.wrap(null)
.usage("Usage: $0")
Expand Down Expand Up @@ -74,6 +76,11 @@ yargs(hideBin(process.argv))
.positional("GrepTest", {
type: "string",
description: "Pattern to grep test ID/Description to run",
})
.option("subDirectory", {
describe: "Additional sub-directory filter for test suites",
alias: "d",
type: "string",
});
},
async (args) => {
Expand All @@ -82,6 +89,7 @@ yargs(hideBin(process.argv))
if (
!(await testCmd(args.envName.toString(), {
testNamePattern: args.GrepTest,
subDirectory: args.subDirectory,
}))
) {
process.exitCode = 1;
Expand All @@ -93,7 +101,7 @@ yargs(hideBin(process.argv))
}
}
)
.command(
.command<RunCommandArgs>(
"run <envName> [GrepTest]",
"Start new network found in global config",
(yargs) => {
Expand All @@ -104,11 +112,16 @@ yargs(hideBin(process.argv))
.positional("GrepTest", {
type: "string",
description: "Pattern to grep test ID/Description to run",
})
.option("subDirectory", {
describe: "Additional sub-directory filter for test suites",
alias: "d",
type: "string",
});
},
async (argv) => {
process.env.MOON_RUN_SCRIPTS = "true";
await runNetworkCmd(argv as any);
await runNetworkCmd(argv);
}
)
.command<{ suitesRootDir: string }>(
Expand Down
23 changes: 18 additions & 5 deletions packages/cli/src/cmds/runNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ import {
resolveZombieInteractiveCmdChoice,
} from "./interactiveCmds";
import { executeTests } from "./runTests";
import { RunCommandArgs } from "./entrypoint";

inquirer.registerPrompt("press-to-continue", PressToContinuePrompt);

let lastSelected = 0;

export async function runNetworkCmd(args) {
export async function runNetworkCmd(args: RunCommandArgs) {
await cacheConfig();
process.env.MOON_TEST_ENV = args.envName;
process.env.MOON_SUBDIR = args.subDirectory;
const globalConfig = await importAsyncConfig();
const env = globalConfig.environments.find(({ name }) => name === args.envName);

Expand Down Expand Up @@ -144,6 +146,10 @@ export async function runNetworkCmd(args) {
console.log(` 🖥️ https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A${port}`);
}

if (process.env.MOON_SUBDIR) {
console.log(chalk.bgWhite.blackBright(`📍 Subdirectory Filter: ${process.env.MOON_SUBDIR}`));
}

if (!args.GrepTest) {
const question = questions.find(({ name }) => name === "NetworkStarted");

Expand All @@ -154,8 +160,8 @@ export async function runNetworkCmd(args) {
await inquirer.prompt(question);
} else {
process.env.MOON_RECYCLE = "true";
process.env.MOON_GREP = await args.GrepTest;
await executeTests(env, { testNamePattern: await args.GrepTest });
process.env.MOON_GREP = args.GrepTest;
await executeTests(env, { testNamePattern: args.GrepTest, subDirectory: args.subDirectory });
}

mainloop: for (;;) {
Expand Down Expand Up @@ -299,6 +305,9 @@ const resolveInfoChoice = async (env: Environment) => {
for (const { port } of portsList) {
console.log(` 🖥️ https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A${port}`);
}
if (process.env.MOON_SUBDIR) {
console.log(chalk.bgWhite.blackBright(`📍 Subdirectory Filter: ${process.env.MOON_SUBDIR}`));
}
};

const resolveGrepChoice = async (env: Environment, silent = false) => {
Expand All @@ -310,7 +319,11 @@ const resolveGrepChoice = async (env: Environment, silent = false) => {
});
process.env.MOON_RECYCLE = "true";
process.env.MOON_GREP = await choice.grep;
const opts: any = { testNamePattern: await choice.grep, silent };
const opts: any = {
testNamePattern: await choice.grep,
silent,
subDirectory: process.env.MOON_SUBDIR,
};
if (silent) {
opts.reporters = ["dot"];
}
Expand All @@ -319,7 +332,7 @@ const resolveGrepChoice = async (env: Environment, silent = false) => {

const resolveTestChoice = async (env: Environment, silent = false) => {
process.env.MOON_RECYCLE = "true";
const opts: any = { silent };
const opts: any = { silent, subDirectory: process.env.MOON_SUBDIR };
if (silent) {
opts.reporters = ["dot"];
}
Expand Down
8 changes: 6 additions & 2 deletions packages/cli/src/cmds/runTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export async function testCmd(envName: string, additionalArgs?: object): Promise
return false;
}

export async function executeTests(env: Environment, additionalArgs?: object) {
export async function executeTests(env: Environment, additionalArgs?: any) {
return new Promise<Vitest>(async (resolve, reject) => {
const globalConfig = await importAsyncConfig();
if (env.foundation.type === "read_only") {
Expand Down Expand Up @@ -118,7 +118,11 @@ export async function executeTests(env: Environment, additionalArgs?: object) {
}

try {
const folders = env.testFileDir.map((folder) => path.join(".", folder, "/"));
const testFileDir = additionalArgs?.subDirectory
? env.testFileDir.map((folder) => path.join(folder, additionalArgs.subDirectory))
: env.testFileDir;

const folders = testFileDir.map((folder) => path.join(".", folder, "/"));
resolve(
(await startVitest("test", folders, {
...options,
Expand Down
10 changes: 5 additions & 5 deletions test/configs/relaytest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ id = 2_001
[parachains.collator]
args = ["-lparachain=debug"]
command = "polkadot-parachain"
image = "parity/polkadot-parachain:1.3.0"
image = "parity/polkadot-parachain:1.7.0"
name = "collator02"

[relaychain]
chain = "rococo-local"
default_image = "docker.io/parity/polkadot:v1.3.0"
default_image = "docker.io/parity/polkadot:v1.7.0"

[relaychain.genesis.runtime.configuration.config]
[relaychain.genesis.runtimeGenesis.patch.configuration.config]
scheduling_lookahead = 4

[relaychain.genesis.runtime.configuration.config.async_backing_params]
[relaychain.genesis.runtimeGenesis.patch.configuration.config.async_backing_params]
allowed_ancestry_len = 4
max_candidate_depth = 4

Expand All @@ -30,4 +30,4 @@ timeout = 1_000
[types.Header]
number = "u64"
parent_hash = "Hash"
post_state = "Hash"
post_state = "Hash"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
verifyMessage,
} from "viem";
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
import { tokenAbi, bytecode as tokenBytecode } from "../../_test_data/token";
import { tokenAbi, bytecode as tokenBytecode } from "../../../_test_data/token";

describeSuite({
id: "D01",
Expand Down Expand Up @@ -618,6 +618,7 @@ describeSuite({
log(`Previous block #${block}, new block #${block2}`);
log(`Previous round #${round}, new round #${round2}`);
expect(round2).toBe(round + 1);

},
});

Expand Down
File renamed without changes.

0 comments on commit cac3d9f

Please sign in to comment.