Skip to content

Instantly share code, notes, and snippets.

@caseywatts
Last active August 2, 2017 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caseywatts/221b353990abfec293aa7e54a397d508 to your computer and use it in GitHub Desktop.
Save caseywatts/221b353990abfec293aa7e54a397d508 to your computer and use it in GitHub Desktop.
Test for presence of .only

UPDATE: just use this plugin lol

To run a single test or category of tests in ember-mocha, you sometimes put .only() after your it or describe or context. But if this gets accidentally checked into the repository, the testing suite will erroneously pass for failures in any other test O_O.

This would be better as a jscs or eslint plugin - probably in ember-suave (which is migrating jscs to eslint right now). But short-term, this helps :)

{
"name": "example-app-name",
...
"scripts":
"test": "./bin/test-are-any-only-present && ./bin/some-test-command-you-normally-do",
...
}
#!/usr/bin/env bash
if [[ $(git grep ".only(" tests) ]]; then
echo $(git grep ".only(" tests)
exit 1
else
echo "no '.only(' found in tests/"
exit 0
fi
@caseywatts
Copy link
Author

jk this is unnecessary because someone already made a plugin 🎉
https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/no-exclusive-tests.md

It was just hard to find it :)
The general and google-able word for .only and iit etc, is "exclusive test" 💡

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment