From 090d531cf885d78d3007105b55b307f408d00db9 Mon Sep 17 00:00:00 2001 From: Tom Kirkpatrick Date: Sun, 22 Nov 2015 16:09:37 +0000 Subject: [PATCH] Update dependencies, implement test coverate, reorganise repo --- .gitignore | 4 ++- .jscsrc | 5 ++-- .jshintrc | 26 ++++++++++++++++ README.md | 3 ++ circle.yml | 6 ++-- index.js => lib/index.js | 0 read-only.js => lib/read-only.js | 2 +- package.json | 51 ++++++++++++++++++++++---------- test.js => test/test.js | 51 ++++++++++++++++---------------- 9 files changed, 99 insertions(+), 49 deletions(-) create mode 100644 .jshintrc rename index.js => lib/index.js (100%) rename read-only.js => lib/read-only.js (99%) rename test.js => test/test.js (78%) diff --git a/.gitignore b/.gitignore index c2658d7..1fd04da 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -node_modules/ +node_modules +coverage +.nyc_output diff --git a/.jscsrc b/.jscsrc index c5f1a60..f21b369 100644 --- a/.jscsrc +++ b/.jscsrc @@ -16,9 +16,8 @@ "allowComments": true, "allowRegex": true }, - "validateJSDoc": { - "checkParamNames": false, - "checkRedundantParams": false, + "jsDoc": { + "checkParamNames": true, "requireParamTypes": true } } diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..0be18ac --- /dev/null +++ b/.jshintrc @@ -0,0 +1,26 @@ +{ + "node": true, + "esnext": true, + "bitwise": true, + "camelcase": true, + "eqeqeq": true, + "eqnull": true, + "immed": true, + "indent": 2, + "latedef": "nofunc", + "newcap": true, + "nonew": true, + "noarg": true, + "quotmark": "single", + "regexp": true, + "undef": true, + "unused": false, + "trailing": true, + "sub": true, + "maxlen": 120, + "predef": ["-prompt"], + "browser": true, + "devel": true, + "mocha": true, + "expr": true +} diff --git a/README.md b/README.md index f646de1..61cf757 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,9 @@ READONLY ============= +[![Circle CI](https://circleci.com/gh/fullcube/loopback-ds-readonly-mixin.svg?style=svg)](https://circleci.com/gh/fullcube/loopback-ds-readonly-mixin) [![Coverage Status](https://coveralls.io/repos/fullcube/loopback-ds-readonly-mixin/badge.svg?branch=master&service=github)](https://coveralls.io/github/fullcube/loopback-ds-readonly-mixin?branch=master) [![Dependencies](http://img.shields.io/david/fullcube/loopback-ds-readonly-mixin.svg?style=flat)](https://david-dm.org/fullcube/loopback-ds-readonly-mixin) + + This module is designed for the [Strongloop Loopback](https://github.com/strongloop/loopback) framework. It provides a mixin that makes it possible to mark models or model properties as Readonly. A Readonly property may not be written to directly when creating or diff --git a/circle.yml b/circle.yml index b1326f1..94074f2 100644 --- a/circle.yml +++ b/circle.yml @@ -1,3 +1,3 @@ -machine: - node: - version: 0.10.22 +test: + post: + - npm run coverage diff --git a/index.js b/lib/index.js similarity index 100% rename from index.js rename to lib/index.js diff --git a/read-only.js b/lib/read-only.js similarity index 99% rename from read-only.js rename to lib/read-only.js index 26b0b24..a8c6797 100644 --- a/read-only.js +++ b/lib/read-only.js @@ -39,4 +39,4 @@ module.exports = function(Model, options) { Model.beforeRemote('updateAll', function(ctx, modelInstance, next) { Model.stripReadOnlyProperties(ctx, modelInstance, next); }); -} +}; diff --git a/package.json b/package.json index 8838441..0bd46a0 100644 --- a/package.json +++ b/package.json @@ -1,21 +1,38 @@ { "name": "loopback-ds-readonly-mixin", - "version": "1.0.0", "description": "A mixin to enable loopback Model properties to be marked as readonly.", - "main": "index.js", - "scripts": { - "pretest": "jscs index.js && jshint index.js", - "test": "mocha --reporter spec test.js" + "version": "1.0.0", + "main": "./lib/index.js", + "author": "Tom Kirkpatrick @mrfelton", + "contributors": [ + "Bram Borggreve @beeman", + "Matteo Padovano @mrbatista" + ], + "repository": { + "type": "git", + "url": "https://github.com/fullcube/loopback-ds-readonly-mixin.git" }, "keywords": [ "loopback", - "strongloop" + "strongloop", + "mixin" ], - "author": "Tom Kirkpatrick", "license": "MIT", - "repository": { - "type": "git", - "url": "https://github.com/fullcube/loopback-ds-readonly-mixin.git" + "bugs": { + "url": "https://github.com/fullcube/loopback-ds-readonly-mixin/issues" + }, + "homepage": "https://github.com/fullcube/loopback-ds-readonly-mixin", + "files": [ + "lib", + "test" + ], + "scripts": { + "lint": "jscs lib && jshint lib", + "test": "nyc mocha -R spec --timeout 10000 test/test.js", + "test:watch": "npm run test -- -w", + "pretest": "npm run lint", + "coverage": "nyc report --reporter=text-lcov | coveralls", + "outdated": "npm outdated --depth=0" }, "dependencies": { "debug": "2.x", @@ -25,10 +42,14 @@ "loopback-datasource-juggler": ">=2.18.1" }, "devDependencies": { - "loopback": "2.x", - "loopback-testing": "1.x", - "mocha": "2.x", - "jscs": "1.13.x", - "jshint": "2.7.x" + "bluebird": "latest", + "chai": "latest", + "coveralls": "^2.11.4", + "jscs": "latest", + "jshint": "latest", + "loopback": ">=2.22.0", + "loopback-testing": "1.2.0", + "mocha": "latest", + "nyc": "latest" } } diff --git a/test.js b/test/test.js similarity index 78% rename from test.js rename to test/test.js index d800128..b22afc8 100644 --- a/test.js +++ b/test/test.js @@ -1,14 +1,13 @@ -/* jshint mocha: true */ - -var assert = require('assert'); var loopback = require('loopback'); var lt = require('loopback-testing'); +var chai = require('chai'); +var expect = chai.expect; // Create a new loopback app. var app = loopback(); // import our Readonly mixin. -require('./')(app); +require('../lib')(app); describe('loopback datasource readonly property', function() { @@ -48,9 +47,9 @@ describe('loopback datasource readonly property', function() { lt.beforeEach.givenModel('product', {name:'some book', type:'book', status: 'pending'}); it('should save readonly properties on create.', function(done) { - assert.equal(this.product.name, 'some book'); - assert.equal(this.product.type, 'book'); - assert.equal(this.product.status, 'pending'); + expect(this.product.name).to.equal('some book'); + expect(this.product.type).to.equal('book'); + expect(this.product.status).to.equal('pending'); done(); }); @@ -59,10 +58,10 @@ describe('loopback datasource readonly property', function() { self.product.name = 'some other book'; self.product.status = 'disabled'; self.product.save(function(err, p) { - assert.ifError(err); - assert.equal(p.name, self.product.name); - assert.equal(p.type, self.product.type); - assert.equal(p.status, self.product.status); + expect(err).to.not.exist; + expect(p.name).to.equal(self.product.name); + expect(p.type).to.equal(self.product.type); + expect(p.status).to.equal(self.product.status); done(); }); }); @@ -79,9 +78,9 @@ describe('loopback datasource readonly property', function() { }) .expect(200) .end(function(err, res) { - assert.ifError(err); - assert.equal(res.body.name, 'test product'); - assert(!res.body.status); + expect(err).to.not.exist; + expect(res.body.name).to.equal('test product'); + expect(res.body.status).to.not.exist; done(); }); }); @@ -96,9 +95,9 @@ describe('loopback datasource readonly property', function() { }) .expect(200) .end(function(err, res) { - assert.ifError(err); - assert.equal(res.body.name, 'updated name'); - assert.equal(res.body.status, 'pending'); + expect(err).to.not.exist; + expect(res.body.name).to.equal('updated name'); + expect(res.body.status).to.equal('pending'); done(); }); }); @@ -114,10 +113,10 @@ describe('loopback datasource readonly property', function() { }) .expect(200) .end(function(err, res) { - assert.ifError(err); - assert.equal(res.body.name, 'Tom (edited)'); - assert.equal(res.body.status, 'disabled'); - assert.equal(res.body.role, 'user'); + expect(err).to.not.exist; + expect(res.body.name).to.equal('Tom (edited)'); + expect(res.body.status).to.equal('disabled'); + expect(res.body.role).to.equal('user'); done(); }); }); @@ -146,13 +145,13 @@ describe('loopback datasource readonly property', function() { .set('Accept', 'application/json') .expect(200) .end(function(err, res) { - assert.ifError(err); + expect(err).to.not.exist; self.Product.findById(self.book1.id, function(err, b1) { - assert.ifError(err); - assert.equal(b1.status, self.book1.status); + expect(err).to.not.exist; + expect(b1.status).to.equal(self.book1.status); self.Product.findById(self.book2.id, function(err, b2) { - assert.ifError(err); - assert.equal(b2.status, self.book2.status); + expect(err).to.not.exist; + expect(b2.status).to.equal(self.book2.status); done(); }); });