feat: run shared tests

This commit is contained in:
jannyHou 2019-06-28 10:54:45 -04:00
parent 869061c6f2
commit 01c94b6a60
14 changed files with 115 additions and 41 deletions

1
.eslintignore Normal file
View File

@ -0,0 +1 @@
**/node_modules/

View File

@ -1,6 +1,5 @@
language: node_js
node_js:
- "6"
- "8"
- "10"
# Xenial build environment comes with MySQL 5.7

8
deps/juggler-v3/package.json vendored Normal file
View File

@ -0,0 +1,8 @@
{
"name": "juggler-v3",
"version": "3.0.0",
"dependencies": {
"loopback-datasource-juggler":"3.x",
"should": "^8.4.0"
}
}

31
deps/juggler-v3/test.js vendored Normal file
View File

@ -0,0 +1,31 @@
// Copyright IBM Corp. 2019. All Rights Reserved.
// Node module: loopback-connector-mysql
// This file is licensed under the Artistic License 2.0.
// License text available at https://opensource.org/licenses/Artistic-2.0
'use strict';
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/include.test.js');
// === Operation hooks ==== //
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
deps/juggler-v4/package.json vendored Normal file
View File

@ -0,0 +1,8 @@
{
"name": "juggler-v4",
"version": "4.0.0",
"dependencies": {
"loopback-datasource-juggler":"4.x",
"should": "^13.2.3"
}
}

32
deps/juggler-v4/test.js vendored Normal file
View File

@ -0,0 +1,32 @@
// Copyright IBM Corp. 2019. All Rights Reserved.
// Node module: loopback-connector-mysql
// 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/include.test.js');
// === Operation hooks ==== //
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});
});

View File

@ -444,6 +444,12 @@ MySQL.prototype.fromColumnValue = function(prop, val) {
lat: val.y,
};
break;
case 'ObjectID':
val = new prop.type(val);
break;
case 'Buffer':
val = prop.type(val);
break;
case 'List':
case 'Array':
case 'Object':
@ -453,10 +459,6 @@ MySQL.prototype.fromColumnValue = function(prop, val) {
}
break;
default:
if (!Array.isArray(prop.type) && !prop.type.modelName) {
// Do not convert array and model types
val = prop.type(val);
}
break;
}
}

View File

@ -3,13 +3,13 @@
"version": "5.4.1",
"description": "MySQL connector for loopback-datasource-juggler",
"engines": {
"node": ">=6"
"node": ">=8"
},
"main": "index.js",
"scripts": {
"pretest": "node pretest.js",
"lint": "eslint .",
"test": "mocha --timeout 10000 --require test/init.js test/*.js",
"test": "mocha --timeout 10000 test/*.test.js node_modules/juggler-v3/test.js node_modules/juggler-v4/test.js",
"posttest": "npm run lint"
},
"dependencies": {
@ -24,7 +24,9 @@
"bluebird": "~2.9.10",
"eslint": "^4.3.0",
"eslint-config-loopback": "^8.0.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": "^2.1.0",
"rc": "^1.0.0",
"should": "^8.0.2",

View File

@ -7,6 +7,7 @@
require('./init.js');
var assert = require('assert');
var _ = require('lodash');
const GeoPoint = require('loopback-datasource-juggler').GeoPoint;
var db, BlobModel, EnumModel, ANIMAL_ENUM, City, Account;
@ -206,7 +207,8 @@ describe('MySQL specific datatypes', function() {
var xcor, ycor;
City.create(city1, function(err, res) {
if (err) return done(err);
res.loc.should.deepEqual(city1.loc);
const loc_in_geo_type = new GeoPoint(city1.loc);
res.loc.should.deepEqual(loc_in_geo_type);
res.name.should.equal(city1.name);
var sqlStmt = 'select ST_X(loc),ST_Y(loc) from City where id=1';
db.connector.execute(sqlStmt, function(err, res) {

View File

@ -1,14 +0,0 @@
// 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';
describe('mysql imported features', function() {
before(function() {
require('./init.js');
});
require('loopback-datasource-juggler/test/common.batch.js');
require('loopback-datasource-juggler/test/include.test.js');
});

View File

@ -6,8 +6,8 @@
'use strict';
module.exports = require('should');
var DataSource = require('loopback-datasource-juggler').DataSource;
const juggler = require('loopback-datasource-juggler');
let DataSource = juggler.DataSource;
var config = require('rc')('loopback', {test: {mysql: {}}}).test.mysql;
global.getConfig = function(options) {
@ -28,11 +28,23 @@ global.getConfig = function(options) {
return dbConf;
};
global.getDataSource = global.getSchema = function(options) {
var db = new DataSource(require('../'), global.getConfig(options));
let db;
global.getDataSource = global.getSchema = function(options, customClass) {
const ctor = customClass || DataSource;
db = new ctor(require('../'), global.getConfig(options));
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,

View File

@ -639,7 +639,9 @@ var getFields = function(model, cb) {
res.forEach(function(field) {
fields[field.Field] = field;
});
cb(err, fields);
// The returned data are in arrays of type `RowDataPacket`,
// which are not objects.
cb(err, JSON.parse(JSON.stringify(fields)));
}
});
};

View File

@ -7,6 +7,7 @@
var async = require('async');
var should = require('./init.js');
var sinon = require('sinon');
const List = require('loopback-datasource-juggler/lib/list');
var Post, PostWithStringId, PostWithUniqueTitle, PostWithNumId, Student, db;
@ -88,7 +89,7 @@ describe('mysql', function() {
p.content.should.be.equal(post.content);
p.title.should.be.equal('a');
p.comments.should.eql(['1', '2']);
p.comments.should.eql(new List(['1', '2']));
p.history.should.eql({a: 1, b: 'b'});
done();

View File

@ -1,12 +0,0 @@
// Copyright IBM Corp. 2015,2017. 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('./init');
var suite = require('loopback-datasource-juggler/test/persistence-hooks.suite.js');
suite(global.getDataSource(), should, {
replaceOrCreateReportsNewInstance: false,
});