mad-eye / meteor-mocha-web

easily and safely run mocha tests within the Meteor framework
MIT License
145 stars 46 forks source link

Is there a global before / beforeEach for packageTest? #154

Open chmac opened 9 years ago

chmac commented 9 years ago

Firstly, thanks for the awesome packageTest branch. It's absolutely fantastic. To be running mocha tests inside our packages is a dream compared to slogging through tinytest. Fabulous.

In my never ending quest for optimisation, I spent far too many hours today trying to figure out how to declare a global beforeEach, before, afterEach and / or after. I'm pulling in sinon and would like to wrap some sinon sandboxing stuff around mocha. But for the life of me I cannot find a global beforeEach hook.

I've tried reading this codebase, tried global.beforeEach() and countless other ideas, but no dice.

If it is possible, or if you have any pointers as to where I might continue my search, I'd be most grateful. Again, really, thanks for this package, mocha + meteor packages = deeply awesome!

valle-xyz commented 9 years ago

Did you try to write it in a seperate file without using descibe or it?

Basecally this should do the job:

if (typeof MochaWeb !== "undefined" && MochaWeb !== null) {
    MochaWeb.testOnly(function() {
      beforeEach(function() {
        console.log('everytime');
      });
    });
  }
chmac commented 9 years ago

Is that for testing the app, or for testing packages? I'm running the packageTest branch and testing my packages using mocha. I don't think the MochaWeb variable is used for package testing, but I could well be wrong...