diff --git a/Gruntfile.js b/Gruntfile.js index a3d9127..1714fc5 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -28,6 +28,19 @@ module.exports = function(grunt) { } }, mochaTest: { + 'integration': { + src: 'test/integration/*.js', + options: { + reporter: 'dot' + } + }, + 'integration-xml': { + src: 'test/integration/*.js', + options: { + reporter: 'xunit', + captureFile: 'xintegration.xml' + } + }, 'unit': { src: 'test/*.js', options: { @@ -49,8 +62,13 @@ module.exports = function(grunt) { grunt.loadNpmTasks('grunt-contrib-jshint'); // Default task. - grunt.registerTask('default', ['test']); + grunt.registerTask('default', ['unit', 'integration']); - grunt.registerTask('test', [ - process.env.JENKINS_HOME ? 'mochaTest:unit-xml' : 'mochaTest:unit']); + if (process.env.JENKINS_HOME) { + grunt.registerTask('unit', ['mochaTest:unit-xml']); + grunt.registerTask('integration', ['mochaTest:integration-xml']); + } else { + grunt.registerTask('unit', ['mochaTest:unit']); + grunt.registerTask('integration', ['mochaTest:integration']); + } }; diff --git a/package.json b/package.json index a881114..c21c169 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "StrongLoop" ], "scripts": { - "test": "grunt test" + "test": "grunt" }, "repository": { "type": "git", @@ -31,6 +31,7 @@ }, "devDependencies": { "assert": "^1.1.2", + "bluebird": "^3.3.5", "grunt": "~0.4.5", "grunt-cli": "^0.1.13", "grunt-contrib-jshint": "~0.10.0", diff --git a/test/integration/promise-support.js b/test/integration/promise-support.js new file mode 100644 index 0000000..e312f94 --- /dev/null +++ b/test/integration/promise-support.js @@ -0,0 +1,54 @@ +var assert = require('assert'); +var helper = require('../helper'); +var Promise = require('bluebird'); + +var globalPromiseSetManually = false; +var User; + +describe('promise support', function() { + before(setGlobalPromise); + before(createUserModel); + after(resetGlobalPromise); + + context('create', function() { + it('supports promises', function() { + var retval = User.create(); + assert(retval && typeof retval.then === 'function'); + }); + }); + + context('find', function() { + it('supports promises', function() { + var retval = User.find(); + assert(retval && typeof retval.then === 'function'); + }); + }); + + context('findById', function() { + it('supports promises', function() { + var retval = User.findById(1); + assert(retval && typeof retval.then === 'function'); + }); + }); +}); + +function setGlobalPromise() { + if (!global.Promise) { + global.Promise = Promise; + globalPromiseSetManually = true; + } +} + +function createUserModel() { + User = helper.createModel({ + parent: 'user', + app: helper.createRestAppAndListen(), + datasource: helper.createMemoryDataSource(), + properties: helper.getUserProperties() + }); +} + +function resetGlobalPromise() { + if (globalPromiseSetManually) + global.Promise = undefined; +} diff --git a/test/models.test.js b/test/models.test.js index c0054cc..624cf0c 100644 --- a/test/models.test.js +++ b/test/models.test.js @@ -99,15 +99,6 @@ describe('Model tests', function() { }); }); - describe('Model methods', function() { - it('should support promises', function(done) { - assert(User.create() instanceof Promise); - assert(User.find() instanceof Promise); - assert(User.findById(99) instanceof Promise); - done(); - }); - }); - describe('Model.create([data], [callback])', function() { it('should create an instance and save to the attached data source', function(done) {