Merge pull request #47 from strongloop/bug/do-not-use-native-promises

Do not use native promises in tests
This commit is contained in:
Miroslav Bajtoš 2016-05-20 14:36:07 +02:00
commit d86791435f
4 changed files with 77 additions and 13 deletions

View File

@ -28,6 +28,19 @@ module.exports = function(grunt) {
} }
}, },
mochaTest: { mochaTest: {
'integration': {
src: 'test/integration/*.js',
options: {
reporter: 'dot'
}
},
'integration-xml': {
src: 'test/integration/*.js',
options: {
reporter: 'xunit',
captureFile: 'xintegration.xml'
}
},
'unit': { 'unit': {
src: 'test/*.js', src: 'test/*.js',
options: { options: {
@ -49,8 +62,13 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-jshint'); grunt.loadNpmTasks('grunt-contrib-jshint');
// Default task. // Default task.
grunt.registerTask('default', ['test']); grunt.registerTask('default', ['unit', 'integration']);
grunt.registerTask('test', [ if (process.env.JENKINS_HOME) {
process.env.JENKINS_HOME ? 'mochaTest:unit-xml' : 'mochaTest:unit']); grunt.registerTask('unit', ['mochaTest:unit-xml']);
grunt.registerTask('integration', ['mochaTest:integration-xml']);
} else {
grunt.registerTask('unit', ['mochaTest:unit']);
grunt.registerTask('integration', ['mochaTest:integration']);
}
}; };

View File

@ -10,7 +10,7 @@
"StrongLoop" "StrongLoop"
], ],
"scripts": { "scripts": {
"test": "grunt test" "test": "grunt"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -31,6 +31,7 @@
}, },
"devDependencies": { "devDependencies": {
"assert": "^1.1.2", "assert": "^1.1.2",
"bluebird": "^3.3.5",
"grunt": "~0.4.5", "grunt": "~0.4.5",
"grunt-cli": "^0.1.13", "grunt-cli": "^0.1.13",
"grunt-contrib-jshint": "~0.10.0", "grunt-contrib-jshint": "~0.10.0",

View File

@ -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;
}

View File

@ -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() { describe('Model.create([data], [callback])', function() {
it('should create an instance and save to the attached data source', it('should create an instance and save to the attached data source',
function(done) { function(done) {