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

Test for require. #102

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"mocha": "^2.0.1",
"plur": "^1.0.0",
"resolve-from": "^1.0.0",
"temp": "^0.8.3",
"through": "^2.3.4"
}
}
42 changes: 42 additions & 0 deletions test/require-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
var path = require('path');
var temp = require('temp');
var mocha = require('../');
var fs = require('fs');
var assert = require('assert');

var tempFile
const filePrefix = './';

function removeFile(file) {
try {
fs.unlinkSync(file);
} catch(err) {}
}

beforeEach(function(){
tempFile = temp.path({dir:process.cwd(), suffix: '.js'});
tempFileBaseName = path.basename(tempFile);
fs.closeSync(fs.openSync(tempFile, 'w'));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More succinct to just use https://github.com/sindresorhus/temp-write

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just want an empty file in the current working directory. temp-write seems to write the the tmp-directory of the running OS.

Importing the file using the whole path works before 044d6b6 so I don't feel that the test would cover the case I was having trouble with.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, right. Nvm.

});

afterEach(function(){
removeFile(tempFile);
});


it('should fail when trying to require a file that doesn\'t exist', function() {
removeFile(tempFile);
assert.throws(function() {
mocha({ require: [filePrefix + tempFileBaseName]});
});
})

it('should be able to import js-files in cwd', function() {
mocha({ require: [filePrefix + tempFileBaseName]});
});

it('should fail when not having the ./ file prefix', function(){
assert.throws(function() {
mocha({require: [tempFileBaseName]})
});
});