From 689b64937cd79d2b8bf430377e1a33814e98b643 Mon Sep 17 00:00:00 2001 From: Ethan Hur Date: Wed, 9 Oct 2019 01:37:44 +0900 Subject: [PATCH] replace Bluebird.map to Promise.all --- test/integration/migrate/index.js | 155 ++++++++++++++++-------------- 1 file changed, 83 insertions(+), 72 deletions(-) diff --git a/test/integration/migrate/index.js b/test/integration/migrate/index.js index b252d1c918..011c8c8576 100644 --- a/test/integration/migrate/index.js +++ b/test/integration/migrate/index.js @@ -410,21 +410,23 @@ module.exports = function(knex) { // Map the table names to promises that evaluate chai expectations to // confirm that the table exists and the 'id' and 'name' columns exist // within the table - return Bluebird.map(tables, function(table) { - return knex.schema.hasTable(table).then(function(exists) { - expect(exists).to.equal(true); - if (exists) { - return Promise.all([ - knex.schema.hasColumn(table, 'id').then(function(exists) { - expect(exists).to.equal(true); - }), - knex.schema.hasColumn(table, 'name').then(function(exists) { - expect(exists).to.equal(true); - }), - ]); - } - }); - }); + return Promise.all( + tables.map(function(table) { + return knex.schema.hasTable(table).then(function(exists) { + expect(exists).to.equal(true); + if (exists) { + return Promise.all([ + knex.schema.hasColumn(table, 'id').then(function(exists) { + expect(exists).to.equal(true); + }), + knex.schema.hasColumn(table, 'name').then(function(exists) { + expect(exists).to.equal(true); + }), + ]); + } + }); + }) + ); }); }); @@ -459,11 +461,13 @@ module.exports = function(knex) { 'migration_test_4_1', ]; - return Bluebird.map(expectedTables, function(table) { - return knex.schema.hasTable(table).then(function(exists) { - expect(exists).to.equal(true); - }); - }); + return Promise.all( + expectedTables.map(function(table) { + return knex.schema.hasTable(table).then(function(exists) { + expect(exists).to.equal(true); + }); + }) + ); }); }); @@ -484,11 +488,13 @@ module.exports = function(knex) { }); it('should drop tables as specified in the batch', function() { - return Bluebird.map(tables, function(table) { - return knex.schema.hasTable(table).then(function(exists) { - expect(!!exists).to.equal(false); - }); - }); + return Promise.all( + tables.map(function(table) { + return knex.schema.hasTable(table).then(function(exists) { + expect(!!exists).to.equal(false); + }); + }) + ); }); }); @@ -531,11 +537,13 @@ module.exports = function(knex) { }); it('should drop tables as specified in the batch', () => { - return Bluebird.map(tables, function(table) { - return knex.schema.hasTable(table).then(function(exists) { - expect(!!exists).to.equal(false); - }); - }); + return Promise.all( + tables.map(function(table) { + return knex.schema.hasTable(table).then(function(exists) { + expect(!!exists).to.equal(false); + }); + }) + ); }); }); @@ -576,11 +584,13 @@ module.exports = function(knex) { }); it('should drop tables as specified in the batch', () => { - return Bluebird.map(tables, function(table) { - return knex.schema.hasTable(table).then(function(exists) { - expect(!!exists).to.equal(false); - }); - }); + return Promise.all( + tables.map(function(table) { + return knex.schema.hasTable(table).then(function(exists) { + expect(!!exists).to.equal(false); + }); + }) + ); }); }); @@ -746,28 +756,27 @@ module.exports = function(knex) { } it('is not able to run two migrations in parallel when transactions are disabled', function() { - return Bluebird.map( - [ - knex.migrate - .latest({ - directory: 'test/integration/migrate/test', - disableTransactions: true, - }) - .catch(function(err) { - return err; - }), - knex.migrate - .latest({ - directory: 'test/integration/migrate/test', - disableTransactions: true, - }) - .catch(function(err) { - return err; - }), - ], - function(res) { - return res && res.name; - } + const migrations = [ + knex.migrate + .latest({ + directory: 'test/integration/migrate/test', + disableTransactions: true, + }) + .catch(function(err) { + return err; + }), + knex.migrate + .latest({ + directory: 'test/integration/migrate/test', + disableTransactions: true, + }) + .catch(function(err) { + return err; + }), + ]; + + return Promise.all( + migrations.map((migration) => migration.then((res) => res && res.name)) ).then(function(res) { // One should fail: const hasLockError = @@ -993,21 +1002,23 @@ module.exports = function(knex) { 'migration_test_2', 'migration_test_2_1a', ]; - return Bluebird.map(tables, function(table) { - return knex.schema.hasTable(table).then(function(exists) { - expect(exists).to.equal(true); - if (exists) { - return Promise.all([ - knex.schema.hasColumn(table, 'id').then(function(exists) { - expect(exists).to.equal(true); - }), - knex.schema.hasColumn(table, 'name').then(function(exists) { - expect(exists).to.equal(true); - }), - ]); - } - }); - }); + return Promise.all( + tables.map(function(table) { + return knex.schema.hasTable(table).then(function(exists) { + expect(exists).to.equal(true); + if (exists) { + return Promise.all([ + knex.schema.hasColumn(table, 'id').then(function(exists) { + expect(exists).to.equal(true); + }), + knex.schema.hasColumn(table, 'name').then(function(exists) { + expect(exists).to.equal(true); + }), + ]); + } + }); + }) + ); }); it('should not create unexpected tables', function() {