From b315f6c432e6dc6e9e6e6a24248d0f7ff77a31e9 Mon Sep 17 00:00:00 2001 From: Andrea Giacobino Date: Thu, 4 Jul 2024 15:03:37 +0200 Subject: [PATCH] fix: regexp and execution --- packages/cli/src/cmds/runTests.ts | 23 +++++++---------------- packages/types/config_schema.json | 21 +++++++++++++++++++++ packages/types/src/config.ts | 6 +++--- 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/packages/cli/src/cmds/runTests.ts b/packages/cli/src/cmds/runTests.ts index 3c1c83c5..ed45b624 100644 --- a/packages/cli/src/cmds/runTests.ts +++ b/packages/cli/src/cmds/runTests.ts @@ -106,10 +106,15 @@ export async function executeTests(env: Environment, additionalArgs?: any) { }, } satisfies UserConfig; - const skipOptions = addSkipConfig(baseOptions, additionalArgs?.skipTests); + // transform in regexp pattern + if(env.skipTests && env.skipTests.length > 0){ + // the final pattern will look like this: "^((?!SO00T02|SM00T01|SM00T03).)*$" + additionalArgs.testNamePattern = `^((?!${env.skipTests?.map((test) => `${test.name}`).join("|")}).)*$`; + } + // TODO: Create options builder class - const options = addThreadConfig(skipOptions, env.multiThreads); + const options = addThreadConfig(baseOptions, env.multiThreads); if ( globalConfig.environments.find((env) => env.name === process.env.MOON_TEST_ENV)?.foundation @@ -198,17 +203,3 @@ function addThreadConfig( } return configWithThreads; } - -// Add skip tests to the config, by replacing the testNamePattern with a negative lookahead pattern -function addSkipConfig(config: UserConfig, skipTests: SkipTestSpec[] | undefined): UserConfig { - // example pattern: (?!\s*foo\s*$) - const skipTestsPatterns = skipTests?.map((test) => `(?!\s*${test.name}\s*$)`).join(""); - // final negative pattern: ^(?!\s*foo\s*$).+$ - if (skipTests) { - return { - ...config, - testNamePattern: `^${skipTestsPatterns}.+$`, - }; - } - return config; -} diff --git a/packages/types/config_schema.json b/packages/types/config_schema.json index c89a148a..3d8d2355 100644 --- a/packages/types/config_schema.json +++ b/packages/types/config_schema.json @@ -631,6 +631,27 @@ }, "type": "array" }, + "skipTests": { + "description": "A list of test to skip.", + "items": { + "properties": { + "name": { + "description": "The name of the test to skip. Eg. S22C500", + "type": "string" + }, + "reason": { + "description": "The reason for skipping the test. Must be provided. Eg. https://github.com/org/repo/issues/123.", + "type": "string" + }, + "since": { + "description": "The date when the test was skipped. Must be provided and be RFC3339 compliant. Eg. 2021-09-01T00:00:00Z", + "type": "string" + } + }, + "type": "object" + }, + "type": "array" + }, "testFileDir": { "description": "An array of directories with test files.", "items": { diff --git a/packages/types/src/config.ts b/packages/types/src/config.ts index 331dbbc8..80362014 100644 --- a/packages/types/src/config.ts +++ b/packages/types/src/config.ts @@ -136,17 +136,17 @@ export type Environment = { export type SkipTestSpec = { /** - * The name of the test to skip. Eg. "S22C500" + * The name of the test to skip. Eg. S22C500 */ name: string; /** - * The reason for skipping the test. Must be provided. Eg. link to issue or PR. + * The reason for skipping the test. Must be provided. Eg. https://github.com/org/repo/issues/123. */ reason: string; /** - * The date when the test was skipped. Must be provided and be RFC3339 compliant. Eg. "2021-09-01T00:00:00Z" + * The date when the test was skipped. Must be provided and be RFC3339 compliant. Eg. 2021-09-01T00:00:00Z */ since: string; };