Commit b5358450 authored by Antoine's avatar Antoine
Browse files

[tests] Move 'unhandledRejection' handler and database setup to their own file.

parent 7db8a4e6
......@@ -5,5 +5,6 @@ set -e
BABEL_ENV=tests NODE_ENV=test mocha \
--require @babel/polyfill \
--require @babel/register \
--file ./tests/database/config.js\
--recursive ./tests \
--timeout 120000
/* eslint-disable no-console */
// There's a bug between eslint and prettier with spacing around async arrow
// functions, so we need to explicitly use async functions instead.
/* eslint-disable prefer-arrow-callback */
import PouchDB from 'pouchdb';
import { apply as applyConfig } from '../../server/config';
// eslint-disable-next-line import/named
import { testing as serverTesting } from '../../server';
process.on('unhandledRejection', (reason, promise) => {
promise.catch(err => {
console.error('Reason: ', reason);
console.error('Promise stack trace: ', err.stack || err);
});
throw new Error(`Unhandled promise rejection (promise stack trace is in the logs): ${reason}`);
});
before(async function() {
// Set process.kresus.user for models.
applyConfig({});
// Set a temporary database for testing.
let options = {
dbName: '/tmp/kresus-test-db'
};
options.db = new PouchDB(options.dbName, { auto_compaction: true });
await serverTesting.configureCozyDB(options);
// Initialize models.
let initModels = require('../../server/models');
await initModels();
console.log('Database ready');
});
......@@ -7,22 +7,8 @@
// Testing for undefined values is done in a way that makes the linter thinks the line is unused.
/* eslint-disable no-unused-expressions */
import PouchDB from 'pouchdb';
import { apply as applyConfig } from '../../server/config';
// eslint-disable-next-line import/named
import { testing as serverTesting } from '../../server';
import { UNKNOWN_OPERATION_TYPE } from '../../shared/helpers';
process.on('unhandledRejection', (reason, promise) => {
promise.catch(err => {
console.error('Reason: ', reason);
console.error('Promise stack trace: ', err.stack || err);
});
throw new Error(`Unhandled promise rejection (promise stack trace is in the logs): ${reason}`);
});
let Accesses = null;
let Accounts = null;
let Alerts = null;
......@@ -37,20 +23,6 @@ let TransactionTypes = null;
let MIGRATIONS = null;
before(async function() {
// Set process.kresus.user for models.
applyConfig({});
// Set a temporary database for testing.
let options = {
dbName: '/tmp/kresus-test-db'
};
options.db = new PouchDB(options.dbName, { auto_compaction: true });
await serverTesting.configureCozyDB(options);
// Initialize models.
let initModels = require('../../server/models');
await initModels();
Accesses = require('../../server/models/accesses');
Accounts = require('../../server/models/accounts');
Alerts = require('../../server/models/alerts');
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment