Skip to content

Commit

Permalink
cleanup #102
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Jul 12, 2015
1 parent a7091e8 commit 20bc2ce
Showing 1 changed file with 32 additions and 25 deletions.
57 changes: 32 additions & 25 deletions test/require-test.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,49 @@
'use strict';
var path = require('path');
var temp = require('temp');
var mocha = require('../');
var fs = require('fs');
var assert = require('assert');
var temp = require('temp');
var mocha = require('../');

var tempFile
const filePrefix = './';
var tempFile;
var tempFileBaseName;
var filePrefix = './';

function removeFile(file) {
try {
fs.unlinkSync(file);
} catch(err) {}
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'));
beforeEach(function () {
tempFile = temp.path({
dir: process.cwd(),
suffix: '.js'
});

tempFileBaseName = path.basename(tempFile);

fs.writeFileSync(tempFile, '');
});

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

it('should fail when trying to require a file that doesn\'t exist', 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]});
});
})
assert.throws(function () {
mocha({require: [filePrefix + tempFileBaseName]});
});
});

it('should be able to import js-files in cwd', 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]})
});
it('should fail when not having the ./ file prefix', function () {
assert.throws(function () {
mocha({require: [tempFileBaseName]});
});
});

0 comments on commit 20bc2ce

Please sign in to comment.