Add support for injecting test helper files
Now, the phrase `requires test modules: ` may be place in a comment in a file to require modules local to the test directory, similarly to the way the `require local modules: ` line may be used to inject files in the 'include' directory. This is useful for when common fakes need to be injected into a test.
This commit is contained in:
parent
4a4643c05d
commit
d906dfc953
|
@ -46,6 +46,16 @@ if (all_js && !program.autoInject) {
|
||||||
all_modules[path.resolve(__dirname, '../include/', mod)+'.js'] = 1;
|
all_modules[path.resolve(__dirname, '../include/', mod)+'.js'] = 1;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var fakes_ind = content.indexOf('requires test files: ');
|
||||||
|
if (fakes_ind > -1) {
|
||||||
|
fakes_ind += 'requires test modules: '.length;
|
||||||
|
var fakes_eol = content.indexOf('\n', fakes_ind);
|
||||||
|
var fakes_modules = content.slice(fakes_ind, fakes_eol).split(/,\s*/);
|
||||||
|
fakes_modules.forEach(function (mod) {
|
||||||
|
all_modules[path.resolve(__dirname, mod) + '.js'] = 1;
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
program.autoInject = Object.keys(all_modules);
|
program.autoInject = Object.keys(all_modules);
|
||||||
|
@ -65,6 +75,7 @@ if (program.autoInject) {
|
||||||
template.header += "\n" + template.script_tag(path.resolve(__dirname, 'node_modules/mocha/mocha.js'));
|
template.header += "\n" + template.script_tag(path.resolve(__dirname, 'node_modules/mocha/mocha.js'));
|
||||||
template.header += "\n" + template.script_tag(path.resolve(__dirname, 'node_modules/sinon/pkg/sinon.js'));
|
template.header += "\n" + template.script_tag(path.resolve(__dirname, 'node_modules/sinon/pkg/sinon.js'));
|
||||||
template.header += "\n" + template.script_tag(path.resolve(__dirname, 'node_modules/sinon-chai/lib/sinon-chai.js'));
|
template.header += "\n" + template.script_tag(path.resolve(__dirname, 'node_modules/sinon-chai/lib/sinon-chai.js'));
|
||||||
|
template.header += "\n" + template.script_tag(path.resolve(__dirname, 'node_modules/sinon-chai/lib/sinon-chai.js'));
|
||||||
template.header += "\n<script>mocha.setup('bdd');</script>";
|
template.header += "\n<script>mocha.setup('bdd');</script>";
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue