Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

fix wonky lookupFiles test; closes #2347

Christopher Hillercbf9bca72345
diff --git a/package.json b/package.json
index 1ca94777..e77b31fc 100644
--- a/package.json
+++ b/package.json
@@ -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"
diff --git a/test/acceptance/lookup-files.js b/test/acceptance/lookup-files.js
index 958f1b70..5d4a48d8 100644
--- a/test/acceptance/lookup-files.js
+++ b/test/acceptance/lookup-files.js
@@ -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'));
@@ -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);
}
});