-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Protect us from forgetting to remove .skip() or .only() #1633
Comments
I do use that a lot in my personal projects. It is definitely better than Further, I would argue, AVA's runner should be more robust than static analysis. |
The ESLint rules have saved me many many times. I do understand not everyone will or can use that though, so I'm open to doing something in AVA. It's a very common mistake to make. Maybe we could also have an option to fail if @novemberborn Thoughts? |
Definitely 👍 on doing this by default in CI. I suppose I'm not keen on supporting configuration through environment variables. If we'd support a JS file to build the configuration though that could be implemented locally. |
I hear that. I usually go to great lengths to avoid env vars. In this case, though, it would make it easier to have hooks that make no assumptions about the
Hmm well to me this isn't really any different than just having my pre-push hook modify package.json momentarily to add |
Yes. You could make up your own env var for that, too. That might be a better place to start than reasoning through which settings should have env vars and which shouldn't. |
Just wanted to add a different angle on this issue. I'm using Now, if somebody would port the For the record, failing CI builds are nasty, a waste of time. Here's an alternative idea. What if we introduced the We could piggyback many features on dev mode:
For posterity, #1472 and per-file isolation is just a single const files = await globby(patterns, {
absolute: true,
braceExpansion: true,
caseSensitiveMatch: false,
cwd,
dot: false,
expandDirectories: false,
extglob: true,
followSymbolicLinks: true,
gitignore: false,
globstar: true,
ignore: defaultIgnorePatterns,
baseNameMatch: false,
onlyFiles: true,
stats: false,
unique: true
}).then(filesArr => {
if (dev && Array.isArray(filesArr) && filesArr.length > 1) {
for (let i = filesArr.length; i--; ) {
const filesContents = fs.readFileSync(filesArr[i], "utf8");
if (
filesContents.includes(".only(") ||
filesContents.includes("avaonly")
) {
return [filesArr[i]];
}
}
return filesArr;
}
return filesArr;
}); What do you think? |
I wouldn't want AVA to just ignore the skips, ever. It should either respect them or demand they be removed. That ensures good code hygiene. Other than that, I think the idea of a dev mode is fine. |
Without more use-cases for a I don't think we quite spelled it out, so I think this should cause failures when |
Description
This is an idea for a feature to help alleviate problems with forgetting to remove
.skip()
and.only()
in tests.Problem
It is a common practice to run tests during development, but even the most diligent of us (and all of our fancy automation) can be easily fooled into thinking everything is okay when it isn't, by simple human error, when you forget to remove
.only()
/.skip()
from a test. It is easy to end up in a situation where you ship broken code because the tests technically succeeded but lots of tests were not actually run and the broken code didn't even get exercised at all.Currently, AVA prints a reminder to the console when you use these methods, which is useful if you happen to notice it. But in some cases, that may not even be possible. For example, a common way to run
npm test
is via git hooks, but my favorite GUI for git, Tower, only shows output from hooks when they fail. I like it that way, in general, though that means AVA's logs cannot be seen and thus it is even less obvious that some tests were not run.Solution
One of the better solutions I have seen so far to prevent leaving in skip modifies is to
grep
for them inside of a pre-push hook, as documented by @jegtnes here:https://jegtnes.com/blog/use-git-pre-push-hooks-to-stop-test-suite-skips/
That got me thinking... AVA could make this nearly foolproof because it actually knows whether things are skipped, so much more reliably than
grep
!I propose a CLI command / flag that exits non-zero if
.skip()
or.only()
are used.You would then use that for your pre-push hook. If the tests pass and neither
.skip()
nor.only()
were called, then git will push your commits, otherwise it will display a meaningful message from AVA, even in apps like Tower. All AVA has to do is provide this mode and exit with an error, if appropriate.An alternative method to enable the mode could be an environment variable, to better support existing
npm
scripts...AVA_CHECK_SKIPS=true npm test
If this functionality were to be implemented, we could then automate it across all collaborators on a project with tools like husky. Fewer broken PRs, anyone? :)
The text was updated successfully, but these errors were encountered: