Skip to content

Commit

Permalink
1403-running-tests-against-shared-db
Browse files Browse the repository at this point in the history
  • Loading branch information
basarbk committed Aug 4, 2020
1 parent 0165967 commit d3a752f
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 8 deletions.
4 changes: 3 additions & 1 deletion __tests__/Auth.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ const en = require('../locales/en/translation.json');
const tr = require('../locales/tr/translation.json');

beforeAll(async () => {
await sequelize.sync();
if (process.env.NODE_ENV === 'test') {
await sequelize.sync();
}
});

beforeEach(async () => {
Expand Down
4 changes: 3 additions & 1 deletion __tests__/PasswordReset.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ beforeAll(async () => {

await server.listen(config.mail.port, 'localhost');

await sequelize.sync();
if (process.env.NODE_ENV === 'test') {
await sequelize.sync();
}
jest.setTimeout(20000);
});

Expand Down
4 changes: 3 additions & 1 deletion __tests__/TokenService.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ const Token = require('../src/auth/Token');
const TokenService = require('../src/auth/TokenService');

beforeAll(async () => {
await sequelize.sync();
if (process.env.NODE_ENV === 'test') {
await sequelize.sync();
}
});

beforeEach(async () => {
Expand Down
4 changes: 3 additions & 1 deletion __tests__/UserDelete.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ const en = require('../locales/en/translation.json');
const tr = require('../locales/tr/translation.json');

beforeAll(async () => {
await sequelize.sync();
if (process.env.NODE_ENV === 'test') {
await sequelize.sync();
}
});

beforeEach(async () => {
Expand Down
4 changes: 3 additions & 1 deletion __tests__/UserListing.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ const en = require('../locales/en/translation.json');
const tr = require('../locales/tr/translation.json');

beforeAll(async () => {
await sequelize.sync();
if (process.env.NODE_ENV === 'test') {
await sequelize.sync();
}
});

beforeEach(async () => {
Expand Down
4 changes: 3 additions & 1 deletion __tests__/UserRegister.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ beforeAll(async () => {

await server.listen(config.mail.port, 'localhost');

await sequelize.sync();
if (process.env.NODE_ENV === 'test') {
await sequelize.sync();
}
jest.setTimeout(20000);
});

Expand Down
4 changes: 3 additions & 1 deletion __tests__/UserUpdate.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ const { uploadDir, profileDir } = config;
const profileDirectory = path.join('.', uploadDir, profileDir);

beforeAll(async () => {
await sequelize.sync();
if (process.env.NODE_ENV === 'test') {
await sequelize.sync();
}
});

beforeEach(async () => {
Expand Down
19 changes: 19 additions & 0 deletions config/staging.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
database: {
database: 'hoaxify',
username: 'my-db-user',
password: 'db-p4ss',
dialect: 'sqlite',
storage: './staging.sqlite',
logging: false,
},
mail: {
host: 'localhost',
port: Math.floor(Math.random() * 2000) + 10000,
tls: {
rejectUnauthorized: false,
},
},
uploadDir: 'uploads-staging',
profileDir: 'profile',
};
8 changes: 8 additions & 0 deletions database/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,13 @@
"host": "localhost",
"dialect": "sqlite",
"storage": "./database.sqlite"
},
"staging": {
"username": "my-db-user",
"password": "db-p4ss",
"database": "hoaxify",
"host": "localhost",
"dialect": "sqlite",
"storage": "./staging.sqlite"
}
}
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
"start": "cross-env NODE_ENV=development nodemon index",
"test": "cross-env NODE_ENV=test jest --watch",
"posttest": "cross-env NODE_ENV=test node test-cleanup",
"lint": "eslint ."
"lint": "eslint .",
"test:staging": "cross-env NODE_ENV=staging jest -f . --runInBand",
"migrate:test": "cross-env NODE_ENV=staging sequelize-cli db:migrate",
"pretest:staging": "npm run migrate:test"
},
"author": "Basar Buyukkahraman",
"license": "ISC",
Expand Down

0 comments on commit d3a752f

Please sign in to comment.