Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Luc Didry
kresus
Commits
b5358450
Commit
b5358450
authored
May 05, 2019
by
Antoine
Browse files
[tests] Move 'unhandledRejection' handler and database setup to their own file.
parent
7db8a4e6
Changes
3
Hide whitespace changes
Inline
Side-by-side
scripts/check/test.sh
View file @
b5358450
...
...
@@ -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
tests/database/config.js
0 → 100644
View file @
b5358450
/* 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
'
);
});
tests/database/migrations.js
View file @
b5358450
...
...
@@ -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
'
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment