Added the browser based test suite, have it running automatically via PhantomJS with grunt, all tests are passing except one, which requires PhantomJS send a body with a DELETE request

This commit is contained in:
Spencer Alger
2013-11-05 09:57:56 -07:00
parent 4273ffc2c7
commit 7e6fa479ad
34 changed files with 58054 additions and 1008 deletions

View File

@ -21,7 +21,8 @@ module.exports = function (grunt) {
'<%= grunt.template.today("yyyy-mm-dd") %>\n' +
'<%= pkg.homepage ? " * " + pkg.homepage + "\\n" : "" %>' +
' * Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
' Licensed <%= pkg.license %> */\n\n'
' Licensed <%= pkg.license %> */\n' +
' // built using browserify\n\n'
},
clean: {
dist: {
@ -48,18 +49,11 @@ module.exports = function (grunt) {
src: [
'src/**/*.js',
'scripts/**/*.js',
'test/**/*.js -test/browser_integration/yaml_tests.js',
'Gruntfile.js'
],
options: {
jshintrc: '.jshintrc'
}
},
tests: {
src: [
'test/**/*.js'
],
options: {
jshintrc: 'test/.jshintrc'
jshintrc: true
}
}
},
@ -85,37 +79,66 @@ module.exports = function (grunt) {
'scripts/generate/js_api'
]
},
yaml_suite: {
yaml_tests: {
cmd: 'node',
args: [
'scripts/generate/yaml_tests'
]
}
},
start: {
integration_server: {
cmd: 'node',
args: [
'test/browser_integration/server.js'
]
}
},
browserify: {
generic: {
client: {
files: {
'<%= distDir %>/elasticsearch.js': 'src/elasticsearch.js'
},
options: {
standalone: 'true',
standalone: 'elasticsearch',
ignore: _.union(sharedBrowserfyExclusions, [
'src/lib/connectors/jquery.js',
'src/lib/connectors/angular.js'
])
}
},
angular: {
angular_client: {
files: {
'<%= distDir %>/elasticsearch.angular.js': ['src/elasticsearch.angular.js']
},
options: {
standalone: 'true',
standalone: 'elasticsearch',
ignore: _.union(sharedBrowserfyExclusions, [
'src/lib/connectors/jquery.js',
'src/lib/connectors/xhr.js'
])
}
},
yaml_suite: {
files: {
'test/browser_integration/yaml_tests.js': ['test/integration/yaml_suite/index.js']
},
options: {
external: [
'optimist'
]
}
}
},
concat: {
dist_banners: {
files: {
'<%= distDir %>/elasticsearch.js': ['<%= distDir %>/elasticsearch.js'],
'<%= distDir %>/elasticsearch.angular.js': ['<%= distDir %>/elasticsearch.angular.js']
},
options: {
banner: '<%= meta.banner %>'
}
}
},
uglify: {
@ -134,68 +157,48 @@ module.exports = function (grunt) {
}
}
}
}//,
// docular: {
// groups: [
// {
// groupTitle: 'Node',
// groupId: 'example',
// groupIcon: 'icon-beer',
// sections: [
// {
// id: "client",
// title: "Client",
// scripts: [
// "src/lib/client.js"
// ],
// docs: [],
// rank : {}
// }
// ]
// }
// ],
// }
// ,
// yuidoc: {
// compile: {
// name: '<%= pkg.name %>',
// description: '<%= pkg.description %>',
// version: '<%= pkg.version %>',
// url: '<%= pkg.homepage %>',
// logo: '<%= pkg.logo %>',
// options: {
// paths: 'src',
// themedir: '../yuidoc-bootstrap-theme',
// helpers: [
// '../yuidoc-bootstrap-theme/helpers/helpers.js'
// ],
// outdir: 'docs'
// }
// }
// }
},
mocha: {
yaml_suite: {
options: {
// log: true,
run: true,
urls: [ 'http://localhost:8888' ],
timeout: 10e3,
'--web-security': false
}
}
}
});
// load plugins
// grunt.loadNpmTasks('grunt-docular');
grunt.loadNpmTasks('grunt-mocha');
grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks('grunt-mocha-test');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jshint');
// Default task.
grunt.registerTask('default', [
/*jshint scripturl:true*/
'jshint',
'mochaTest:unit',
'generate:yaml_suite',
'mochaTest:yaml_suite'
'build',
'mochaTest:yaml_suite',
'start:integration_server',
// 'mocha:yaml_suite' -- this will fail because of the way that PhantomJS handle's DELETE requests with body's
]);
grunt.registerTask('build', [
'clean:dist',
'browserify',
'uglify:dist'
'uglify:dist',
'concat:dist_banners',
'generate:yaml_tests',
'generate:js_api'
]);
grunt.task.registerMultiTask('generate', 'used to generate things', function () {
@ -216,4 +219,51 @@ module.exports = function (grunt) {
});
});
var runningProcs = {};
process.on('exit', function () {
_.each(runningProcs, function (proc) {
proc.kill();
});
});
grunt.task.registerMultiTask('start', 'used to start external processes (like servers)', function () {
var self = this;
var proc = require('child_process').spawn(
self.data.cmd,
self.data.args,
{
stdio: ['ignore', 'pipe', 'pipe']
}
);
proc.stdout.on('data', grunt.log.write);
proc.stderr.on('data', function (chunk) {
grunt.log.error(chunk);
proc.kill();
self.ansyc()(new Error('Error output received'));
clearTimeout(timeoutId);
});
runningProcs[self.nameArgs] = proc;
proc.on('close', function (exitCode) {
delete runningProcs[self.nameArgs];
});
// operates asyncronously to give the processes a moment to start up, not sure if there is a signal for "I'm ready"
var timeoutId = setTimeout(self.async(), 1000);
});
grunt.task.registerMultiTask('stop', 'used to stop external processes (like servers)', function () {
var proc = runningProcs[this.nameArgs.replace(/^start:/, 'stop:')];
if (proc) {
proc.kill();
} else {
grunt.log.error(this.nameArgs + ' failed to find active process');
}
});
};