diff --git a/packages/babel-cli/test/index.js b/packages/babel-cli/test/index.js index 9e8af0d9b9..7aa457b00f 100644 --- a/packages/babel-cli/test/index.js +++ b/packages/babel-cli/test/index.js @@ -115,13 +115,6 @@ const buildTest = function(binName, testName, opts) { const binLoc = path.join(__dirname, "../lib", binName); return function(callback) { - const dir = process.cwd(); - - process.chdir(__dirname); - if (fs.existsSync(tmpLoc)) rimraf.sync(tmpLoc); - fs.mkdirSync(tmpLoc); - process.chdir(tmpLoc); - saveInFiles(opts.inFiles); let args = [binLoc]; @@ -159,7 +152,6 @@ const buildTest = function(binName, testName, opts) { args.map(arg => `"${arg}"`).join(" ") + ": " + err.message; } - process.chdir(dir); callback(err); }); @@ -175,6 +167,26 @@ fs.readdirSync(fixtureLoc).forEach(function(binName) { const suiteLoc = path.join(fixtureLoc, binName); describe("bin/" + binName, function() { + let cwd; + + beforeEach(() => { + cwd = process.cwd(); + + if (fs.existsSync(tmpLoc)) { + for (const child of fs.readdirSync(tmpLoc)) { + rimraf.sync(path.join(tmpLoc, child)); + } + } else { + fs.mkdirSync(tmpLoc); + } + + process.chdir(tmpLoc); + }); + + afterEach(() => { + process.chdir(cwd); + }); + fs.readdirSync(suiteLoc).forEach(function(testName) { if (testName.startsWith(".")) return; diff --git a/packages/babel-node/test/index.js b/packages/babel-node/test/index.js index 9fd61c73f8..45283de769 100644 --- a/packages/babel-node/test/index.js +++ b/packages/babel-node/test/index.js @@ -99,7 +99,6 @@ const buildTest = function(binName, testName, opts) { const binLoc = path.join(__dirname, "../lib", binName); return function(callback) { - clear(); saveInFiles(opts.inFiles); let args = [binLoc]; @@ -146,13 +145,6 @@ const buildTest = function(binName, testName, opts) { }; }; -const clear = function() { - process.chdir(__dirname); - if (fs.existsSync(tmpLoc)) rimraf.sync(tmpLoc); - fs.mkdirSync(tmpLoc); - process.chdir(tmpLoc); -}; - fs.readdirSync(fixtureLoc).forEach(function(binName) { if (binName[0] === ".") return; @@ -162,6 +154,16 @@ fs.readdirSync(fixtureLoc).forEach(function(binName) { beforeEach(() => { cwd = process.cwd(); + + if (fs.existsSync(tmpLoc)) { + for (const child of fs.readdirSync(tmpLoc)) { + rimraf.sync(path.join(tmpLoc, child)); + } + } else { + fs.mkdirSync(tmpLoc); + } + + process.chdir(tmpLoc); }); afterEach(() => {