From e0539a397c0673e1213b8d88ecfcbf99d3b28dae Mon Sep 17 00:00:00 2001 From: Agnes Lin Date: Mon, 17 Jun 2019 16:13:15 -0400 Subject: [PATCH] feat: run shared tests from v3 n v4 of juggler --- .eslintignore | 1 + deps/juggler-v3/package.json | 8 ++++++++ deps/juggler-v3/test.js | 31 +++++++++++++++++++++++++++++++ deps/juggler-v4/package.json | 8 ++++++++ deps/juggler-v4/test.js | 30 ++++++++++++++++++++++++++++++ package.json | 4 +++- test.js | 6 ++++-- test/imported.test.js | 14 -------------- test/init.js | 16 +++++++++++++--- 9 files changed, 98 insertions(+), 20 deletions(-) create mode 100644 .eslintignore create mode 100644 deps/juggler-v3/package.json create mode 100644 deps/juggler-v3/test.js create mode 100644 deps/juggler-v4/package.json create mode 100644 deps/juggler-v4/test.js diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000..7cd53fdb --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +**/node_modules/ diff --git a/deps/juggler-v3/package.json b/deps/juggler-v3/package.json new file mode 100644 index 00000000..b8b11477 --- /dev/null +++ b/deps/juggler-v3/package.json @@ -0,0 +1,8 @@ +{ + "name": "juggler-v3", + "version": "3.0.0", + "dependencies": { + "loopback-datasource-juggler":"3.x", + "should": "^8.4.0" + } +} diff --git a/deps/juggler-v3/test.js b/deps/juggler-v3/test.js new file mode 100644 index 00000000..b5229a2d --- /dev/null +++ b/deps/juggler-v3/test.js @@ -0,0 +1,31 @@ +// Copyright IBM Corp. 2019. All Rights Reserved. +// Node module: loopback-connector-cloudant +// This file is licensed under the Artistic License 2.0. +// License text available at https://opensource.org/licenses/Artistic-2.0 + +'use strict'; + +const juggler = require('loopback-datasource-juggler'); +const name = require('./package.json').name; + +require('../../test/init.js'); + +describe(name, function() { + before(function() { + global.IMPORTED_TEST = true; + return global.resetDataSourceClass(juggler.DataSource); + }); + + after(function() { + global.IMPORTED_TEST = false; + return global.resetDataSourceClass(); + }); + require('loopback-datasource-juggler/test/include.test.js'); + require('loopback-datasource-juggler/test/common.batch.js'); +}); + +/* TODO: run persistence-hooks, default scope test suites too + var testHooks = require('loopback-datasource-juggler/test/persistence-hooks.suite.js'); + var testDefaultScope = require('loopback-datasource-juggler/test/default-scope.test.js'); + */ + diff --git a/deps/juggler-v4/package.json b/deps/juggler-v4/package.json new file mode 100644 index 00000000..e73724e5 --- /dev/null +++ b/deps/juggler-v4/package.json @@ -0,0 +1,8 @@ +{ + "name": "juggler-v4", + "version": "4.0.0", + "dependencies": { + "loopback-datasource-juggler":"4.x", + "should": "^13.2.3" + } +} diff --git a/deps/juggler-v4/test.js b/deps/juggler-v4/test.js new file mode 100644 index 00000000..2406bab1 --- /dev/null +++ b/deps/juggler-v4/test.js @@ -0,0 +1,30 @@ +// Copyright IBM Corp. 2019. All Rights Reserved. +// Node module: loopback-connector-cloudant +// This file is licensed under the Artistic License 2.0. +// License text available at https://opensource.org/licenses/Artistic-2.0 + +'use strict'; + +const juggler = require('loopback-datasource-juggler'); +const name = require('./package.json').name; + +require('../../test/init.js'); + +describe(name, function() { + before(function() { + global.IMPORTED_TEST = true; + return global.resetDataSourceClass(juggler.DataSource); + }); + + after(function() { + global.IMPORTED_TEST = false; + return global.resetDataSourceClass(); + }); + require('loopback-datasource-juggler/test/include.test.js'); + require('loopback-datasource-juggler/test/common.batch.js'); +}); + +/* TODO: run persistence-hooks, default scope test suites too + var testHooks = require('loopback-datasource-juggler/test/persistence-hooks.suite.js'); + var testDefaultScope = require('loopback-datasource-juggler/test/default-scope.test.js'); + */ diff --git a/package.json b/package.json index 727f27ca..fef1ee96 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,9 @@ "dockerode": "^2.4.3", "eslint": "^5.16.0", "eslint-config-loopback": "^13.1.0", - "loopback-datasource-juggler": "^3.0.0", + "juggler-v3": "file:./deps/juggler-v3", + "juggler-v4": "file:./deps/juggler-v4", + "loopback-datasource-juggler": "^3.0.0 || ^4.0.0", "mocha": "^5.2.0", "ms": "^2.0.0", "rc": "^1.1.5", diff --git a/test.js b/test.js index 279aa00f..84a6a797 100644 --- a/test.js +++ b/test.js @@ -37,8 +37,10 @@ async.waterfall([ setCloudantEnv, waitFor('/_all_dbs'), createDB('test-db'), - run([mochaBin, '--timeout', '40000', '--require', 'strong-mocha-interfaces', - '--require', 'test/init.js', '--ui', 'strong-bdd']), + run([mochaBin, 'test/*.test.js', 'node_modules/juggler-v3/test.js', + 'node_modules/juggler-v4/test.js', '--timeout', '40000', + '--require', 'strong-mocha-interfaces', '--require', 'test/init.js', + '--ui', 'strong-bdd']), ], function(testErr) { dockerCleanup(function(cleanupErr) { if (cleanupErr) { diff --git a/test/imported.test.js b/test/imported.test.js index ebb4cac3..6032f352 100644 --- a/test/imported.test.js +++ b/test/imported.test.js @@ -5,20 +5,6 @@ 'use strict'; -describe('cloudant imported features', function() { - before(function() { - global.IMPORTED_TEST = true; - }); - - after(function() { - global.IMPORTED_TEST = false; - }); - - require('loopback-datasource-juggler/test/include.test.js'); - require('loopback-datasource-juggler/test/common.batch.js'); -}); - -// Run the COUCHDB2 Test Suite. require('./init.js'); process.env.COUCHDB2_TEST_SKIP_INIT = true; diff --git a/test/init.js b/test/init.js index 45a7c4b4..e64e0eed 100644 --- a/test/init.js +++ b/test/init.js @@ -7,7 +7,8 @@ module.exports = require('should'); -const DataSource = require('loopback-datasource-juggler').DataSource; +const juggler = require('loopback-datasource-juggler'); +let DataSource = juggler.DataSource; const _ = require('lodash'); const config = { @@ -40,8 +41,10 @@ if (process.env.LOOPBACK_MOCHA_SKIPS) { process.env.LOOPBACK_MOCHA_SKIPS = JSON.stringify(skips); } -global.getDataSource = global.getSchema = function(customConfig) { - const db = new DataSource(require('../'), customConfig || config); +let db; +global.getDataSource = global.getSchema = function(customConfig, customClass) { + const ctor = customClass || DataSource; + db = new ctor(require('../'), customConfig || config); db.log = function(a) { console.log(a); }; @@ -115,6 +118,13 @@ global.getDataSource = global.getSchema = function(customConfig) { return db; }; +global.resetDataSourceClass = function(ctor) { + DataSource = ctor || juggler.DataSource; + const promise = db ? db.disconnect() : Promise.resolve(); + db = undefined; + return promise; +}; + global.connectorCapabilities = { ilike: false, nilike: false,