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

Require 'flag' for JS api #430

Closed
rauno56 opened this issue May 14, 2012 · 7 comments
Closed

Require 'flag' for JS api #430

rauno56 opened this issue May 14, 2012 · 7 comments

Comments

@rauno56
Copy link
Contributor

rauno56 commented May 14, 2012

As far as I know there's no way to add files to require for suites using JS API. If there is, please educate me.

I would really like to help with that but it feels a bit too complex for me to get my hands dirty. If here's anyone who could explain me how it is working for cli, I would appriciate it. require() seems to be modded to able it to usage so the exports of a module would go global. Like here:

module.paths.push(cwd, join(cwd, 'node_modules'));

program.on('require', function(mod){
  var abs = path.existsSync(mod)
    || path.existsSync(mod + '.js');

  if (abs) mod = join(cwd, mod);
  require(mod);
});

Any comments are welcome.

@emilecantin
Copy link

+1, I'm growing tired of including Chai, Sinon, and declaring expect at the top of each test case.

Alternatively, there should be a way to define global objects for the testcases (like the 'describe' and 'it' functions)

@emilecantin
Copy link

Nevermind, I found a way: attach Chai and Sinon, or anything you want a global to the 'global' object. This works in both Node.js and the browser.

@rauno56
Copy link
Contributor Author

rauno56 commented May 31, 2012

Unfortunately not an option for me. Anyways I'd think, that it would add a lot of dynamism to the framework.
However, the question at least for the workaround for this stands.

@dudymas
Copy link

dudymas commented Oct 20, 2012

just would like to second this as a nice to have

@tj
Copy link
Contributor

tj commented Oct 20, 2012

no reason to introduce tons of globals really, a few first-class mocha globals are ok but why have tons of them? It's much clearer where things came from, that's one of the best things about node (and commonjs). Buy anyway, to answer the question you can use Mocha#addFile(path) https://github.com/visionmedia/mocha/blob/master/lib/mocha.js#L75

@pghalliday
Copy link

+1 for me too - someone just raised an issue against my grunt-mocha-test task for not supporting this.

pghalliday/grunt-mocha-test#2

I will look into the use of Mocha#addFile(path) to see if i can work around it that way

@danielstjules
Copy link
Contributor

Closing as Mocha.prototype.addFile allows you to load additional files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants