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?
fit will focus on a test or a set of them. so if you have 5 tests, 3 it and 2 fit , only the 2 with fit will run by Jasmine.
fdescribe: FunctionLike describe , but instructs the test runner to only run the test cases in this group. This is useful for debugging. See http://jasmine.github.io/ for more details.
Edit 14.11.19:
To make things easier I created an installable package you can find at https://www.npmjs.com/package/tslint-jasmine
Original post:
If you're using TSLint and (like me) found that all the defocus and tslint-jasmine-noSkipOrFocus checkers are not working for you, I created a Gist for that: https://gist.github.com/djungowski/7d9126bb79970446b4ffeb5656c6bf1f
How to use:
TSLint/Rules
as noJasmineFocusRule.js
rulesDirectory: 'TSLint/Rules'
"no-jasmine-focus": true
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 of npm run test
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With