Steps to reproduce:
git clon https://github.com/facebook/jest.gitnpm iit to it.onlynpm testResult:
jasmine1 runner
149 tests passed (149 total in 20 test suites, run time 4.652s)
jasmine2 runner
- TypeError: it.only is not a function
Please fix it as it is very difficult to develop tests without it!
Hey! This is an intentional API change. Jasmine 2 has fit and fdescribe, meaning focused it and focused describe instead.
@cpojer thanks for information!
But it does not work now with jasmine2!
fit:npm run jasmine2149 tests passed (149 total in 20 test suites, run time 3.556s)
Jest parallelizes test runs and it doesn't know upfront which tests it should run and which it shouldn't run. This means when you use "fit", it will only run one test in that file but still run all other test files in your project. fit should only be used for debugging purposes, so I recommend invoking jest with jest MyTest.js, which will only run one file and the one test within it.
@cpojer thanks for explanation!
But this additional actions really make developing tests less convenient than in other frameworks. In pure jasmine or mocha I can just set it.only and run usual npm test.
What do you think about adding option to disable parallelism (at least when developing tests)?
You can pass -i for that, but jest still won't know that only one test will be run. I don't think there is a good way to fix this issue although I'm open to ideas :) I'll be restructuring how tests are being run and provide a better implementation of --watch to improve the developer ergonomics around this.
I think we should go a familiar way. If I develop test it should be enough to mark it as .only or fit or whatever to run and debug exclusively.
From the jest side as I understand currently it gets spec file and instantly passes it to the runner. In developer mode we can first concat all specs into single bundle and then pass it to runner. In that case jasmine's built-in .only mechanism will do the job.
Performance is not the issue during single test development.
That is not possible because Jest isolates test files into separate environments. Of course, that could be disabled using a different param, but then you'd have to pass another cli option. Internally we have a --spec option which could be useful for this as well.
Ok, I got it.
It seems we can't avoid pre-scanning specs before actually running jest. I thinks I can end up with package (something like jest-only) that will pre scan specs, search for fit (using esprima or more straght regex) and run jest with particular spec if fit found.
Yup, you can do this but the question is whether it is worth it. At FB we have thousands of tests and doing static analysis to figure out whether only one tests needs to be run would likely take about 1/3 of the entire test runtime. For small projects the overhead isn't big, so this makes sense. I'm hoping to modularize more pieces of Jest so you can pull out the parts of jest that give you, for example, all the valid test files.
Ok, thanks.
Bwt, when you have thousands of tests and you are fixing one do you run them all?
(may be I miss some another approach)
Yes, for continuous integration we do. Locally, people run jest --onlyChanged which will only run test files related to changed files.
Sorry for continuing asking more and more.. :)
But it's very interesting:
--onlyChanged described somewhere and is it official jest cli option? Didn't find any mention of it in docs.Yes it is part of Jest. We use node-haste for dependency management and have a reverse dependency lookup algorithm. In #599 I've written a new implementation of this algorithm which works better than previously.
I believe describe.only, fdescribe, it.only, and fit don't work!!! I know there're 2 solutions to run a specific test such as _test.only_ instead of _it.only_ or running "jest -t TEST_NAME". However, I need to use the above functions to run focused tests.
Am I missing a flag while running jest?
Same issue here.
Most helpful comment
I believe
describe.only,fdescribe,it.only, andfitdon't work!!! I know there're 2 solutions to run a specific test such as _test.only_ instead of _it.only_ or running "jest -t TEST_NAME". However, I need to use the above functions to run focused tests.Am I missing a flag while running jest?