Skip to content

Commit

Permalink
fix: regexp and execution
Browse files Browse the repository at this point in the history
  • Loading branch information
noandrea committed Jul 4, 2024
1 parent 2874797 commit b315f6c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
23 changes: 7 additions & 16 deletions packages/cli/src/cmds/runTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
21 changes: 21 additions & 0 deletions packages/types/config_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
6 changes: 3 additions & 3 deletions packages/types/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit b315f6c

Please sign in to comment.