Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

juggler-v3-v4 shared test #206

Merged
merged 1 commit into from
Jun 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/node_modules/
8 changes: 8 additions & 0 deletions deps/juggler-v3/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "juggler-v3",
"version": "3.0.0",
"dependencies": {
"loopback-datasource-juggler":"3.x",
"should": "^8.4.0"
}
}
31 changes: 31 additions & 0 deletions deps/juggler-v3/test.js
Original file line number Diff line number Diff line change
@@ -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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make this work, you need to modify test/init.js, add resetDataSourceClass helper and modify getDataSource to allow configuration of the data-source class used. See https://github.com/strongloop/loopback-connector-mongodb/pull/519/files#diff-40dfb1c53004f1488cbe6eb300b286dd

});
require('loopback-datasource-juggler/test/include.test.js');
require('loopback-datasource-juggler/test/common.batch.js');
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a TODO comment to remind us that we should eventually include the following tests too:

  • loopback-datasource-juggler/test/default-scope.test.js
  • loopback-datasource-juggler/test/persistence-hooks.suite.js

See https://github.com/strongloop/loopback-connector-mongodb/blob/master/deps/juggler-v4/test.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');
*/

8 changes: 8 additions & 0 deletions deps/juggler-v4/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "juggler-v4",
"version": "4.0.0",
"dependencies": {
"loopback-datasource-juggler":"4.x",
"should": "^13.2.3"
}
}
30 changes: 30 additions & 0 deletions deps/juggler-v4/test.js
Original file line number Diff line number Diff line change
@@ -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');
*/
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 4 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
14 changes: 0 additions & 14 deletions test/imported.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 13 additions & 3 deletions test/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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);
};
Expand Down Expand Up @@ -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,
Expand Down