-
Notifications
You must be signed in to change notification settings - Fork 251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(ignore patterns): add "ignorePatterns" config option #2848
Conversation
@stryker-mutator/stryker-js-and-friends-maintainers What do you think about this? A couple of thoughts:
|
4eeac1c
to
8b5d8b3
Compare
Maybe we should rename it to |
Ok, I think I know what I want to do. I think I'll deprecate {
"files": [ "src/**/*.ts", "dist/**/*.js"]
} becomes {
"ignorePatterns": ["**", "!src/**/*ts", "!dist/**/*.js"]
} |
Changing
into
will work, but removing the |
docs/configuration.md
Outdated
When using the config file you can provide an array with `string`s | ||
Default: `[]`<br /> | ||
Command line: `--ignorePatterns dist,dist-test`<br /> | ||
Config file: `"ignorePatterns": ["dist", "dist-test"]`<br /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we should also add a coverage
folder to this example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, good one, I'll replace dist-test
with coverage
|
||
You can *ignore* files by adding an exclamation mark (`!`) at the start of an expression. | ||
These patterns are **always ignored**: `['node_modules', '.git', '/reports', '/stryker.log', '.stryker-tmp']`. Because Stryker always ignores these, you should rarely have to adjust the `"ignorePatterns"` setting at all. If you want to undo one of these ignore patterns, you can use the `!` prefix, for example: `['!node_modules']`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you specify reports
and stryker.log
with a /
at the front, but not for other files/folders?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because I know for a fact that Stryker places them at the root of your project. For example. I would like the src/reports
directory that someone might have to be included. Starting with a /
means to only match when it exists in the root of the cwd.
"fileLogLevel": { | ||
"description": "Set the log level that Stryker uses to write to the \"stryker.log\" file", | ||
"$ref": "#/definitions/logLevel", | ||
"default": "off" | ||
}, | ||
"files": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this still be in the schema, but deprecated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As explained during the community meeting, I don't want people to use it. The rewrite to ignorePatterns
is being done before the options are validated. This is in line with other deprecated options.
packages/core/package.json
Outdated
@@ -66,6 +66,7 @@ | |||
"file-url": "~3.0.0", | |||
"get-port": "~5.0.0", | |||
"glob": "~7.1.2", | |||
"ignore": "^5.1.8", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was the ^
intentional here? Or did you mean ~
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, not using it. Will remove 😅
// Inspired by https://github.com/npm/ignore-walk/blob/0e4f87adccb3e16f526d2e960ed04bdc77fd6cca/index.js#L124 | ||
const matchesDirectory = (entryName: string, entryPath: string, rule: IMinimatch) => { | ||
return ( | ||
matchesFile(entryName, entryPath, rule) || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is quite unreadable as you're combining a lot of matches. It might be more readable if the sets are more on one line (for example rule.negate && (rule.match(
/${entryPath}, true) || rule.match(entryPath, true))
It might also be smart to place the checks in separate variables so you can actually name what's going on
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're using prettier
I can't play around with the formatting. Separate variables would work, but it would technically cost performance since all matches would always be done (instead of stopping at the first failing match).
I've added a third matchesXxx
helper function:
const matchesDirectoryPartially = (entryPath: string, rule: IMinimatch) => {
// @ts-expect-error Missing overload in type definitions. See https://github.com/isaacs/minimatch/issues/134
return rule.match(`/${entryPath}`, true) || rule.match(entryPath, true);
};
This helps a lot I think.
I've added a remark about completely removing "files":
|
LGTM! |
Add the ability to specify
ignorePatterns
in your Stryker configuration. This replacesfiles
option which is now deprecated.By specifying
ignorePatterns
you choose which files should not be copied to the Sandbox directory (inside the.stryker-tmp
directory). This effectively excludes them from being used during mutation testing.For example:
This will discover all files in your current working directory, except for files matching the
"dist"
pattern. Stryker uses .gitignore rules to resolve these patterns.Stryker always adds
['.git', 'node_modules', '/reports', 'stryker.log', '.stryker-tmp']
when resolving these patterns. If you really want them in your sandbox, you can un-ignore them using a!
prefix in your pattern, for example:The
ignorePatterns
is now also the default way files are discovered. Previously, Stryker usedgit ls-files --others --exclude-standard --cached --exclude .stryker-tmp
to discover files by default. This had some limitations:git
installed. If not, you got an error and had to usefiles
.gitignore
'd file is needed to run your tests, you needed to fall back onfiles
.Specifying
files
is now deprecated, but still works for the time being. Stryker will rewrite your file patterns internally to ignore patterns.Closes #1593
Closes #2739
BREAKING CHANGE: Stryker will no longer use a git command to determine which files belong to your project. Instead, it will rely on sane defaults. You can change this behavior by defining
ignorePatterns
.BREAKING CHANGE: The
files
configuration option is deprecated and will be removed in a future release. Please useignorePatterns
instead.This:
Is equivalent to: