diff --git a/.eslintignore b/.eslintignore index 404abb2..78f826b 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1,2 @@ coverage/ +**/node_modules/ diff --git a/.gitignore b/.gitignore index 3c1dcdc..92f0258 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ *.tgz node_modules checkstyle.xml +**/node_modules/ diff --git a/deps/juggler-v3/package.json b/deps/juggler-v3/package.json new file mode 100644 index 0000000..b8b1147 --- /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 0000000..1e28d8a --- /dev/null +++ b/deps/juggler-v3/test.js @@ -0,0 +1,33 @@ +// Copyright IBM Corp. 2019. All Rights Reserved. +// Node module: loopback-connector-postgresql +// This file is licensed under the Artistic License 2.0. +// License text available at https://opensource.org/licenses/Artistic-2.0 + +'use strict'; + +const createDataSource = require('../../test/helpers/data-source-factory'); +const kvaoTestSuite = require('loopback-datasource-juggler/test/kvao.suite.js'); +const juggler = require('loopback-datasource-juggler'); +const name = require('./package.json').name; + +describe(name, function() { + before(function() { + return createDataSource.resetDataSourceClass(juggler.DataSource); + }); + + after(function() { + return createDataSource.resetDataSourceClass(); + }); + + context('using binary packer', function() { + kvaoTestSuite(createDataSource); + }); + + context('using json-string packer', function() { + kvaoTestSuite(createDataSource.json); + }); + + context('using json-string packer with hex buffers', function() { + kvaoTestSuite(createDataSource.jsonWithHexBuffers); + }); +}); diff --git a/deps/juggler-v4/package.json b/deps/juggler-v4/package.json new file mode 100644 index 0000000..800ae49 --- /dev/null +++ b/deps/juggler-v4/package.json @@ -0,0 +1,8 @@ +{ + "name": "juggler-v4", + "version": "3.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 0000000..1e28d8a --- /dev/null +++ b/deps/juggler-v4/test.js @@ -0,0 +1,33 @@ +// Copyright IBM Corp. 2019. All Rights Reserved. +// Node module: loopback-connector-postgresql +// This file is licensed under the Artistic License 2.0. +// License text available at https://opensource.org/licenses/Artistic-2.0 + +'use strict'; + +const createDataSource = require('../../test/helpers/data-source-factory'); +const kvaoTestSuite = require('loopback-datasource-juggler/test/kvao.suite.js'); +const juggler = require('loopback-datasource-juggler'); +const name = require('./package.json').name; + +describe(name, function() { + before(function() { + return createDataSource.resetDataSourceClass(juggler.DataSource); + }); + + after(function() { + return createDataSource.resetDataSourceClass(); + }); + + context('using binary packer', function() { + kvaoTestSuite(createDataSource); + }); + + context('using json-string packer', function() { + kvaoTestSuite(createDataSource.json); + }); + + context('using json-string packer with hex buffers', function() { + kvaoTestSuite(createDataSource.jsonWithHexBuffers); + }); +}); diff --git a/package.json b/package.json index e33e0c8..e996b12 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ }, "main": "lib/kv-redis.js", "scripts": { - "test": "mocha test/integration", + "test": "mocha test/integration node_modules/juggler-v3/test.js node_modules/juggler-v4/test.js", "posttest": "npm run lint", "lint": "eslint ." }, @@ -36,6 +36,8 @@ "dirty-chai": "^2.0.1", "eslint": "^4.19.1", "eslint-config-loopback": "^10.0.0", + "juggler-v3": "file:./deps/juggler-v3", + "juggler-v4": "file:./deps/juggler-v4", "loopback-datasource-juggler": "^3.0.0", "mocha": "^5.2.0", "should": "^8.4.0" diff --git a/test/helpers/data-source-factory.js b/test/helpers/data-source-factory.js index 2bcd7c3..0e1e6ec 100644 --- a/test/helpers/data-source-factory.js +++ b/test/helpers/data-source-factory.js @@ -5,8 +5,9 @@ 'use strict'; -const DataSource = require('loopback-datasource-juggler').DataSource; const connector = require('../..'); +const juggler = require('loopback-datasource-juggler'); +let DataSource = juggler.DataSource; const SETTINGS = { host: process.env.REDIS_HOST || 'localhost', @@ -62,6 +63,10 @@ createDataSource.jsonWithHexBuffers = function(options) { return createDataSource(settings); }; +createDataSource.resetDataSourceClass = function(ctor) { + DataSource = ctor || juggler.DataSource; +}; + beforeEach(function clearDatabase(done) { const ds = createDataSource(); ds.connector.execute('FLUSHDB', function(err) { diff --git a/test/integration/juggler-api.integration.js b/test/integration/juggler-api.integration.js deleted file mode 100644 index d8f4588..0000000 --- a/test/integration/juggler-api.integration.js +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright IBM Corp. 2016,2018. All Rights Reserved. -// Node module: loopback-connector-kv-redis -// This file is licensed under the MIT License. -// License text available at https://opensource.org/licenses/MIT - -'use strict'; - -const createDataSource = require('../helpers/data-source-factory'); -const expect = require('../helpers/expect'); -const kvaoTestSuite = require('loopback-datasource-juggler/test/kvao.suite.js'); - -describe('Juggler API', function() { - context('using binary packer', function() { - kvaoTestSuite(createDataSource); - }); - - context('using json-string packer', function() { - kvaoTestSuite(createDataSource.json); - }); - - context('using json-string packer with hex buffers', function() { - kvaoTestSuite(createDataSource.jsonWithHexBuffers); - }); -});