diff --git a/package.json b/package.json index 220fe57..e8043c1 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/test/require-test.js b/test/require-test.js new file mode 100644 index 0000000..72fadfa --- /dev/null +++ b/test/require-test.js @@ -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')); +}); + +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]}) + }); +});