diff --git a/.gitignore b/.gitignore index a2f0c1e..146d798 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ node_modules # created by testing /store-backup +/database-backup # managed by application /database diff --git a/package.json b/package.json index fb54081..df57ae6 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,10 @@ "typeorm:migrate:library": "typeorm migration:run -c library", "watch": "gulp build --watch --dev", "build": "gulp build", - "test:fast": "mocha --grep @slow --invert", - "test": "mocha", + "test:before": "node tests/setup/before.js", + "test:after": "node tests/setup/after.js", + "test:fast": "npm run test:before && mocha --grep @slow --invert && npm run test:after", + "test": "npm run test:before && mocha && npm run test:after", "coverage:fast": "nyc npm run test:fast", "coverage": "nyc npm run test", "lint:check": "npm run eslint:check && npm run tslint:check", diff --git a/tests/main/services/store.spec.ts b/tests/main/services/store.spec.ts index 0715920..6cbac1f 100644 --- a/tests/main/services/store.spec.ts +++ b/tests/main/services/store.spec.ts @@ -8,29 +8,16 @@ import path from 'path'; import { load, save, StoreKeys } from '../../../src/main/services/store'; const storeDirectory = path.resolve('store'); -const storeBackupDirectory = path.resolve('store-backup'); describe('Store Service', function() { this.timeout(10000); before(() => { rewiremock.enable(); - if (fs.existsSync(storeDirectory)) { - if (fs.existsSync(storeBackupDirectory)) { - fs.removeSync(storeBackupDirectory); - } - fs.moveSync(storeDirectory, storeBackupDirectory); - } }); after(() => { rewiremock.disable(); - if (fs.existsSync(storeBackupDirectory)) { - if (fs.existsSync(storeDirectory)) { - fs.removeSync(storeDirectory); - } - fs.moveSync(storeBackupDirectory, storeDirectory); - } }); beforeEach(() => { diff --git a/tests/setup/after.ts b/tests/setup/after.ts new file mode 100644 index 0000000..5e83412 --- /dev/null +++ b/tests/setup/after.ts @@ -0,0 +1,5 @@ +import 'mocha'; +import { databaseBackupDirectory, databaseDirectory, moveDir, storeBackupDirectory, storeDirectory } from './before'; + +moveDir(storeBackupDirectory, storeDirectory); +moveDir(databaseBackupDirectory, databaseDirectory); diff --git a/tests/setup/before.ts b/tests/setup/before.ts new file mode 100644 index 0000000..579c999 --- /dev/null +++ b/tests/setup/before.ts @@ -0,0 +1,21 @@ +import fs from 'fs-extra'; +import 'mocha'; +import path from 'path'; + +export const storeDirectory = path.resolve('store'); +export const storeBackupDirectory = path.resolve('store-backup'); + +export const databaseDirectory = path.resolve('database'); +export const databaseBackupDirectory = path.resolve('database-backup'); + +export function moveDir(fromDir: string, toDir: string) { + if (fs.existsSync(fromDir)) { + if (fs.existsSync(toDir)) { + fs.removeSync(toDir); + } + fs.moveSync(fromDir, toDir); + } +} + +moveDir(storeDirectory, storeBackupDirectory); +moveDir(databaseDirectory, databaseBackupDirectory);