Skip to content

Commit a7091e8

Browse files
stillesjosindresorhus
authored andcommitted
Close #102 PR: Test for require..
1 parent da517a9 commit a7091e8

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"mocha": "^2.0.1",
3838
"plur": "^1.0.0",
3939
"resolve-from": "^1.0.0",
40+
"temp": "^0.8.3",
4041
"through": "^2.3.4"
4142
}
4243
}

test/require-test.js

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
var path = require('path');
2+
var temp = require('temp');
3+
var mocha = require('../');
4+
var fs = require('fs');
5+
var assert = require('assert');
6+
7+
var tempFile
8+
const filePrefix = './';
9+
10+
function removeFile(file) {
11+
try {
12+
fs.unlinkSync(file);
13+
} catch(err) {}
14+
}
15+
16+
beforeEach(function(){
17+
tempFile = temp.path({dir:process.cwd(), suffix: '.js'});
18+
tempFileBaseName = path.basename(tempFile);
19+
fs.closeSync(fs.openSync(tempFile, 'w'));
20+
});
21+
22+
afterEach(function(){
23+
removeFile(tempFile);
24+
});
25+
26+
27+
it('should fail when trying to require a file that doesn\'t exist', function() {
28+
removeFile(tempFile);
29+
assert.throws(function() {
30+
mocha({ require: [filePrefix + tempFileBaseName]});
31+
});
32+
})
33+
34+
it('should be able to import js-files in cwd', function() {
35+
mocha({ require: [filePrefix + tempFileBaseName]});
36+
});
37+
38+
it('should fail when not having the ./ file prefix', function(){
39+
assert.throws(function() {
40+
mocha({require: [tempFileBaseName]})
41+
});
42+
});

0 commit comments

Comments
 (0)