Skip to content
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

ddescribe and iit do not work #296

Closed
binarykitchen opened this issue Mar 10, 2015 · 24 comments
Closed

ddescribe and iit do not work #296

binarykitchen opened this issue Mar 10, 2015 · 24 comments

Comments

@binarykitchen
Copy link

Somehow I cannot pick one test only anymore. Jest always scans for all tests and runs them all. Adding one ddescribe() in one of them has no impact.

@jeffmo
Copy link
Contributor

jeffmo commented Mar 10, 2015

I think you're looking for it.only() and describe.only()?

@binarykitchen
Copy link
Author

Yes, I tried these too. No effect. Probably broken?

Beware that I am running the tests through gulp-jest ...

@jeffmo
Copy link
Contributor

jeffmo commented Mar 10, 2015

Hmm, it works for me on master...what version are you using?
Just to be completely clear about what I'm seeing work for me:

describe('suite', function() {
  it.only('a', function() { console.log('a'); });
  it('b', function() { console.log('b'); });
});

(I only see 'a' printed with the above test)

@binarykitchen
Copy link
Author

Yes, that's what I am after and is not working here.

gulp-jest is using jest-cli version 0.4.0, see
https://github.com/Dakuan/gulp-jest/blob/master/package.json#L24

Can you try the above example of yours within gulp-jest?

@emmenko
Copy link
Contributor

emmenko commented Mar 11, 2015

My 2 cents: afaics it.only works, but in the related describe block (meaning if you have many test files they still run). What I would expect instead is that from all the test files, only the one marked as it.only is run.

PS: the repo looks quite dead (over 2 years ago) https://github.com/davemo/jasmine-only

@jeffmo
Copy link
Contributor

jeffmo commented Mar 11, 2015

Given that test files run in parallel, I don't think it'd be possible to know to skip other test files until it's too late. What you can do (and what I do often) is specify a unique part of the name of a test file as the first arg to the test runner. This will enure only tests matching that arg string get executed (and then internally, only the .only() test will run)

@emmenko
Copy link
Contributor

emmenko commented Mar 11, 2015

The classic workaround ;)

@emmenko
Copy link
Contributor

emmenko commented Mar 11, 2015

PS: the new jasmine syntax to run specific specs is to "focus" them with fit, fdescribe
http://jasmine.github.io/2.1/focused_specs.html

Not sure if it's possible to integrate it in jest though, not at least before upgrading to v2.0...
Refs #74

@binarykitchen
Copy link
Author

@jeffmo sure, we all could do your classic workaround but let's think of DX and try to make our lives easier. I'd welcome a fit and fdescribe integration into jest. Really.

@jeffmo
Copy link
Contributor

jeffmo commented Mar 11, 2015

@binarykitchen: I don't think fit or fdescribe solve the problem here...and I don't see a solution, do you? How do you deal with the fact that tests run in parallel and therefore you can't know until you've already run all the tests whether one of them is marked as "focused" or "only"?

@binarykitchen
Copy link
Author

good point @jeffmo i am sure this problem has already been solved somewhere else with other unit test runners such as mocha. load and parse all files first and then decide which tests to run.

@emmenko
Copy link
Contributor

emmenko commented Mar 12, 2015

The karma runner for jasmine supports that. I don't know how it works exactly and how it differs from jest, still I think it's worth mentioning...

https://github.com/karma-runner/karma-jasmine

@zeroliu
Copy link

zeroliu commented Oct 26, 2015

Any updates on supporting fit & fdescribe in jest?

@cpojer
Copy link
Member

cpojer commented Oct 26, 2015

Given that jest runs tests in parallel this seems quite impossible as @jeffmo pointed out earlier. What I've found to work well is it.only and passing the name of the test to jest, so it only runs a single file:

it.only(...) and jest MyTest.js

@danielstern
Copy link

+1
By the way this seems quite possible, just the user would need to specify not to run the tests in parallel.

@cpojer
Copy link
Member

cpojer commented Dec 26, 2016

@danielstern you can now use -i -t <pattern> I guess.

@arcseldon
Copy link

For Node.js testing, just moved over to try Jest as opposed to my former go-to test dependencies (Mocha, Chai, Proxyquire and Sinon) - the idea of consolidating to just having to use Jest was a primary motiviation, together with Mock by default behaviour... really liked the idea of cutting down on the test harness plumbing. So far the experience using Jest has been really disappointing for reasons (one of many) such as this - too many workarounds and sub-optimal hacks to get equivalent behaviour that is expected to be out of the box. In fact, using Jest has resulted in more plumbing, not less - and less options / power. Using Mocha, Chai, Proxyquire and Sinon is not ideal either (hence the Jest trial). Shame that a lot of the promise for Jest has not (yet) been realised - frustratingly close to what I was looking for - shall take another look in 6-12 months as I still think the library may one day get there.

@thymikee
Copy link
Collaborator

@arcseldon what has disappointed you about Jest? Can you elaborate on that? It's crucial to get such feedback, so we can work on this to make Jest better.

@cpojer
Copy link
Member

cpojer commented Jan 15, 2017

@arcseldon this is a very vague comment on a random issue and isn't very helpful. If you have concerns or concrete issues and would like to see Jest improved, please help us by starting discussions in the appropriate places or send us pull requests to make Jest work for you.

@unional
Copy link
Contributor

unional commented May 25, 2017

I think it is possible. ava also runs tests in parallel and its test.only() is working as expected (only those tests are ran across all test files)

@chriswatrous
Copy link

chriswatrous commented Mar 19, 2018

Here's a workaround I'm using, in package.json:

"test:unit:only": "jest $(grep -rl '\\.only' test/unit)"

then

npm run test:unit:only

@SimenB
Copy link
Member

SimenB commented Mar 21, 2018

FWIW ava has an issue for --only flag now. Maybe we should have the same?

avajs/ava#1472

@Diokuz
Copy link
Contributor

Diokuz commented May 7, 2018

So, the main problem here is parallel execution, right?
What about --runInBand then? Can we fix the problem at least for non-parallel runInBand mode?

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests