Skip to content

Commit

Permalink
Merge pull request #519 from strongloop/build/test-juggler-v3-and-v4
Browse files Browse the repository at this point in the history
Run shared tests from both v3 and v4 of juggler
  • Loading branch information
bajtos authored May 14, 2019
2 parents 5c9ed78 + 830f83a commit 2ba8cc7
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 61 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
coverage
**/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"
}
}
49 changes: 49 additions & 0 deletions deps/juggler-v3/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// 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 semver = require('semver');
const should = require('should');
const juggler = require('loopback-datasource-juggler');
const name = require('./package.json').name;

require('../../test/init');

describe(name, function() {
before(function() {
return global.resetDataSourceClass(juggler.DataSource);
});

after(function() {
return global.resetDataSourceClass();
});

require('loopback-datasource-juggler/test/common.batch.js');
require('loopback-datasource-juggler/test/default-scope.test.js');
require('loopback-datasource-juggler/test/include.test.js');

// === Operation hooks ==== //

const suite = require('loopback-datasource-juggler/test/persistence-hooks.suite.js');

const DB_VERSION = process.env.MONGODB_VERSION;

if (!DB_VERSION) {
console.log('The ENV variable MONGODB_VERSION is not set.' +
' Assuming MongoDB version 2.6 or newer.');
}

const DB_HAS_2_6_FEATURES = (!DB_VERSION ||
semver.satisfies(DB_VERSION, '>=2.6.0'));

const customConfig = Object.assign({}, global.config, {
enableOptimisedFindOrCreate: DB_HAS_2_6_FEATURES,
});

suite(global.getDataSource(customConfig, juggler.DataSource), should, {
replaceOrCreateReportsNewInstance: DB_HAS_2_6_FEATURES,
});
});
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"
}
}
49 changes: 49 additions & 0 deletions deps/juggler-v4/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// 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 semver = require('semver');
const should = require('should');
const juggler = require('loopback-datasource-juggler');
const name = require('./package.json').name;

require('../../test/init');

describe(name, function() {
before(function() {
return global.resetDataSourceClass(juggler.DataSource);
});

after(function() {
return global.resetDataSourceClass();
});

require('loopback-datasource-juggler/test/common.batch.js');
require('loopback-datasource-juggler/test/default-scope.test.js');
require('loopback-datasource-juggler/test/include.test.js');

// === Operation hooks ==== //

const suite = require('loopback-datasource-juggler/test/persistence-hooks.suite.js');

const DB_VERSION = process.env.MONGODB_VERSION;

if (!DB_VERSION) {
console.log('The ENV variable MONGODB_VERSION is not set.' +
' Assuming MongoDB version 2.6 or newer.');
}

const DB_HAS_2_6_FEATURES = (!DB_VERSION ||
semver.satisfies(DB_VERSION, '>=2.6.0'));

const customConfig = Object.assign({}, global.config, {
enableOptimisedFindOrCreate: DB_HAS_2_6_FEATURES,
});

suite(global.getDataSource(customConfig, juggler.DataSource), should, {
replaceOrCreateReportsNewInstance: DB_HAS_2_6_FEATURES,
});
});
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"scripts": {
"benchmarks": "make benchmarks",
"leak-detection": "make leak-detection",
"test": "mocha",
"test": "mocha test/*.test.js node_modules/juggler-v3/test.js node_modules/juggler-v4/test.js",
"lint": "eslint .",
"posttest": "npm run lint"
},
Expand Down Expand Up @@ -39,7 +39,9 @@
"bluebird": "^3.5.4",
"eslint": "^5.1.0",
"eslint-config-loopback": "^10.0.0",
"loopback-datasource-juggler": "^3.23.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",
"rc": "^1.2.8",
"semver": "^5.5.1",
Expand Down
16 changes: 0 additions & 16 deletions test/imported.test.js

This file was deleted.

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');

var DataSource = require('loopback-datasource-juggler').DataSource;
var juggler = require('loopback-datasource-juggler');
var DataSource = juggler.DataSource;

var TEST_ENV = process.env.TEST_ENV || 'test';
var config = require('rc')('loopback', {test: {mongodb: {}}})[TEST_ENV]
Expand All @@ -24,15 +25,24 @@ config = {

global.config = config;

global.getDataSource = global.getSchema = function(customConfig) {
var db = new DataSource(require('../'), customConfig || config);
var 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);
};

return db;
};

global.resetDataSourceClass = function(ctor) {
DataSource = ctor || juggler.DataSource;
var promise = db ? db.disconnect() : Promise.resolve();
db = undefined;
return promise;
};

global.connectorCapabilities = {
ilike: false,
nilike: false,
Expand Down
7 changes: 4 additions & 3 deletions test/mongodb.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,9 @@ describe('mongodb connector', function() {
});

it('ignores invalid option', function(done) {
var configWithInvalidOption = global.config;
configWithInvalidOption.invalidOption = 'invalid';
var configWithInvalidOption = Object.assign({}, global.config, {
invalidOption: 'invalid',
});
var ds = global.getDataSource(configWithInvalidOption);
ds.ping(function(err) {
if (err) return done(err);
Expand All @@ -393,7 +394,7 @@ describe('mongodb connector', function() {
it('should prioritize to the database given in the url property', function(done) {
var cfg = JSON.parse(JSON.stringify(global.config));
var testDb = 'lb-ds-overriden-test-1';
cfg.url = 'mongodb://' + cfg.hostname + ':' + cfg.port + '/' + testDb;
cfg.url = 'mongodb://' + cfg.host + ':' + cfg.port + '/' + testDb;
var ds = global.getDataSource(cfg);
ds.once('connected', function() {
var db = ds.connector.db;
Expand Down
37 changes: 0 additions & 37 deletions test/persistence-hooks.test.js

This file was deleted.

0 comments on commit 2ba8cc7

Please sign in to comment.