Skip to content
This repository has been archived by the owner on Feb 7, 2024. It is now read-only.

Commit

Permalink
Implement teardown
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewJo committed Apr 21, 2016
1 parent 5e12762 commit 027a274
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
17 changes: 17 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,23 @@ module.exports = {
},

teardown: function (context) {
console.log(this);
let tmp = this.readConfig('projectTmpPath');
let repoTmpPath = path.join(tmp, this.readConfig('repoTmpPath'));
repoTmpPath = path.resolve(context.project.root, repoTmpPath);

return new Promise((resolve, reject) => {
this.log('cleaning up');
fs.remove(repoTmpPath, error => {
if (error) {
this.log(error, { color: 'red' });
reject(error);
}

this.log('cleanup complete', { color: 'green' });
resolve();
});
});
}
});

Expand Down
29 changes: 25 additions & 4 deletions tests/unit/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,15 @@ describe('github pages plugin', function () {
});
});

// after(function (done) {
// fs.remove(repoPath, function () {
// done();
// });
// afterEach(function (done) {
// fs.remove(repoPath, function () {
// done();
// });
// plugin.teardown(context)
// .then(() => done())
// .catch(error => {
// done(error);
// });
// });

it('has a name', function () {
Expand Down Expand Up @@ -237,4 +242,20 @@ describe('github pages plugin', function () {
});
});
});

describe('#teardown hook', function () {
before(function (done) {
plugin.beforeHook(context);
plugin.teardown(context)
.then(() => done());
});

it('performs cleanup', function () {
function checkPath() {
fs.accessSync(repoPath, fs.F_OK);
}

expect(checkPath).to.throw(Error);
});
});
});

0 comments on commit 027a274

Please sign in to comment.