Skip to content

Commit

Permalink
run shared test from juggler for v3 and v4
Browse files Browse the repository at this point in the history
  • Loading branch information
Agnes Lin committed Feb 12, 2020
1 parent d8f784b commit 8cd9910
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 21 deletions.
9 changes: 9 additions & 0 deletions deps/juggler-v3/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"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. 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");

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
});
});
9 changes: 9 additions & 0 deletions deps/juggler-v4/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"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. 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");

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
});
});
6 changes: 4 additions & 2 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 20000 --require test/init.js test/*.test.js node_modules/juggler-v3/test.js node_modules/juggler-v4/test.js",
"posttest": "npm run lint"
},
"dependencies": {
Expand All @@ -32,8 +32,10 @@
"bluebird": "^3.5.1",
"eslint": "^6.1.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.

18 changes: 15 additions & 3 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,7 +7,8 @@

module.exports = require('should');

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

let schemaName;

Expand All @@ -34,11 +35,22 @@ const config = {

global.config = config;

let db;
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

0 comments on commit 8cd9910

Please sign in to comment.