Clean up folders in after test runs

This commit is contained in:
Pavel Djundik 2020-03-16 14:40:21 +02:00
parent 487a438f02
commit 6de6f8185e
2 changed files with 25 additions and 1 deletions

View file

@ -16,13 +16,13 @@ describe("SQLite Message Storage", function () {
const expectedPath = path.join(Helper.getHomePath(), "logs", "testUser.sqlite3");
let store;
// Delete database file from previous test run
before(function (done) {
store = new MessageStorage({
name: "testUser",
idMsg: 1,
});
// Delete database file from previous test run
if (fs.existsSync(expectedPath)) {
fs.unlink(expectedPath, done);
} else {
@ -30,6 +30,13 @@ describe("SQLite Message Storage", function () {
}
});
after(function (done) {
// After tests run, remove the logs folder
// so we return to the clean state
fs.unlinkSync(expectedPath);
fs.rmdir(path.join(Helper.getHomePath(), "logs"), done);
});
it("should resolve an empty array when disabled", function (done) {
store.getMessages(null, null).then((messages) => {
expect(messages).to.be.empty;

View file

@ -6,6 +6,7 @@ const crypto = require("crypto");
const expect = require("chai").expect;
const util = require("../util");
const Helper = require("../../src/helper");
const storage = require("../../src/plugins/storage");
const link = require("../../src/plugins/irc-events/link.js");
describe("Image storage", function () {
@ -51,6 +52,13 @@ describe("Image storage", function () {
this.connection.close(done);
});
after(function (done) {
// After storage tests run, remove the remaining empty
// storage folder so we return to the clean state
const dir = Helper.getStoragePath();
fs.rmdir(dir, done);
});
beforeEach(function () {
this.irc = util.createClient();
this.network = util.createNetwork();
@ -125,4 +133,13 @@ describe("Image storage", function () {
done();
});
});
it("should clear storage folder", function () {
const dir = Helper.getStoragePath();
expect(fs.readdirSync(dir)).to.not.be.empty;
storage.emptyDir();
expect(fs.readdirSync(dir)).to.be.empty;
expect(fs.existsSync(dir)).to.be.true;
});
});