fdescribe()
and fit()
are great for reducing noise when you’re working on a subset of tests. I sometimes forget to change them back to describe()
/it()
before merging my branch into master. (It’s okay to have them in separate branch while working on code – i.e. a pre-commit check wouldn’t work for me.)
My CI environment is Codeship. Is there a solution to this problem that would fail the tests in Codeship if it came across any focused methods?
Using something like no-focused-tests would be okay. Any idea how to enable this rule as an error in Codeship and disable it locally?
Advertisement
Answer
Using something like no-focused-tests would be okay. Any idea how to enable this rule as an error in Codeship and disable it locally?
You could use a combination of environment variables and redefining the fdescribe/fit global functions:
npm i --save cross-env
package.json:
"scripts": { "test": "jasmine", "test-safe": "cross-env FOCUSED_TESTS=off jasmine" },
disableFocusedTestsIfNecessary.js (included after jasmine defines its globals):
if (process.env.FOCUSED_TESTS === "off") { console.log("Focused tests must be off"); global.fdescribe = global.fit = function() { throw new Error("fdescribe and fit are disabled in this environment"); }; } else { console.log("Focused tests enabled"); }
Tell codeship to run
npm run test-safe
instead ofnpm run test