From 83731ac577e65e05f58cdbb262f34dfde9e0026e Mon Sep 17 00:00:00 2001 From: Simon Ho Date: Fri, 29 Jan 2016 18:31:50 -0800 Subject: [PATCH] Cleanup --- index.js | 24 +++++++------ lib/{connector.js => connectors/base.js} | 0 lib/datasource.js | 2 +- lib/sql.js | 2 +- package.json | 3 +- test/{automigrate.test.js => automigrate.js} | 3 +- test/{common_test.js => common.js} | 2 +- test/configs/index.js | 36 +++++++++++++++++++ ...Key.test.js => custom-type-foreign-key.js} | 5 +-- test/{schema.test.js => datasource.js} | 3 -- test/{defaults.test.js => defaults.js} | 3 -- test/{discovery.test.js => discovery.js} | 1 - test/{ => fixtures}/memory.json | 0 test/{spec_helper.js => helpers/spec.js} | 0 test/index.js | 8 +++++ test/init.js | 28 --------------- test/juggler.js | 9 ----- test/{memory.test.js => memory.js} | 3 +- .../sql-connector.js} | 0 test/{sql.test.js => sql.js} | 3 +- test/{transaction.test.js => transaction.js} | 3 +- test/{transient.test.js => transient.js} | 1 - 22 files changed, 66 insertions(+), 73 deletions(-) rename lib/{connector.js => connectors/base.js} (100%) rename test/{automigrate.test.js => automigrate.js} (91%) rename test/{common_test.js => common.js} (99%) create mode 100644 test/configs/index.js rename test/{CustomTypeForeignKey.test.js => custom-type-foreign-key.js} (91%) rename test/{schema.test.js => datasource.js} (94%) rename test/{defaults.test.js => defaults.js} (96%) rename test/{discovery.test.js => discovery.js} (99%) rename test/{ => fixtures}/memory.json (100%) rename test/{spec_helper.js => helpers/spec.js} (100%) create mode 100644 test/index.js delete mode 100644 test/init.js delete mode 100644 test/juggler.js rename test/{memory.test.js => memory.js} (99%) rename test/{connectors/test-sql-connector.js => mocks/sql-connector.js} (100%) rename test/{sql.test.js => sql.js} (99%) rename test/{transaction.test.js => transaction.js} (98%) rename test/{transient.test.js => transient.js} (98%) diff --git a/index.js b/index.js index 44eb915..d19b148 100644 --- a/index.js +++ b/index.js @@ -1,20 +1,22 @@ -exports.Connector = require('./lib/connector'); +Object.defineProperties(exports, { + test: { + get: function() { + return require('./test/common'); + } + }, + version: { + value: require('./package.json').version + } +}); + +exports.Connector = require('./lib/connectors/base'); // Set up SqlConnector as an alias to SQLConnector exports.SQLConnector = exports.SqlConnector = require('./lib/sql'); exports.ParameterizedSQL = exports.SQLConnector.ParameterizedSQL; exports.Transaction = require('./lib/transaction'); exports.ModelBuilder = exports.LDL = require('loopback-model/lib/model-builder'); -exports.DataSource = exports.Schema = require('./lib/datasource.js').DataSource; +exports.DataSource = exports.Schema = require('./lib/datasource').DataSource; exports.ModelBaseClass = require('loopback-model/lib/model'); exports.GeoPoint = require('loopback-model').Geo.GeoPoint; exports.ValidationError = require('loopback-model/lib/validations').ValidationError; - -Object.defineProperty(exports, 'version', { - get: function() {return require('./package.json').version;} -}); - -var commonTest = './test/common_test'; -Object.defineProperty(exports, 'test', { - get: function() {return require(commonTest);} -}); diff --git a/lib/connector.js b/lib/connectors/base.js similarity index 100% rename from lib/connector.js rename to lib/connectors/base.js diff --git a/lib/datasource.js b/lib/datasource.js index cf3007d..09b2688 100644 --- a/lib/datasource.js +++ b/lib/datasource.js @@ -1,7 +1,7 @@ /*! * Module dependencies */ -var ModelBuilder = require('loopback-model/lib/model-builder.js').ModelBuilder; +var ModelBuilder = require('loopback-model/lib/model-builder').ModelBuilder; var ModelDefinition = require('loopback-model/lib/model-definition'); var RelationDefinition = require('loopback-model-persistence/lib/relation-definition'); var OberserverMixin = require('loopback-model/lib/observer'); diff --git a/lib/sql.js b/lib/sql.js index d9848ec..5161b4e 100644 --- a/lib/sql.js +++ b/lib/sql.js @@ -1,7 +1,7 @@ var util = require('util'); var async = require('async'); var assert = require('assert'); -var Connector = require('./connector'); +var Connector = require('./connectors/base'); var debug = require('debug')('loopback:connector:sql'); var ParameterizedSQL = require('./parameterized-sql'); var Transaction = require('./transaction'); diff --git a/package.json b/package.json index e707c22..2247d4a 100644 --- a/package.json +++ b/package.json @@ -21,8 +21,7 @@ }, "scripts": { "lint": "eslint .", - "test": "mocha", - "posttest": "npm run lint" + "test": "mocha -r test/configs" }, "repository": { "type": "git", diff --git a/test/automigrate.test.js b/test/automigrate.js similarity index 91% rename from test/automigrate.test.js rename to test/automigrate.js index 0267fc9..9d5b9ad 100644 --- a/test/automigrate.test.js +++ b/test/automigrate.js @@ -1,6 +1,5 @@ var DataSource = require('..').DataSource; -var expect = require('chai').expect; -var testConnector = require('./connectors/test-sql-connector'); +var testConnector = require('./mocks/sql-connector'); var ds = new DataSource({ connector: testConnector, diff --git a/test/common_test.js b/test/common.js similarity index 99% rename from test/common_test.js rename to test/common.js index 0b251e5..1db1f3c 100644 --- a/test/common_test.js +++ b/test/common.js @@ -1,4 +1,4 @@ -var Schema = require('../index').Schema; +var Schema = require('..').Schema; var Text = Schema.Text; var nbSchemaRequests = 0; diff --git a/test/configs/index.js b/test/configs/index.js new file mode 100644 index 0000000..700afef --- /dev/null +++ b/test/configs/index.js @@ -0,0 +1,36 @@ +var chai = require('chai'); +var ModelBuilder = require('loopback-model/lib/model-builder').ModelBuilder; +var Schema = require('../..').Schema; +var should = require('should'); + +/* +if (!process.env.TRAVIS) { + if (typeof __cov === 'undefined') { + process.on('exit', function() { + require('semicov').report(); + }); + } + + require('semicov').init('lib'); +} +*/ + +Object.defineProperties(global, { + getModelBuilder: { + value: function() { + return new ModelBuilder(); + } + }, + getSchema: { + value: function(connector, settings) { + connector = connector || 'memory'; + return new Schema(connector, settings); + } + }, + expect: { + value: chai.expect + }, + should: { + value: should + } +}); diff --git a/test/CustomTypeForeignKey.test.js b/test/custom-type-foreign-key.js similarity index 91% rename from test/CustomTypeForeignKey.test.js rename to test/custom-type-foreign-key.js index 880dc93..9cc4c55 100644 --- a/test/CustomTypeForeignKey.test.js +++ b/test/custom-type-foreign-key.js @@ -1,7 +1,4 @@ -var should = require('./init.js'); - -var jdb = require('../'); -var DataSource = jdb.DataSource; +var DataSource = require('..').DataSource; var ds, Item, Variant; describe('Datasource-specific field types for foreign keys', function () { diff --git a/test/schema.test.js b/test/datasource.js similarity index 94% rename from test/schema.test.js rename to test/datasource.js index 416f9a9..ad9068f 100644 --- a/test/schema.test.js +++ b/test/datasource.js @@ -1,6 +1,3 @@ -// This test written in mocha+should.js -var should = require('./init.js'); - var db = getSchema(), slave = getSchema(), Model, SlaveModel; describe('dataSource', function () { diff --git a/test/defaults.test.js b/test/defaults.js similarity index 96% rename from test/defaults.test.js rename to test/defaults.js index 6a05e0c..f46d1a9 100644 --- a/test/defaults.test.js +++ b/test/defaults.js @@ -1,6 +1,3 @@ -// This test written in mocha+should.js -var should = require('./init.js'); - var db = getSchema(); describe('defaults', function () { diff --git a/test/discovery.test.js b/test/discovery.js similarity index 99% rename from test/discovery.test.js rename to test/discovery.js index 26e5056..f3e9773 100644 --- a/test/discovery.test.js +++ b/test/discovery.js @@ -1,6 +1,5 @@ var jdb = require('../'); var DataSource = jdb.DataSource; -var should = require('./init.js'); describe('Memory connector with mocked discovery', function() { var ds; diff --git a/test/memory.json b/test/fixtures/memory.json similarity index 100% rename from test/memory.json rename to test/fixtures/memory.json diff --git a/test/spec_helper.js b/test/helpers/spec.js similarity index 100% rename from test/spec_helper.js rename to test/helpers/spec.js diff --git a/test/index.js b/test/index.js new file mode 100644 index 0000000..687a8b0 --- /dev/null +++ b/test/index.js @@ -0,0 +1,8 @@ +var main = require('..'); +var pkgJson = require('../package.json'); + +describe('main', function() { + it('should expose a version number', function() { + main.version.should.equal(pkgJson.version); + }); +}); diff --git a/test/init.js b/test/init.js deleted file mode 100644 index 23d6c73..0000000 --- a/test/init.js +++ /dev/null @@ -1,28 +0,0 @@ -module.exports = require('should'); - -/* - if (!process.env.TRAVIS) { - if (typeof __cov === 'undefined') { - process.on('exit', function () { - require('semicov').report(); - }); - } - - require('semicov').init('lib'); - } - */ - -var ModelBuilder = require('loopback-model/lib/model-builder').ModelBuilder; -var Schema = require('../').Schema; - -if (!('getSchema' in global)) { - global.getSchema = function (connector, settings) { - return new Schema(connector || 'memory', settings); - }; -} - -if (!('getModelBuilder' in global)) { - global.getModelBuilder = function () { - return new ModelBuilder(); - }; -} diff --git a/test/juggler.js b/test/juggler.js deleted file mode 100644 index aa01b50..0000000 --- a/test/juggler.js +++ /dev/null @@ -1,9 +0,0 @@ -var metadata = require('../package.json'); -var project = require('..'); -var should = require('./init.js'); - -describe('juggler', function() { - it('should expose a version number', function() { - project.version.should.equal(metadata.version); - }); -}); diff --git a/test/memory.test.js b/test/memory.js similarity index 99% rename from test/memory.test.js rename to test/memory.js index 5dbfb87..5e874dc 100644 --- a/test/memory.test.js +++ b/test/memory.js @@ -4,11 +4,10 @@ var path = require('path'); var fs = require('fs'); var assert = require('assert'); var async = require('async'); -var should = require('./init.js'); var Memory = require('../lib/connectors/memory').Memory; describe('Memory connector', function() { - var file = path.join(__dirname, 'memory.json'); + var file = path.join(__dirname, '/fixtures/memory.json'); function readModels(done) { fs.readFile(file, function(err, data) { diff --git a/test/connectors/test-sql-connector.js b/test/mocks/sql-connector.js similarity index 100% rename from test/connectors/test-sql-connector.js rename to test/mocks/sql-connector.js diff --git a/test/sql.test.js b/test/sql.js similarity index 99% rename from test/sql.test.js rename to test/sql.js index 0cc0621..2552f84 100644 --- a/test/sql.test.js +++ b/test/sql.js @@ -1,8 +1,7 @@ var DataSource = require('..').DataSource; -var expect = require('chai').expect; var SQLConnector = require('../lib/sql'); var ParameterizedSQL = SQLConnector.ParameterizedSQL; -var testConnector = require('./connectors/test-sql-connector'); +var testConnector = require('./mocks/sql-connector'); var ds = new DataSource({ connector: testConnector, diff --git a/test/transaction.test.js b/test/transaction.js similarity index 98% rename from test/transaction.test.js rename to test/transaction.js index 20e7dd9..ce779a7 100644 --- a/test/transaction.test.js +++ b/test/transaction.js @@ -1,6 +1,5 @@ var DataSource = require('..').DataSource; -var expect = require('chai').expect; -var testConnector = require('./connectors/test-sql-connector'); +var testConnector = require('./mocks/sql-connector'); var Transaction = require('../index').Transaction; var db; diff --git a/test/transient.test.js b/test/transient.js similarity index 98% rename from test/transient.test.js rename to test/transient.js index cd90761..cd99735 100644 --- a/test/transient.test.js +++ b/test/transient.js @@ -1,5 +1,4 @@ var DataSource = require('..').DataSource; -var should = require('./init.js'); describe('connectors.transient', function() { var db;