From 7c0a470d643bf8dc5a0c5a041647d28cfcf6e593 Mon Sep 17 00:00:00 2001 From: Ritchie Martori Date: Mon, 14 Apr 2014 12:25:41 -0700 Subject: [PATCH] Add basic Remote connector e2e test --- Gruntfile.js | 91 ++++++++++++++++++++++++++++++-- lib/application.js | 7 ++- package.json | 4 +- test/e2e/remote-connector.e2e.js | 28 ++++++++++ test/fixtures/e2e/app.js | 14 +++++ test/fixtures/e2e/models.js | 4 ++ 6 files changed, 140 insertions(+), 8 deletions(-) create mode 100644 test/e2e/remote-connector.e2e.js create mode 100644 test/fixtures/e2e/app.js create mode 100644 test/fixtures/e2e/models.js diff --git a/Gruntfile.js b/Gruntfile.js index 885f909c..cfd7b873 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -103,11 +103,7 @@ module.exports = function(grunt) { // - PhantomJS // - IE (only Windows) browsers: [ - 'Chrome', - 'Firefox', - 'Opera', - 'Safari', - 'PhantomJS' + 'Chrome' ], // If browser does not capture in given timeout [ms], kill it @@ -136,6 +132,83 @@ module.exports = function(grunt) { // Add browserify to preprocessors 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-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. grunt.registerTask('default', ['browserify']); diff --git a/lib/application.js b/lib/application.js index 54d509ef..6e71ce7c 100644 --- a/lib/application.js +++ b/lib/application.js @@ -56,7 +56,12 @@ app.remotes = function () { if(this._remotes) { return this._remotes; } else { - var options = this.get('remoting') || {}; + var options = {}; + + if(this.get) { + options = this.get('remoting'); + } + return (this._remotes = RemoteObjects.create(options)); } } diff --git a/package.json b/package.json index d956d662..6fd78af6 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "supertest": "~0.9.0", "chai": "~1.9.0", "loopback-testing": "~0.1.2", - "browserify": "~3.30.2", + "browserify": "~3.41.0", "grunt": "~0.4.2", "grunt-browserify": "~1.3.1", "grunt-contrib-uglify": "~0.3.2", @@ -50,7 +50,7 @@ "karma-html2js-preprocessor": "~0.1.0", "karma-phantomjs-launcher": "~0.1.2", "karma": "~0.10.9", - "karma-browserify": "0.1.0", + "karma-browserify": "~0.2.0", "karma-mocha": "~0.1.1", "grunt-karma": "~0.6.2" }, diff --git a/test/e2e/remote-connector.e2e.js b/test/e2e/remote-connector.e2e.js new file mode 100644 index 00000000..c1258056 --- /dev/null +++ b/test/e2e/remote-connector.e2e.js @@ -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(); + }); + }); +}); diff --git a/test/fixtures/e2e/app.js b/test/fixtures/e2e/app.js new file mode 100644 index 00000000..337d6145 --- /dev/null +++ b/test/fixtures/e2e/app.js @@ -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()); diff --git a/test/fixtures/e2e/models.js b/test/fixtures/e2e/models.js new file mode 100644 index 00000000..dad14f61 --- /dev/null +++ b/test/fixtures/e2e/models.js @@ -0,0 +1,4 @@ +var loopback = require('../../../'); +var DataModel = loopback.DataModel; + +exports.TestModel = DataModel.extend('TestModel');