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 test from both v3 and v4 of juggler #96

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

'use strict';

const should = require('should');
const juggler = require('loopback-datasource-juggler');

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

describe('dashdb imported feature v3', 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
const suite = require("loopback-datasource-juggler/test/persistence-hooks.suite.js");
const customConfig = Object.assign({}, global.config);
suite(global.getDataSource(customConfig, juggler.DataSource), 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"
}
}
32 changes: 32 additions & 0 deletions deps/juggler-v4/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright IBM Corp. 2020. All Rights Reserved.
// Node module: loopback-connector-dashdb
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

'use strict';

const should = require('should');
const juggler = require('loopback-datasource-juggler');

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

describe('dashdb imported feature v4', 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
const suite = require("loopback-datasource-juggler/test/persistence-hooks.suite.js");
const customConfig = Object.assign({}, global.config);
suite(global.getDataSource(customConfig, juggler.DataSource), should, {
replaceOrCreateReportsNewInstance: false
});
*/
});
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"lint": "eslint .",
"lint:fix": "eslint --fix .",
"pretest": "node pretest.js",
"test": "mocha --timeout 20000 --require test/init.js",
"test": "mocha --timeout 60000 --require test/init.js test/*.test.js node_modules/juggler-v3/test.js node_modules/juggler-v4/test.js",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: for whoever working on any similar tasks, adding timeout/making it longer may fix timing-related errors.

Copy link
Member

Choose a reason for hiding this comment

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

Ideally, we should move the timeout configuration to test/mocha.opts or a mocha-rc file, so that we can run individual test files via npx mocha node_modules/juggler-v3/test.js and don't have to specify the timeout in CLI args.

"posttest": "npm run lint"
},
"dependencies": {
Expand All @@ -30,10 +30,12 @@
},
"devDependencies": {
"bluebird": "^3.5.1",
"eslint": "^6.1.0",
"eslint": "^6.8.0",
"eslint-config-loopback": "^13.1.0",
"juggler-v3": "file:./deps/juggler-v3",
"juggler-v4": "file:./deps/juggler-v4",
"loopback-datasource-juggler": "^3.0.0 || ^4.0.0",
"lodash": "^4.17.10",
"loopback-datasource-juggler": "^3.23.0",
"mocha": "^6.2.0",
"ms": "^2.1.1",
"rc": "^1.2.8",
Expand Down
16 changes: 0 additions & 16 deletions test/imported.test.js

This file was deleted.

20 changes: 16 additions & 4 deletions test/init.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright IBM Corp. 2016,2019. All Rights Reserved.
// Copyright IBM Corp. 2016,2020. All Rights Reserved.
// Node module: loopback-connector-dashdb
// This file is licensed under the Artistic License 2.0.
// License text available at https://opensource.org/licenses/Artistic-2.0
Expand All @@ -7,9 +7,11 @@

module.exports = require('should');

const DataSource = require('loopback-datasource-juggler').DataSource;
const Connector = require('../');
const juggler = require('loopback-datasource-juggler');
let DataSource = juggler.DataSource;

let schemaName;
let schemaName, db;

/** these are the env variables in jenkins **/
if (process.env.CI && process.env.PACKAGE_NAME &&
Expand All @@ -35,10 +37,20 @@ const config = {
global.config = config;

global.getDataSource = global.getSchema = function(options) {
const db = new DataSource(require('../'), config);
db = new DataSource(Connector, global.config);
db.log = function(a) {
console.log(a);
};
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