mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-11 18:35:22 +03:00
Wrapped test teardown in a fallback
- The fast truncateAll method can fail - If it does, use knex-migrate to do a safe reset of the DB instead - This is being done to try to make test runs more reliable in the face of database errors
This commit is contained in:
parent
b90e367563
commit
11a792f7df
@ -49,7 +49,7 @@ module.exports.reset = async ({truncate} = {truncate: false}) => {
|
||||
if (truncate) {
|
||||
// Perform a fast reset by tearing down all the tables and inserting the fixtures
|
||||
try {
|
||||
await module.exports.teardown();
|
||||
await truncateAll();
|
||||
await knexMigrator.init({only: 2});
|
||||
} catch (err) {
|
||||
// If it fails, try a normal restore
|
||||
@ -96,11 +96,22 @@ module.exports.clearData = async () => {
|
||||
urlServiceUtils.reset();
|
||||
};
|
||||
|
||||
/**
|
||||
* Reset the database to tables only
|
||||
*/
|
||||
module.exports.teardown = async () => {
|
||||
try {
|
||||
await truncateAll();
|
||||
} catch (err) {
|
||||
await knexMigrator.reset({force: true});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Has to run in a transaction for MySQL, otherwise the foreign key check does not work.
|
||||
* Sqlite3 has no truncate command.
|
||||
*/
|
||||
module.exports.teardown = () => {
|
||||
const truncateAll = () => {
|
||||
debug('Database teardown');
|
||||
urlServiceUtils.reset();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user