Execution order

1,375 views
Skip to first unread message

Ilya Shaisultanov

unread,
Mar 22, 2013, 10:46:47 AM3/22/13
to moc...@googlegroups.com
I'm curious about how Mocha runs tests.
Are "describe"s serial? What about sync/async "it"s?

vision media [ Tj Holowaychuk ]

unread,
Mar 22, 2013, 10:52:12 AM3/22/13
to moc...@googlegroups.com
everything is run in sequence as mocha traverses the describe "tree"

On Fri, Mar 22, 2013 at 7:46 AM, Ilya Shaisultanov <ilya.sha...@gmail.com> wrote:
I'm curious about how Mocha runs tests.
Are "describe"s serial? What about sync/async "it"s?

--
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.
 
 

Message has been deleted

Gregory Langlais

unread,
Mar 24, 2013, 11:21:19 AM3/24/13
to moc...@googlegroups.com

Run this with mocha for an example of execution order:

describe('first', function() {
  console.log('>> first describe (parent)');

  before(function(done) {
    console.log('>> first describe before');

    setTimeout(function() {
      console.log('>> first describe before done (async)');
      done();
    }, 5);
  });


  describe('second', function() {
    console.log('>> second describe');

    console.log('>>> second describe random code WITHOUT before statement');

    it('', function(done) {
      setTimeout(function() {
        console.log('>> second describe it done (async)');
        done();
      }, 5);
    });
  });

  describe('third', function() {
    console.log('>> third describe');

    before(function(done) {
      console.log('>>> third describe random code WITH before statement');
      done();
    });

    it('', function(done) {
      console.log('>> third describe it done (sync)');
      done();
    });
  });
});

Alberto Maldonado

unread,
Apr 18, 2013, 12:28:01 PM4/18/13
to moc...@googlegroups.com, t...@vision-media.ca
I don't really understand "mocha traverses the describe "tree". What does it mean?

I'm doing some test: creation user, some other stuff with this user and deletion of that user.
I ended in windows renaming files 1_create.js, 2_stuff.js, 3_delete.js so that way they are run in order, however in linux when i do mocha test, they run in this order 2,3,1.

So my question is what is the best practice to follow so i can run my test in the order I want??

Thank you,
Alberto

vision media [ Tj Holowaychuk ]

unread,
Apr 18, 2013, 12:36:44 PM4/18/13
to moc...@googlegroups.com
it executes in the same order they're define, so if you have:

describe 'foo'
  describe 'bar'
    it 'number one'
  describe 'baz'
    it 'number two'

foo executes, there's no tests so 'bar' executes, there's "number one" so it executes, then "baz" executes and the final "number two" test case
    


--

Dmitriy Navrotskyy

unread,
Apr 26, 2013, 9:44:13 AM4/26/13
to moc...@googlegroups.com, t...@vision-media.ca
the question is still: what is the execution order of files when running with mocha --recursive

vision media [ Tj Holowaychuk ]

unread,
Apr 26, 2013, 11:23:41 AM4/26/13
to moc...@googlegroups.com
that depends on the filesystem, it's all up to readdir(), if the order matters for some reason you should list the files out, however I'd really question why the order matters
Reply all
Reply to author
Forward
0 new messages