From 30202025978fe33af6feb8ad890bb20c73ffe25a Mon Sep 17 00:00:00 2001 From: oleg Date: Fri, 24 Jan 2020 22:14:19 +0300 Subject: [PATCH 1/2] connect megrator before removeMigratorDir testUtils/createMigrator - fixes not reliable tests with mongodb adapter --- testUtils/createMigrator.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/testUtils/createMigrator.js b/testUtils/createMigrator.js index 68d37323..4ea5b2d4 100644 --- a/testUtils/createMigrator.js +++ b/testUtils/createMigrator.js @@ -16,6 +16,8 @@ module.exports = (params) => { return Promise.resolve() .then(() => migrator.configure(params.configureParams)) + // always connect migrator coz `removeDirBefore` makes unmark executed + .then(() => migrator.connect()) .then(() => { if (params.removeDirBefore) { return removeMigratorDir(migrator); @@ -27,8 +29,9 @@ module.exports = (params) => { } }) .then(() => { - if (params.connect) { - return migrator.connect(); + // disconnect if connected was not required + if (!params.connect) { + return migrator.disconnect(); } }) .then(() => migrator); From c279a9b543ba77d3847d3d6cab341c7617af55d3 Mon Sep 17 00:00:00 2001 From: oleg Date: Fri, 24 Jan 2020 22:24:04 +0300 Subject: [PATCH 2/2] make create with numbers and dates tests more similar --- .../create/withDateTimeMigrationNumberFormat.js | 17 ++++++++++++++++- .../withSequentialMigrationNumberFormat.js | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/test/01-migrator/create/withDateTimeMigrationNumberFormat.js b/test/01-migrator/create/withDateTimeMigrationNumberFormat.js index 61cb3013..10f2d60c 100644 --- a/test/01-migrator/create/withDateTimeMigrationNumberFormat.js +++ b/test/01-migrator/create/withDateTimeMigrationNumberFormat.js @@ -2,6 +2,7 @@ const tap = require('tap'); const expect = require('expect.js'); +const pEachSeries = require('p-each-series'); const testUtils = require('../../../testUtils'); tap.mochaGlobals(); @@ -38,7 +39,7 @@ describe('migrator create with date time migration number format', () => { migrator.params.migrationNumberFormat = 'sequentialNumber'; }); - it('should create new files with a dateTime prefix', () => { + it('should create migrations without errors', () => { return Promise.resolve() .then(() => testUtils.createMigrations({migrator, baseNames})) .then((migrationNames) => { @@ -51,4 +52,18 @@ describe('migrator create with date time migration number format', () => { expect(name).to.match(new RegExp(`^[0-9]{14}_${baseNames[index]}$`)); }); }); + + it('created migrations should exist', () => { + return migrator.checkMigrationsExists(names); + }); + + it('created migrations should be loadable', () => { + return pEachSeries(names, (name) => migrator.loadMigration(name)); + }); + + it('created migrations should be listed as `new`', () => { + return Promise.resolve() + .then(() => migrator.getNewMigrationNames()) + .then((newNames) => expect(newNames).eql(names)); + }); }); diff --git a/test/01-migrator/create/withSequentialMigrationNumberFormat.js b/test/01-migrator/create/withSequentialMigrationNumberFormat.js index 70ec20ad..f557a2f5 100644 --- a/test/01-migrator/create/withSequentialMigrationNumberFormat.js +++ b/test/01-migrator/create/withSequentialMigrationNumberFormat.js @@ -31,7 +31,7 @@ describe('migrator create with sequential migration number format', () => { after(() => testUtils.destroyEnv(testEnv)); - it('should create migrations sequentially without errors', () => { + it('should create migrations without errors', () => { return Promise.resolve() .then(() => testUtils.createMigrations({migrator, baseNames})) .then((migrationNames) => {