Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Commit

Permalink
new test fixtures and working debug
Browse files Browse the repository at this point in the history
The old test is now test-index which tests the deprecated index file
method.
New tests are using a loopback app in the fixtures directory to
simulate loading the mixin.
Using require for the debug module, unlikely it more useful than just
requiring it without the local module as of yet but may want to try
again later.
  • Loading branch information
clarkbw committed Jul 11, 2015
1 parent 053a7e6 commit fa5b452
Show file tree
Hide file tree
Showing 16 changed files with 384 additions and 27 deletions.
2 changes: 2 additions & 0 deletions .npmignore
@@ -1,2 +1,4 @@
.jscsrc
.travis.yml
.jshintignore
.jshintrc
2 changes: 1 addition & 1 deletion debug.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion debug.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions es6/time-stamp.js
@@ -1,10 +1,10 @@
import debug from './debug';
const debug = require('./debug')();

export default (Model, options) => {
export default (Model, options = {}) => {

debug('TimeStamp mixin for Model %s', Model.modelName);

Object.assign(options, { createdAt: 'createdAt', updatedAt: 'updatedAt', required: true});
options = Object.assign({ createdAt: 'createdAt', updatedAt: 'updatedAt', required: true}, options);

debug('options', options);

Expand Down
17 changes: 9 additions & 8 deletions package.json
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"pretest": "jscs ./es6/*.js && jshint ./es6/*.js",
"test": "nyc tap ./test.js",
"test": "nyc tap ./test/*.js",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"outdated": "npm outdated --depth=0"
},
Expand All @@ -26,16 +26,17 @@
"loopback-datasource-juggler": ">=2.23.0"
},
"devDependencies": {
"gulp": "^3.9.0",
"gulp-babel": "^5.1.0",
"gulp-sourcemaps": "^1.5.2",
"babel-core": "^5.5.6",
"babel-plugin-object-assign": "^1.1.0",
"coveralls": "^2.11.2",
"jscs": "^1.13.1",
"jshint": "^2.8.0",
"gulp": "^3.9.0",
"gulp-babel": "^5.1.0",
"gulp-sourcemaps": "^1.5.2",
"jscs": "latest",
"jshint": "latest",
"loopback": "2.x",
"nyc": "^2.2.1",
"tap": "^1.2.0"
"loopback-boot": "2.x",
"nyc": "latest",
"tap": "latest"
}
}
3 changes: 3 additions & 0 deletions test/fixtures/simple-app/common/models/widget.js
@@ -0,0 +1,3 @@
module.exports = function(Widget) {

};
21 changes: 21 additions & 0 deletions test/fixtures/simple-app/common/models/widget.json
@@ -0,0 +1,21 @@
{
"name": "Widget",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"name": {
"type": "string",
"required": false
},
"type": {
"type": "string",
"required": false
}
},
"mixins": {
"TimeStamp" : true
}
}
6 changes: 6 additions & 0 deletions test/fixtures/simple-app/server/config.json
@@ -0,0 +1,6 @@
{
"restApiRoot": "/api",
"host": "0.0.0.0",
"port": 3000,
"legacyExplorer": false
}
6 changes: 6 additions & 0 deletions test/fixtures/simple-app/server/datasources.json
@@ -0,0 +1,6 @@
{
"db": {
"name": "db",
"connector": "memory"
}
}
20 changes: 20 additions & 0 deletions test/fixtures/simple-app/server/middleware.json
@@ -0,0 +1,20 @@
{
"initial:before": {
},
"initial": {
},
"session": {
},
"auth": {
},
"parse": {
},
"routes": {
},
"files": {
},
"final": {
},
"final:after": {
}
}
33 changes: 33 additions & 0 deletions test/fixtures/simple-app/server/model-config.json
@@ -0,0 +1,33 @@
{
"_meta": {
"sources": [
"../common/models"
],
"mixins": [
"../../../../"
]
},
"User": {
"dataSource": "db"
},
"AccessToken": {
"dataSource": "db",
"public": false
},
"ACL": {
"dataSource": "db",
"public": false
},
"RoleMapping": {
"dataSource": "db",
"public": false
},
"Role": {
"dataSource": "db",
"public": false
},
"Widget": {
"dataSource": "db",
"public": false
}
}
22 changes: 22 additions & 0 deletions test/fixtures/simple-app/server/server.js
@@ -0,0 +1,22 @@
var loopback = require('loopback');
var boot = require('loopback-boot');

var app = module.exports = loopback();

app.start = function() {
// start the web server
return app.listen(function() {
app.emit('started');
console.log('Web server listening at: %s', app.get('url'));
});
};

// Bootstrap the application, configure models, datasources and middleware.
// Sub-apps like REST API are mounted via boot scripts.
boot(app, __dirname, function(err) {
if (err) throw err;

// start the server if `$ node server.js`
if (require.main === module)
app.start();
});
11 changes: 10 additions & 1 deletion test.js → test/test-index.js
Expand Up @@ -11,7 +11,7 @@ var dataSource = app.createDataSource({
});

// import our TimeStamp mixin
require('./')(app);
require('../')(app);

test('loopback datasource timestamps', function(tap) {
'use strict';
Expand Down Expand Up @@ -83,6 +83,8 @@ test('loopback datasource timestamps', function(tap) {
});
});

t.end();

});

tap.test('updatedAt', function(t) {
Expand Down Expand Up @@ -161,6 +163,8 @@ test('loopback datasource timestamps', function(tap) {
});
});

t.end();

});

tap.test('boot options', function(t) {
Expand Down Expand Up @@ -208,6 +212,8 @@ test('loopback datasource timestamps', function(tap) {
tt.end();
});

t.end();

});

tap.test('operation hook options', function(t) {
Expand Down Expand Up @@ -241,6 +247,9 @@ test('loopback datasource timestamps', function(tap) {
});
});

t.end();
});

tap.end();

});

0 comments on commit fa5b452

Please sign in to comment.