I am using Mocha programatically as described here:
Very similarly to how the examples are written:
test-runner.js:
var Mocha = require('mocha');
var mocha = new Mocha();
mocha.addFile('spec.js');
mocha.run(function() {});
Inside the test spec, I am spinning up a headless browser to run the test on a specific url:
spec.js:
var Browser = new Browser();
browser.visit(url, function(){});
Is there a way to pass the desired url from test-runner.js to spec.js?
I am using Mocha programatically as described here:
https://github./visionmedia/mocha/wiki/Using-mocha-programmatically
Very similarly to how the examples are written:
test-runner.js:
var Mocha = require('mocha');
var mocha = new Mocha();
mocha.addFile('spec.js');
mocha.run(function() {});
Inside the test spec, I am spinning up a headless browser to run the test on a specific url:
spec.js:
var Browser = new Browser();
browser.visit(url, function(){});
Is there a way to pass the desired url from test-runner.js to spec.js?
Share Improve this question asked Dec 21, 2012 at 23:36 superdikerysuperdikery 781 silver badge6 bronze badges1 Answer
Reset to default 5In your spec file, you can require a module that contains the configurations for those tests:
var url = require('./config.js').url;
describe("blah", function(){
...
});
This config module could also be set from the initial mocha tests (e.g.):
var Mocha = require('mocha');
var mocha = new Mocha();
var config = require('./config.js');
config.setOptions({url:"localhost/testme.html"});
mocha.addFile('spec.js');
mocha.run(function() {});
Check out this related SO regarding node modules being singletons.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745247863a4618495.html
评论列表(0条)