How to run test files one by one?

6,284 views
Skip to first unread message

Yuping Jin

unread,
Dec 22, 2013, 12:37:32 PM12/22/13
to moc...@googlegroups.com
Hi,

I've multiple test files under test folder. It seems that mocha runs the files at the same time. Is it possible to run them one by one?

Thanks and regards,
Yuping

vision media [ Tj Holowaychuk ]

unread,
Dec 22, 2013, 12:53:10 PM12/22/13
to moc...@googlegroups.com
$ mocha path/to/one-test.js

they do run sequentially though if that's what you were asking, no parallel execution of files


--
You received this message because you are subscribed to the Google Groups "Mocha" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mochajs+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Yuping Jin

unread,
Dec 23, 2013, 10:56:29 PM12/23/13
to moc...@googlegroups.com, t...@vision-media.ca
Thanks a lot! 
In that case it might be caused by async tests? I knew that Node won't wait for aync call return in a module before loading next. In my case I use sinon.stub on same object & function in 2 test files and the first will restore the function after test done. The fact is that the second file threw exception complaining calling sinon.stub on a already wrapped function.

Thanks and regards,
Yuping 

Atom Cong

unread,
May 15, 2015, 12:49:27 AM5/15/15
to moc...@googlegroups.com, t...@vision-media.ca
sorry for reviving this old thread. 

I have similar issue.  There are two testing files in one folder, both have database operations in it.  Run them independently, no problem at all. 

If I just call mocha, which starts both, then the test fails.  

My feeling is also the tests have been running in parallel... How to disable it?

Vlad GURDIGA

unread,
May 16, 2015, 2:39:52 AM5/16/15
to moc...@googlegroups.com, t...@vision-media.ca
Hi Atom!

Could you please post the test code somewhere? (Or at least the part of it that you think it’s relevant.) It’s hard to troubleshoot this kind of situation without seeing any code.

Cheers!

Jonathan Boudreau

unread,
May 19, 2015, 3:15:37 PM5/19/15
to moc...@googlegroups.com, t...@vision-media.ca
Hello, I'm also have this problem. I'm not sure if its really that its running everything in parallel, could just be that it executes the next file before the "root after" hook runs/finishes (which in my case will make the next test break). Added some prints to see what was going on with my little project, each file is being executed as follows:

carts - before hook called
carts - database cleaned
products - before hook called
carts - after hook called
products - after hook called

Then it blows up. I tried it a few times and it does the same thing over and over. What is likely happening here is that the server isn't closed (ie, there's still a connection with the database, which would make DROP DATABASE return an error afaik) when I try to rebuild the database. Thing is, I've placed the logic to close the server in the "root after" hook, which for some odd reason is being run after the "root before" hook for the next file.

I've been learning node and I made a simple project. Simply run mocha test/integration or npm run integraton to see the error. I kept the prints in.

https://github.com/AGhost-7/node-shop

I imagine that the only other way around this would be to use the programmatic API, but there should be another way to do this I think since my impression is that what I'm trying to do is (maybe) pretty common.

Any suggestions? Is this a bug?

Thanks.

Vlad GURDIGA

unread,
May 20, 2015, 3:15:06 AM5/20/15
to moc...@googlegroups.com, t...@vision-media.ca
For every file there must be a top describe() which encloses everything else, including before() and after().  :o)

That’s it! :-)


Jonathan Boudreau

unread,
May 20, 2015, 10:20:55 AM5/20/15
to moc...@googlegroups.com, t...@vision-media.ca
I thought that mocha had a top level suite so you wouldn't need to do that? Is this how you're actually supposed to do it, or is it a hack?

Thanks

Vlad GURDIGA

unread,
May 20, 2015, 11:01:14 AM5/20/15
to moc...@googlegroups.com
It’s not a hack. :-)

Rick Lambrechts

unread,
Jan 4, 2018, 2:53:42 PM1/4/18
to Mocha
Hi Vlad,

Thank you for this answer, even this is an old post, you helped me also!

Vlad GURDIGA

unread,
Jan 5, 2018, 3:22:42 AM1/5/18
to Mocha
Key Rick! 👋

Very cool! I’m glad to hear it’s helpful! 🤓
Reply all
Reply to author
Forward
0 new messages