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

Commit 027a274

Browse files
committed
Implement teardown
1 parent 5e12762 commit 027a274

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,23 @@ module.exports = {
339339
},
340340

341341
teardown: function (context) {
342+
console.log(this);
343+
let tmp = this.readConfig('projectTmpPath');
344+
let repoTmpPath = path.join(tmp, this.readConfig('repoTmpPath'));
345+
repoTmpPath = path.resolve(context.project.root, repoTmpPath);
346+
347+
return new Promise((resolve, reject) => {
348+
this.log('cleaning up');
349+
fs.remove(repoTmpPath, error => {
350+
if (error) {
351+
this.log(error, { color: 'red' });
352+
reject(error);
353+
}
354+
355+
this.log('cleanup complete', { color: 'green' });
356+
resolve();
357+
});
358+
});
342359
}
343360
});
344361

tests/unit/index-test.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,15 @@ describe('github pages plugin', function () {
5959
});
6060
});
6161

62-
// after(function (done) {
63-
// fs.remove(repoPath, function () {
64-
// done();
65-
// });
62+
// afterEach(function (done) {
63+
// fs.remove(repoPath, function () {
64+
// done();
65+
// });
66+
// plugin.teardown(context)
67+
// .then(() => done())
68+
// .catch(error => {
69+
// done(error);
70+
// });
6671
// });
6772

6873
it('has a name', function () {
@@ -237,4 +242,20 @@ describe('github pages plugin', function () {
237242
});
238243
});
239244
});
245+
246+
describe('#teardown hook', function () {
247+
before(function (done) {
248+
plugin.beforeHook(context);
249+
plugin.teardown(context)
250+
.then(() => done());
251+
});
252+
253+
it('performs cleanup', function () {
254+
function checkPath() {
255+
fs.accessSync(repoPath, fs.F_OK);
256+
}
257+
258+
expect(checkPath).to.throw(Error);
259+
});
260+
});
240261
});

0 commit comments

Comments
 (0)