Skip to content
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

Add the ability to add gitignored files inside the config: files #1593

Closed
trollepierre opened this issue Jun 20, 2019 · 20 comments
Closed

Add the ability to add gitignored files inside the config: files #1593

trollepierre opened this issue Jun 20, 2019 · 20 comments
Labels
🚀 Feature request New feature request
Milestone

Comments

@trollepierre
Copy link

Summary

Here:
https://github.com/stryker-mutator/stryker/tree/master/packages/core#files-string

I would like to be able to add my translation files that are gitignored. I run a command to update them.

@nicojs
Copy link
Member

nicojs commented Jun 24, 2019

Hi @trollepierre thanks for opening this issue.

I think you linked the correct stryker option. With https://github.com/stryker-mutator/stryker/tree/master/packages/core#files-string you can override the default behavior of ignoring certain files.

Or is there some other feature you're requesting here?

@trollepierre
Copy link
Author

Can you please give an example how to do add every file, except gitignored files, but with one exception file that is ignored?

@trollepierre
Copy link
Author

I didn't succeed in doing it. :S

@nicojs
Copy link
Member

nicojs commented Jul 15, 2019

Can you please give an example how to do add every file, except gitignored files, but with one exception file that is ignored?

I see... this isn't possible at the moment, no. You would need to add glob expressions for all files you want to add explicitly.

I've added the feature tag to this issue. How would you expect us to support this (without a breaking change)? We could add a flag like fileResolvingStrategy... or add a magic string constant that you need to put as first in the files array, like !!gitfiles or something, both not ideal.

@trollepierre
Copy link
Author

I've added the feature tag to this issue.
Where?

How would you expect us to support this (without a breaking change)?
Adding a flag like fileResolvingStrategy would be the simplest solution to me.

Optional values would match:

  • all files => all
  • all gitfiles => gitfiles
  • custom (in that case, follow what is inside files

What do you think about it?

@simondel simondel added the 🚀 Feature request New feature request label Jul 23, 2019
@simondel
Copy link
Member

With the exception of your node_modules folder, what is in your .gitignore right now? You could also work by adding all files and then excluding what you don't want.

Also, why would you like to have a file in the sandbox that is not in your git repo? What kind of file (or files) are we talking about?

@trollepierre
Copy link
Author

I am talking about the translation, that we get from an external service (Phraseapp).
The en.json and other language json are not committed during development. But are necessary to test the app.

@nicojs
Copy link
Member

nicojs commented Aug 22, 2019

I've got another suggestion.

NYC has a similair feature. It ignores node_modules by default, even if you override it with an exclude property. It than allows you to override this behavior using --exclude-node-modules=false.

We can do this as well by providing a --include-repository-files flag. @simondel do you agree? This keeps backward compatibility and make it nice and explicit. I'm open for naming suggestions.

@trollepierre
Copy link
Author

I was happy with the suggestion at first sight, but I wonder how can we implement custom files. 🤔

Example: I want to test every files in my .gitignore + my translation. (not more)

Moreover I am not a big fan of the naming. Using a script --include-repository-files=translations works, but what if I have other files?

@trollepierre
Copy link
Author

@simondel :

what is in your .gitignore right now?

In my .gitignore, I have /.idea, *.log, coverage, several dist, .yarn.cache, .env

@nicojs
Copy link
Member

nicojs commented Aug 27, 2019

Moreover I am not a big fan of the naming. Using a script --include-repository-files=translations works, but what if I have other files?

I'm not sure if you understand me. This is what your stryker.conf.js would look like:

{
  includeRepositoryFiles: true,
  files: ['dist/*.translation.js']
}

So it would just be a flag to signal that you also want your repository files to be included.

@trollepierre
Copy link
Author

@nicojs : ok I understand and i like this idea!

@nicojs
Copy link
Member

nicojs commented Mar 29, 2020

An out of the box idea, based on an older idea. Instead of whitelisting files, what about blacklisting? Allowing for a .strykerignore file. This is how prettier, eslint and other cool kids do it.

We might be able to use https://www.npmjs.com/package/glob-gitignore to do this.

We wouldn't rely on git anymore to do the file listing, which gives much more flexibility. We could still default to .gitignore, but enforcing the exact same functionality will be difficult, given that .gitignore files can add up (every directory can have one), this doesn't seem to be an out of the box feature of glob-gitignore

@trollepierre
Copy link
Author

that would be better in my opinion!
Or more usable than the config idea

@bartekleon
Copy link
Member

Is it still valid issue? we support files and git now.

@trollepierre
Copy link
Author

I guess yes! (sorry to time to deep dive, in testing it)
Thanks

@nicojs
Copy link
Member

nicojs commented Oct 6, 2020

Pretty sure this issue isn't fixed yet :). But fine for me.

@trollepierre
Copy link
Author

then I reopen (but it can stay in the deep bottom of the backlog) 😆

@trollepierre trollepierre reopened this Oct 6, 2020
@nicojs nicojs mentioned this issue Feb 5, 2021
6 tasks
@nicojs nicojs added this to the 5.0 milestone Mar 26, 2021
@nicojs
Copy link
Member

nicojs commented Mar 26, 2021

I want to implement this feature (.strykerignore) for v5

nicojs added a commit that referenced this issue May 3, 2021
Add the ability to specify `ignorePatterns` in your Stryker configuration. This replaces `files` 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:

```json
{
  "ignorePatterns": ["dist"]
}
```

This will discover all files in your current working directory, _except_ for files matching the `"dist"` pattern. Stryker uses [.gitignore](https://git-scm.com/docs/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:

```json
{
  "ignorePatterns": ["!node_modules"]
}
```

The `ignorePatterns` is now also the default way files are discovered. Previously, Stryker used `git ls-files --others --exclude-standard --cached --exclude .stryker-tmp` to discover files by default. This had some limitations:

* ❌ It only worked inside a git repository and you had to have `git` installed. If not, you got an error and had to use `files`
* ❌ If a `.gitignore`'d file is needed to run your tests, you needed to fall back on `files`. 

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`](https://stryker-mutator.io/docs/stryker-js/configuration/#ignorepatterns-string).

BREAKING CHANGE: The `files` configuration option is deprecated and will be removed in a future release. Please use [`ignorePatterns`](https://stryker-mutator.io/docs/stryker-js/configuration/#ignorepatterns-string) instead.

This:

```json
{
  "files": ["foo.js"]
}
```

Is equivalent to:

```json
{
  "ignorePatterns": ["**", "!foo.js"]
}
```
@nicojs
Copy link
Member

nicojs commented May 7, 2021

Closed with #2848 (please use --ignorePatterns from v5)

@nicojs nicojs closed this as completed May 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚀 Feature request New feature request
Projects
None yet
Development

No branches or pull requests

4 participants