Add basic Remote connector e2e test

This commit is contained in:
Ritchie Martori 2014-04-14 12:25:41 -07:00
parent 5298834c68
commit 7c0a470d64
6 changed files with 140 additions and 8 deletions

View File

@ -103,11 +103,7 @@ module.exports = function(grunt) {
// - PhantomJS // - PhantomJS
// - IE (only Windows) // - IE (only Windows)
browsers: [ browsers: [
'Chrome', 'Chrome'
'Firefox',
'Opera',
'Safari',
'PhantomJS'
], ],
// If browser does not capture in given timeout [ms], kill it // If browser does not capture in given timeout [ms], kill it
@ -136,6 +132,83 @@ module.exports = function(grunt) {
// Add browserify to preprocessors // Add browserify to preprocessors
preprocessors: {'test/*': ['browserify']} preprocessors: {'test/*': ['browserify']}
} }
},
e2e: {
options: {
// base path, that will be used to resolve files and exclude
basePath: '',
// frameworks to use
frameworks: ['mocha', 'browserify'],
// list of files / patterns to load in the browser
files: [
'test/e2e/remote-connector.e2e.js'
],
// list of files to exclude
exclude: [
],
// test results reporter to use
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
reporters: ['dots'],
// web server port
port: 9876,
// cli runner port
runnerPort: 9100,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: 'warn',
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: [
'Chrome'
],
// If browser does not capture in given timeout [ms], kill it
captureTimeout: 60000,
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false,
// Browserify config (all optional)
browserify: {
// extensions: ['.coffee'],
ignore: [
'nodemailer',
'passport',
'passport-local',
'superagent',
'supertest'
],
// transform: ['coffeeify'],
// debug: true,
// noParse: ['jquery'],
watch: true,
},
// Add browserify to preprocessors
preprocessors: {'test/e2e/*': ['browserify']}
}
} }
} }
@ -148,6 +221,14 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-watch'); grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-karma'); grunt.loadNpmTasks('grunt-karma');
grunt.registerTask('e2e-server', function() {
var done = this.async();
var app = require('./test/fixtures/e2e/app');
app.listen(3000, done);
});
grunt.registerTask('e2e', ['e2e-server', 'karma:e2e']);
// Default task. // Default task.
grunt.registerTask('default', ['browserify']); grunt.registerTask('default', ['browserify']);

View File

@ -56,7 +56,12 @@ app.remotes = function () {
if(this._remotes) { if(this._remotes) {
return this._remotes; return this._remotes;
} else { } else {
var options = this.get('remoting') || {}; var options = {};
if(this.get) {
options = this.get('remoting');
}
return (this._remotes = RemoteObjects.create(options)); return (this._remotes = RemoteObjects.create(options));
} }
} }

View File

@ -38,7 +38,7 @@
"supertest": "~0.9.0", "supertest": "~0.9.0",
"chai": "~1.9.0", "chai": "~1.9.0",
"loopback-testing": "~0.1.2", "loopback-testing": "~0.1.2",
"browserify": "~3.30.2", "browserify": "~3.41.0",
"grunt": "~0.4.2", "grunt": "~0.4.2",
"grunt-browserify": "~1.3.1", "grunt-browserify": "~1.3.1",
"grunt-contrib-uglify": "~0.3.2", "grunt-contrib-uglify": "~0.3.2",
@ -50,7 +50,7 @@
"karma-html2js-preprocessor": "~0.1.0", "karma-html2js-preprocessor": "~0.1.0",
"karma-phantomjs-launcher": "~0.1.2", "karma-phantomjs-launcher": "~0.1.2",
"karma": "~0.10.9", "karma": "~0.10.9",
"karma-browserify": "0.1.0", "karma-browserify": "~0.2.0",
"karma-mocha": "~0.1.1", "karma-mocha": "~0.1.1",
"grunt-karma": "~0.6.2" "grunt-karma": "~0.6.2"
}, },

View File

@ -0,0 +1,28 @@
var path = require('path');
var loopback = require('../../');
var models = require('../fixtures/e2e/models');
var TestModel = models.TestModel;
var assert = require('assert');
describe('RemoteConnector', function() {
before(function() {
// setup the remote connector
var localApp = loopback();
var ds = loopback.createDataSource({
url: 'http://localhost:3000/api',
connector: loopback.Remote
});
localApp.model(TestModel);
TestModel.attachTo(ds);
});
it('should be able to call create', function (done) {
TestModel.create({
foo: 'bar'
}, function(err, inst) {
if(err) return done(err);
assert(inst.id);
done();
});
});
});

14
test/fixtures/e2e/app.js vendored Normal file
View File

@ -0,0 +1,14 @@
var loopback = require('../../../');
var path = require('path');
var app = module.exports = loopback();
var models = require('./models');
var TestModel = models.TestModel;
app.use(loopback.cookieParser({secret: app.get('cookieSecret')}));
var apiPath = '/api';
app.use(apiPath, loopback.rest());
app.use(loopback.static(path.join(__dirname, 'public')));
app.use(loopback.urlNotFound());
app.use(loopback.errorHandler());
app.model(TestModel);
TestModel.attachTo(loopback.memory());

4
test/fixtures/e2e/models.js vendored Normal file
View File

@ -0,0 +1,4 @@
var loopback = require('../../../');
var DataModel = loopback.DataModel;
exports.TestModel = DataModel.extend('TestModel');