From e622be01c6e2bbec8501e3ba2630d98fd847fa96 Mon Sep 17 00:00:00 2001 From: Jarrod Overson Date: Sat, 15 Jun 2013 11:50:37 -0700 Subject: [PATCH] async teardown and .grunt removal, closes #58 --- package.json | 2 +- tasks/jasmine.js | 13 +++++++------ tasks/lib/jasmine.js | 7 +++++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index f943cd2..67c57e4 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ }, "dependencies": { "grunt-lib-phantomjs": "~0.3.0", - "rimraf": "~2.0.3" + "rimraf": "~2.1.4" }, "devDependencies": { "grunt-contrib-internal": "~0.4.0", diff --git a/tasks/jasmine.js b/tasks/jasmine.js index 13274b6..bd23731 100644 --- a/tasks/jasmine.js +++ b/tasks/jasmine.js @@ -68,8 +68,9 @@ module.exports = function(grunt) { else grunt.log.error(status.failed + ' failures'); options.keepRunner = options.keepRunner || !success; - teardown(options); - done(success); + teardown(options, function(){ + done(success); + }); }); }); @@ -99,12 +100,12 @@ module.exports = function(grunt) { }); } - function teardown(options) { - if (!options.keepRunner && fs.statSync(options.outfile).isFile()) fs.unlink(options.outfile); - if (!options.keepRunner) jasmine.cleanTemp(); - + function teardown(options, cb) { phantomjs.removeAllListeners(); phantomjs.listenersAny().length = 0; + + if (!options.keepRunner && fs.statSync(options.outfile).isFile()) fs.unlink(options.outfile); + if (!options.keepRunner) jasmine.cleanTemp(cb); } function setup(options) { diff --git a/tasks/lib/jasmine.js b/tasks/lib/jasmine.js index 191612f..9ca7a20 100644 --- a/tasks/lib/jasmine.js +++ b/tasks/lib/jasmine.js @@ -24,8 +24,11 @@ exports.init = function(grunt, phantomjs) { grunt.file.copy(src, file); }; - exports.cleanTemp = function() { - rimraf.sync(tempDir); + exports.cleanTemp = function(cb) { + rimraf(tempDir, function(){ + // if this fails, then ./.grunt isn't empty and that's ok. + fs.rmdir('.grunt', cb); + }); }; exports.buildSpecrunner = function (src, options){