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

Run shared tests from both v3 and v4 of juggler #376

Merged
merged 3 commits into from
May 6, 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"
}
}
30 changes: 30 additions & 0 deletions deps/juggler-v3/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright IBM Corp. 2013,2016. All Rights Reserved.
// Node module: loopback-connector-mysql
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

'use strict';

var should = require('../../test/init');
var juggler = require('loopback-datasource-juggler');
var name = require('./package.json').name;

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/include.test.js');

/* TODO: run persistence-hooks test suite too
var testHooks = require('loopback-datasource-juggler/test/persistence-hooks.suite.js');
testHooks(global.getDataSource(), should, {
replaceOrCreateReportsNewInstance: false,
});
*/
});
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"
}
}
37 changes: 37 additions & 0 deletions deps/juggler-v4/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright IBM Corp. 2013,2016. All Rights Reserved.
// Node module: loopback-connector-mysql
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

'use strict';

// Skip the tests on Node.js versions not supported by juggler v4
// TODO(bajtos): remove this check when we drop Node.js 6 from our CI matrix
var nodeMajor = +process.versions.node.split('.')[0];
bajtos marked this conversation as resolved.
Show resolved Hide resolved
if (nodeMajor < 8) {
return;
}

var should = require('../../test/init');
var juggler = require('loopback-datasource-juggler');
var name = require('./package.json').name;

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/include.test.js');

/* TODO: run persistence-hooks test suite too
var testHooks = require('loopback-datasource-juggler/test/persistence-hooks.suite.js');
bajtos marked this conversation as resolved.
Show resolved Hide resolved
testHooks(global.getDataSource(), should, {
replaceOrCreateReportsNewInstance: false,
});
*/
});
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"main": "index.js",
"scripts": {
"pretest": "node pretest.js",
"test": "mocha -R spec --timeout 10000 --require test/init.js test/*.test.js",
"test": "mocha test/*.test.js node_modules/juggler-v3/test.js node_modules/juggler-v4/test.js",
"lint": "eslint .",
"posttest": "npm run lint"
},
Expand All @@ -31,8 +31,10 @@
"devDependencies": {
"eslint": "^2.13.1",
"eslint-config-loopback": "^4.0.0",
"juggler-v3": "file:./deps/juggler-v3",
"juggler-v4": "file:./deps/juggler-v4",
"lodash": "^4.17.4",
"loopback-datasource-juggler": "^3.0.0",
"loopback-datasource-juggler": "^3.0.0 || ^4.0.0",
"mocha": "^5.0.0",
"rc": "^1.0.0",
"should": "^8.0.2",
Expand Down
10 changes: 9 additions & 1 deletion test/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
// License text available at https://opensource.org/licenses/Artistic-2.0

'use strict';
var DataSource = require('loopback-datasource-juggler').DataSource;
var juggler = require('loopback-datasource-juggler');
b-admike marked this conversation as resolved.
Show resolved Hide resolved
var DataSource = juggler.DataSource;

var config = require('rc')('loopback', {test: {postgresql: {}}}).test.postgresql;

Expand Down Expand Up @@ -55,6 +56,13 @@ global.getDataSource = global.getSchema = function(useUrl) {
return db;
};

global.resetDataSourceClass = function(ctor) {
DataSource = ctor || juggler.DataSource;
var promise = db ? db.disconnect() : Promise.resolve();
b-admike marked this conversation as resolved.
Show resolved Hide resolved
db = undefined;
return promise;
};

global.connectorCapabilities = {
ilike: false,
nilike: false,
Expand Down
4 changes: 4 additions & 0 deletions test/mocha.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--reporter spec
bajtos marked this conversation as resolved.
Show resolved Hide resolved
--timeout 10000
--require test/init.js
--exit
35 changes: 28 additions & 7 deletions test/postgresql.autoupdate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -629,19 +629,27 @@ describe('autoupdate', function() {
// Table create order is important. Referenced tables must exist before creating a reference.
// do initial update/creation of referenced tables
ds.autoupdate(function(err) {
assert(!err, err);
if (err) {
err.message += ' (while running initial autoupdate)';
bajtos marked this conversation as resolved.
Show resolved Hide resolved
return done(err);
}

// do initial update/creation of table with fk
ds.createModel(orderTest_schema_v1.name, orderTest_schema_v1.properties, orderTest_schema_v1.options);
ds.autoupdate(function(err) {
assert(!err, err);
if (err) {
err.message += ' (while updating OrderTest schema v1)';
return done(err);
}
ds.discoverModelProperties('order_test', function(err, props) {
if (err) return done(err);
// validate that we have the correct number of properties
assert.equal(props.length, 3);

// get the foreign keys for order_test
ds.connector.discoverForeignKeys('order_test', {}, function(err, foreignKeys) {
assert(!err, err);
if (err) return done(err);

// validate that the foreign key exists and points to the right column
assert(foreignKeys);
assert.equal(foreignKeys.length, 1);
Expand All @@ -653,14 +661,18 @@ describe('autoupdate', function() {
// update and add another fk
ds.createModel(orderTest_schema_v2.name, orderTest_schema_v2.properties, orderTest_schema_v2.options);
ds.autoupdate(function(err) {
assert(!err, err);
if (err) {
err.message += ' (while updating OrderTest schema v2)';
return done(err);
}
ds.discoverModelProperties('order_test', function(err, props) {
if (err) return done(err);
// validate that we have the correct number of properties
assert.equal(props.length, 4);

// get the foreign keys for order_test
ds.connector.discoverForeignKeys('order_test', {}, function(err, foreignKeysUpdated) {
assert(!err, err);
if (err) return done(err);
// validate that the foreign keys exist and point to the new column
assert(foreignKeysUpdated);
assert.equal(foreignKeysUpdated.length, 1);
Expand All @@ -673,18 +685,27 @@ describe('autoupdate', function() {
ds.createModel(orderTest_schema_v3.name, orderTest_schema_v3.properties,
orderTest_schema_v3.options);
ds.autoupdate(function(err) {
if (err) {
err.message += ' (while updating OrderTest schema v3)';
return done(err);
}
// get the foreign keys for order_test
ds.connector.discoverForeignKeys('order_test', {}, function(err, foreignKeysMulti) {
assert(!err, err);
if (err) return done(err);
assert(foreignKeysMulti);
assert.equal(foreignKeysMulti.length, 2);

// remove fk
ds.createModel(orderTest_schema_v4.name, orderTest_schema_v4.properties,
orderTest_schema_v4.options);
ds.autoupdate(function(err) {
assert(!err, err);
if (err) {
err.message += ' (while updating OrderTest schema v4)';
return done(err);
}
ds.discoverModelProperties('order_test', function(err, props) {
if (err) return done(err);

// validate that we have the correct number of properties
assert.equal(props.length, 4);

Expand Down
2 changes: 0 additions & 2 deletions test/postgresql.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
'use strict';
var juggler = require('loopback-datasource-juggler');
var CreateDS = juggler.DataSource;
require('loopback-datasource-juggler/test/common.batch.js');
require('loopback-datasource-juggler/test/include.test.js');

require('./init');
var async = require('async');
Expand Down