From 33dfb50806e5f17186e60e8c4d751d7f29c526d4 Mon Sep 17 00:00:00 2001 From: David Luecke Date: Mon, 23 Nov 2015 18:34:58 -0800 Subject: [PATCH] Use CommonJS export Babel plugin --- .babelrc | 2 +- README.md | 4 ++++ package.json | 3 ++- src/index.js | 8 +++++--- test/index.test.js | 25 +++---------------------- 5 files changed, 15 insertions(+), 27 deletions(-) diff --git a/.babelrc b/.babelrc index 945d1f7..98c4914 100644 --- a/.babelrc +++ b/.babelrc @@ -1,4 +1,4 @@ { - "plugins": ["transform-object-assign"], + "plugins": ["transform-object-assign", "add-module-exports"], "presets": [ "es2015" ] } diff --git a/README.md b/README.md index 0034eaf..33d52e5 100644 --- a/README.md +++ b/README.md @@ -323,6 +323,10 @@ query: { ## Changelog +__1.2.x__ + +- Babel 6 support, Object.assign polyfill and CommonJS module backwards compatibility + __1.1.0__ - Compatibility with latest service tests diff --git a/package.json b/package.json index abd7353..fbc422c 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "compile": "rm -rf lib/ && babel -d lib/ src/", "jshint": "jshint src/. test/. --config", "mocha": "mocha test/ --compilers js:babel-core/register", - "test": "npm run jshint && npm run mocha" + "test": "npm run compile && npm run jshint && npm run mocha" }, "directories": { "lib": "lib" @@ -54,6 +54,7 @@ "devDependencies": { "babel-cli": "^6.1.4", "babel-core": "^6.1.4", + "babel-plugin-add-module-exports": "^0.1.1", "babel-plugin-transform-object-assign": "^6.1.18", "babel-preset-es2015": "^6.1.4", "chai": "^3.4.0", diff --git a/src/index.js b/src/index.js index e1b234c..06d16ca 100644 --- a/src/index.js +++ b/src/index.js @@ -19,7 +19,7 @@ const OPERATORS = { }; // Create the service. -export const Service = Proto.extend({ +const Service = Proto.extend({ init(name, options) { if(typeof name !== 'string') { throw new Error('No table name specified.'); @@ -229,6 +229,8 @@ export const Service = Proto.extend({ } }); -export default module.exports = function() { +export default function create() { return Proto.create.apply(Service, arguments); -}; +} + +create.Service = Service; diff --git a/test/index.test.js b/test/index.test.js index 34e3eee..c4ffcb6 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -1,6 +1,6 @@ /*jshint expr: true*/ -import chai from 'chai'; +import assert from 'assert'; import baseTests from 'feathers-service-tests'; import { errors } from 'feathers'; import service from '../src'; @@ -12,7 +12,6 @@ const options = { } }; -let expect = chai.expect; let _ids = {}; let people = service('people', options); @@ -57,26 +56,8 @@ describe('Feathers Knex Service', () => { }); }); - describe('init', () => { - describe('without table', () => { - it('throws an error', () => { - expect(service).to.throw('No table name specified.'); - }); - }); - - describe.skip('with table', () => { - it('sets up a database connection via config', () => { - // expect(service).to.throw('No table name specified.'); - }); - - it('sets up a database connection via connection string', () => { - // expect(service).to.throw('No table name specified.'); - }); - - it('sets up a database connection via socket config', () => { - // expect(service).to.throw('No table name specified.'); - }); - }); + it('is CommonJS compatible', () => { + assert.equal(typeof require('../lib'), 'function'); }); baseTests(people, _ids, errors.types);