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

Ability to require local files, -r ./local_file #241

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions bin/_mocha
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,33 @@ program.on('interfaces', function(){
module.paths.push(cwd, join(cwd, 'node_modules'));

program.on('require', function(mod){

// relative file modules support

if (mod[0] == '.') mod = cwd+'/'+mod;

// adds .coffee extension for absolute/relative paths

if (mod[0] == '/' && !mod.match(/\.(js|coffee)$/)) {

// .js modules takes precedence over .coffee

try {
fs.statSync(mod+'.js').isFile() == true;
} catch(err){
try {
if(fs.statSync(mod+'.coffee').isFile()) mod += '.coffee';
} catch (err) {} // ignores file does not exist errors
}

}

// coffee-script support

if (mod.match(/\.coffee$/)) require('coffee-script');

require(mod);

});

// mocha.opts support
Expand Down