Skip to content

Commit

Permalink
fix wonky lookupFiles test; closes #2347
Browse files Browse the repository at this point in the history
  • Loading branch information
boneskull committed Jul 3, 2016
1 parent dc6ca3f commit 59b03a7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 25 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@
"karma-sauce-launcher": "^1.0.0",
"karma-spec-reporter": "0.0.26",
"phantomjs": "1.9.8",
"rimraf": "^2.5.2",
"should": "^9.0.2",
"through2": "^2.0.1",
"watchify": "^3.7.0"
Expand Down
57 changes: 32 additions & 25 deletions test/acceptance/lookup-files.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
'use strict';

var utils = require('../../lib/utils');
var fs = require('fs');
var path = require('path');
var os = require('os');
var mkdirp = require('mkdirp');
var rimraf = require('rimraf');

describe('lookupFiles', function() {
var fs = require('fs'),
path = require('path'),
existsSync = fs.existsSync || path.existsSync,
tmpDir = require('os').tmpDir(),
tmpFile = path.join.bind(path, tmpDir),
symlinkSupported = false;
var tmpDir = path.join(os.tmpDir(), 'mocha-lookup-files');
var existsSync = fs.existsSync;
var tmpFile = path.join.bind(path, tmpDir);
var symlinkSupported = false;

fs.writeFileSync(tmpFile('mocha-utils.js'), 'yippy skippy ying yang yow');
try {
fs.symlinkSync(tmpFile('mocha-utils.js'), tmpFile('mocha-utils-link.js'));
symlinkSupported = true;
} catch (ignored) {
}
(function testSymlinkSupport() {
makeTempDir();

cleanup();
fs.writeFileSync(tmpFile('mocha-utils.js'), 'yippy skippy ying yang yow');
try {
fs.symlinkSync(tmpFile('mocha-utils.js'), tmpFile('mocha-utils-link.js'));
symlinkSupported = true;
} catch (ignored) {
// ignored
} finally {
removeTempDir();
}
}());

beforeEach(function() {
makeTempDir();

fs.writeFileSync(tmpFile('mocha-utils.js'), 'yippy skippy ying yang yow');
if (symlinkSupported) {
fs.symlinkSync(tmpFile('mocha-utils.js'), tmpFile('mocha-utils-link.js'));
Expand Down Expand Up @@ -66,18 +78,13 @@ describe('lookupFiles', function() {
.length(expectedLength);
});

afterEach(cleanup);
afterEach(removeTempDir);

function makeTempDir() {
mkdirp.sync(tmpDir);
}

function cleanup() {
[
'mocha-utils.js',
'mocha-utils-link.js',
'bob'
].forEach(function(path) {
try {
fs.unlinkSync(tmpFile(path));
} catch (ignored) {
}
});
function removeTempDir() {
rimraf.sync(tmpDir);
}
});

0 comments on commit 59b03a7

Please sign in to comment.