test: add test setup files for backing up store and database folders before tests
This commit is contained in:
parent
7c2aaacf13
commit
b73e14f0ab
|
@ -15,6 +15,7 @@ node_modules
|
||||||
|
|
||||||
# created by testing
|
# created by testing
|
||||||
/store-backup
|
/store-backup
|
||||||
|
/database-backup
|
||||||
|
|
||||||
# managed by application
|
# managed by application
|
||||||
/database
|
/database
|
||||||
|
|
|
@ -13,8 +13,10 @@
|
||||||
"typeorm:migrate:library": "typeorm migration:run -c library",
|
"typeorm:migrate:library": "typeorm migration:run -c library",
|
||||||
"watch": "gulp build --watch --dev",
|
"watch": "gulp build --watch --dev",
|
||||||
"build": "gulp build",
|
"build": "gulp build",
|
||||||
"test:fast": "mocha --grep @slow --invert",
|
"test:before": "node tests/setup/before.js",
|
||||||
"test": "mocha",
|
"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:fast": "nyc npm run test:fast",
|
||||||
"coverage": "nyc npm run test",
|
"coverage": "nyc npm run test",
|
||||||
"lint:check": "npm run eslint:check && npm run tslint:check",
|
"lint:check": "npm run eslint:check && npm run tslint:check",
|
||||||
|
|
|
@ -8,29 +8,16 @@ import path from 'path';
|
||||||
import { load, save, StoreKeys } from '../../../src/main/services/store';
|
import { load, save, StoreKeys } from '../../../src/main/services/store';
|
||||||
|
|
||||||
const storeDirectory = path.resolve('store');
|
const storeDirectory = path.resolve('store');
|
||||||
const storeBackupDirectory = path.resolve('store-backup');
|
|
||||||
|
|
||||||
describe('Store Service', function() {
|
describe('Store Service', function() {
|
||||||
this.timeout(10000);
|
this.timeout(10000);
|
||||||
|
|
||||||
before(() => {
|
before(() => {
|
||||||
rewiremock.enable();
|
rewiremock.enable();
|
||||||
if (fs.existsSync(storeDirectory)) {
|
|
||||||
if (fs.existsSync(storeBackupDirectory)) {
|
|
||||||
fs.removeSync(storeBackupDirectory);
|
|
||||||
}
|
|
||||||
fs.moveSync(storeDirectory, storeBackupDirectory);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
after(() => {
|
after(() => {
|
||||||
rewiremock.disable();
|
rewiremock.disable();
|
||||||
if (fs.existsSync(storeBackupDirectory)) {
|
|
||||||
if (fs.existsSync(storeDirectory)) {
|
|
||||||
fs.removeSync(storeDirectory);
|
|
||||||
}
|
|
||||||
fs.moveSync(storeBackupDirectory, storeDirectory);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
import 'mocha';
|
||||||
|
import { databaseBackupDirectory, databaseDirectory, moveDir, storeBackupDirectory, storeDirectory } from './before';
|
||||||
|
|
||||||
|
moveDir(storeBackupDirectory, storeDirectory);
|
||||||
|
moveDir(databaseBackupDirectory, databaseDirectory);
|
|
@ -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);
|
Loading…
Reference in New Issue