Merge pull request #47 from strongloop/bug/do-not-use-native-promises
Do not use native promises in tests
This commit is contained in:
commit
d86791435f
24
Gruntfile.js
24
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']);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue