Skip to content

Commit 9c9b20a

Browse files
committed
better test cleanup
1 parent afd1125 commit 9c9b20a

1 file changed

Lines changed: 20 additions & 11 deletions

File tree

‎test/Compiler-caching.test.js‎

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,28 @@ describe("Compiler (caching)", function() {
9292
var aFilepath = path.join(tempFixturePath, 'a.js');
9393
var cFilepath = path.join(tempFixturePath, 'c.js');
9494

95-
after(function() {
96-
try {
97-
if(fs.statSync(tempFixturePath)) {
98-
fs.unlinkSync(aFilepath);
99-
fs.unlinkSync(cFilepath);
100-
fs.rmdirSync(tempFixturePath);
101-
}
102-
} catch(e) {
103-
if(e.code !== 'ENOENT') {
104-
throw e;
95+
function cleanup() {
96+
function ignoreENOENT(fn) {
97+
try {
98+
return fn();
99+
} catch(e) {
100+
if(e.code !== 'ENOENT') {
101+
throw e;
102+
}
105103
}
106104
}
107-
})
105+
ignoreENOENT(function() {
106+
fs.unlinkSync(aFilepath);
107+
});
108+
ignoreENOENT(function() {
109+
fs.unlinkSync(cFilepath);
110+
});
111+
ignoreENOENT(function() {
112+
fs.rmdirSync(tempFixturePath);
113+
});
114+
}
115+
before(cleanup);
116+
after(cleanup);
108117

109118
function createTempFixture() {
110119

0 commit comments

Comments
 (0)