From 3223fb4a6d6a02d70843fd9576cee0b967874e3a Mon Sep 17 00:00:00 2001 From: Spencer Alger Date: Fri, 10 Jan 2014 11:23:08 -0700 Subject: [PATCH] added browser tests, modified ci script, removed testing for version 0.90.x --- .gitignore | 1 + .travis.yml | 20 +++++--- grunt/browser_clients.js | 5 ++ grunt/config/run.js | 17 ++----- grunt/config/saucelabs-mocha.js | 63 +++++++++++++++++++++++++ package.json | 6 +-- scripts/ci.sh | 42 ++++++++--------- scripts/generate/js_api.js | 6 +-- src/elasticsearch | 2 +- src/lib/api.js | 3 ++ src/lib/client_action.js | 6 +-- test/angular_build_unit_tests.html | 9 ++-- test/browser_build_unit_tests.html | 12 +++-- test/integration/yaml_suite/yaml_doc.js | 22 ++++++--- test/jquery_build_unit_tests.html | 13 +++-- test/unit/browser_test_generic_build.js | 17 +++++++ test/unit/browser_test_jquery_build.js | 18 +++++++ test/unit/test_client_action.js | 2 +- test/unit/test_transport.js | 1 + test/utils/server/index.js | 20 +------- 20 files changed, 194 insertions(+), 91 deletions(-) create mode 100644 grunt/config/saucelabs-mocha.js diff --git a/.gitignore b/.gitignore index bf1530c03..4a5f8f3f1 100644 --- a/.gitignore +++ b/.gitignore @@ -13,5 +13,6 @@ test/integration/yaml_suite/yaml_tests.json junit-*.xml test.log elasticsearch*.log +sauce_connect.lo* coverage.html .snapshots \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 5dc0da1c0..12bd67a84 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,21 +1,27 @@ language: node_js node_js: false +env: + global: + - SAUCE_ACCESS_KEY=3259dd1e-a9f2-41cc-afd7-855d80588aeb + - SAUCE_USERNAME=elasticsearch-js matrix: include: - node_js: "0.8" env: ES_BRANCH=master - node_js: "0.10" env: ES_BRANCH=master COVERAGE=1 + # - node_js: "0.10" + # env: ES_BRANCH=0.90 NODE_UNIT=0 + # - node_js: "0.10" + # env: ES_RELEASE=0.90.9 ES_BRANCH=0.90 NODE_UNIT=0 + # - node_js: "0.10" + # env: ES_RELEASE=0.90.8 ES_BRANCH=0.90 NODE_UNIT=0 - node_js: "0.10" - env: ES_BRANCH=0.90 NODE_UNIT=0 + env: NODE_UNIT=0 NODE_INTEGRATION=0 TEST_BROWSER='chrome' - node_js: "0.10" - env: ES_RELEASE=0.90.9 ES_BRANCH=0.90 NODE_UNIT=0 + env: NODE_UNIT=0 NODE_INTEGRATION=0 TEST_BROWSER='firefox' - node_js: "0.10" - env: ES_RELEASE=0.90.8 ES_BRANCH=0.90 NODE_UNIT=0 - - node_js: "0.10" - env: NODE_UNIT=0 NODE_INTEGRATION=0 TEST_BROWSER='firefox::Windows\ XP' - - node_js: "0.10" - env: NODE_UNIT=0 NODE_INTEGRATION=0 TEST_BROWSER='chrome::Windows\ XP' + env: NODE_UNIT=0 NODE_INTEGRATION=0 TEST_BROWSER='ie' exclude: - node_js: false diff --git a/grunt/browser_clients.js b/grunt/browser_clients.js index 8dcde137e..3be17841f 100644 --- a/grunt/browser_clients.js +++ b/grunt/browser_clients.js @@ -35,6 +35,11 @@ module.exports = function (grunt) { 's3:upload_archives' ]); + grunt.registerTask('browser_clients:test', [ + 'run:browser_test_server', + 'saucelabs-mocha' + ]); + grunt.registerTask('__check_for_confirmation', function () { if (grunt.config.get('confirm.release')) { grunt.log.verbose.writeln('release confirmed'); diff --git a/grunt/config/run.js b/grunt/config/run.js index 5ca144e89..53549fec7 100644 --- a/grunt/config/run.js +++ b/grunt/config/run.js @@ -17,20 +17,11 @@ module.exports = { ] } }, - browser_integration_tests: { - exec: 'node ./scripts/run_browser_integration_suite', + browser_test_server: { + exec: 'node ./test/utils/server', options: { - passArgs: [ - 'browsers' - ] - } - }, - browser_unit_tests: { - exec: './node_modules/.bin/testling .', - options: { - passArgs: [ - 'x' - ] + wait: false, + ready: /listening/ } } }; \ No newline at end of file diff --git a/grunt/config/saucelabs-mocha.js b/grunt/config/saucelabs-mocha.js new file mode 100644 index 000000000..65579296d --- /dev/null +++ b/grunt/config/saucelabs-mocha.js @@ -0,0 +1,63 @@ +module.exports = { + options: { + urls: [ + 'http://127.0.0.1:8000/jquery.html', + 'http://127.0.0.1:8000/browser.html', + 'http://127.0.0.1:8000/angular.html' + ], + build: process.env.TRAVIS_JOB_ID || 'local_' + Date.now(), + detailedError: true + }, + chrome: { + options: { + browsers: [ + { + browserName: 'chrome', + platform: 'Windows 8' + }, + { + browserName: 'chrome', + platform: 'Linux' + } + ], + tags: ['master', 'chrome'] + } + }, + ie: { + options: { + browsers: [ + { + browserName: 'internet explorer', + version: '11', + platform: 'Windows 8.1' + }, + { + browserName: 'internet explorer', + version: '10', + platform: 'Windows 8' + }, + { + browserName: 'internet explorer', + version: '9', + platform: 'Windows 7' + } + ], + tags: ['master', 'ie'] + } + }, + firefox: { + options: { + browsers: [ + { + browserName: 'firefox', + platform: 'Windows 7' + }, + { + browserName: 'firefox', + platform: 'Linux' + } + ], + tags: ['master', 'firefox'] + } + } +}; \ No newline at end of file diff --git a/package.json b/package.json index afddc5c66..faa966c6d 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,8 @@ "glob": "~3.2.7", "expect.js": "~0.2.0", "aliasify": "~1.2.1", - "express": "~3.4.7" + "express": "~3.4.7", + "grunt-saucelabs": "git://github.com/spenceralger/grunt-saucelabs.git#stable_mocha_runner" }, "license": "Apache 2.0", "dependencies": { @@ -66,8 +67,7 @@ "test/unit/angular-*.js" ], "files": [ - "test/unit/test_!(file_logger|http_connector|stdio_logger|console_logger|stream_logger|tracer_logger|transport_with_server)*", - "test/unit/browser_test_*.js" + "test/unit/test_!(file_logger|http_connector|stdio_logger|console_logger|stream_logger|tracer_logger|transport_with_server)*" ], "harness": "mocha", "browsers": { diff --git a/scripts/ci.sh b/scripts/ci.sh index 57cf671bf..0e082dd47 100755 --- a/scripts/ci.sh +++ b/scripts/ci.sh @@ -30,7 +30,7 @@ function group { function call { DO="$*" echo -e "\$ ${DO}" - $DO + echo $DO | bash RESULT=$? if [ "$RESULT" -gt "0" ]; then echo "non-zero exit code: $RESULT" @@ -69,10 +69,10 @@ function get_es { SNAPSHOTS="$ROOT/.snapshots" if [ ! -d "$SNAPSHOTS" ]; then - mkdir $SNAPSHOTS + mkdir -p $SNAPSHOTS fi - if [ ! -z $ES_RELEASE ]; then + if [ -n "$ES_RELEASE" ]; then ES_VERSION="v${ES_RELEASE}" ES_URL="https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-${ES_RELEASE}.zip" ES_DIR="${SNAPSHOTS}/${ES_VERSION}" @@ -88,20 +88,17 @@ function get_es { ES_BIN="$ES_DIR/bin/elasticsearch" - echo "Killing existsing java processes" - killall java 2>/dev/null - - cd $SNAPSHOTS + call cd $SNAPSHOTS if [ ! -d "$ES_DIR" ]; then echo "Downloading Elasticsearch $ES_VERSION" call curl -#O $ES_URL - call unzip -q elasticsearch-*.zip - call rm elasticsearch-*.zip - call mv elasticsearch-*/ $ES_DIR + unzip -q elasticsearch-*.zip + rm elasticsearch-*.zip + mv elasticsearch-*/ $ES_DIR fi - cd $ROOT + call cd $ROOT if [ ! -x "$ES_BIN" ]; then echo "Unable to find elasticsearch executable" @@ -126,31 +123,34 @@ function get_es { if [ -n "$ES_BRANCH" ]; then TESTING_BRANCH=$ES_BRANCH -else if [ -n "$ES_V" ]; then +elif [ -n "$ES_V" ]; then TESTING_BRANCH=$ES_V else TESTING_BRANCH="master" fi -if [[ $NODE_UNIT -eq 1 ]]; then +if [[ "$NODE_UNIT" != "0" ]]; then grunt_ jshint mochacov:unit fi -if [ flag $NODE_INTEGRATION ]; then - if [ -n "$ES_BRANCH" ] && [[ $USER != "jenkins" ]]; then +if [[ "$NODE_INTEGRATION" != "0" ]]; then + if [[ -n "$ES_BRANCH" ]] && [[ "$USER" != "jenkins" ]]; then + killall java 2>/dev/null get_es $ES_BRANCH $ES_RELEASE fi - call node scripts/generate --no-api --es_branch=$TESTING_BRANCH + call node scripts/generate --no-api --es_branch=\"$TESTING_BRANCH\" grunt_ mochacov:integration + + if [[ -n "$ES_BRANCH" ]] && [[ "$USER" != "jenkins" ]]; then + killall java 2>/dev/null + fi fi -if [ -n "$TEST_BROWSER" ]; then - call node scripts/browser_tests --browser=\"$TEST_BROWSER\" --es_branch=$TESTING_BRANCH +if [[ -n "$TEST_BROWSER" ]]; then + grunt_ run:browser_test_server saucelabs-mocha:${TEST_BROWSER} fi -if [[ $COVERAGE -eq 1 ]]; then +if [[ "$COVERAGE" == "1" ]]; then grunt_ mochacov:ship_coverage fi - -killall java 2>/dev/null \ No newline at end of file diff --git a/scripts/generate/js_api.js b/scripts/generate/js_api.js index 46cb6ffa7..e94a8d91b 100644 --- a/scripts/generate/js_api.js +++ b/scripts/generate/js_api.js @@ -349,7 +349,7 @@ aliases = { '/{index}/_stats/search/{search_groups}', '/{index}/_stats/fielddata/{fields}' ], - 'search': [ - '/_search' - ] + // 'search': [ + // '/_search' + // ] }; \ No newline at end of file diff --git a/src/elasticsearch b/src/elasticsearch index da680be42..f58ad8533 160000 --- a/src/elasticsearch +++ b/src/elasticsearch @@ -1 +1 @@ -Subproject commit da680be42792920eb5a41853d2a5869ff20854ec +Subproject commit f58ad8533581a37096c444d958a4701a0711569b diff --git a/src/lib/api.js b/src/lib/api.js index b8ebe29cc..ed6d36dad 100644 --- a/src/lib/api.js +++ b/src/lib/api.js @@ -3513,6 +3513,9 @@ api.search = ca({ type: 'list' } } + }, + { + fmt: '/_search' } ], method: 'POST' diff --git a/src/lib/client_action.js b/src/lib/client_action.js index 8d613b067..85fb0cae9 100644 --- a/src/lib/client_action.js +++ b/src/lib/client_action.js @@ -213,10 +213,8 @@ function exec(transport, spec, params, cb) { if (!request.path) { // there must have been some mimimun requirements that were not met - throw new TypeError( - 'Unable to build a path with those params. Supply at least ' + - _.keys(spec.urls[spec.urls.length - 1].req).join(', ') - ); + var minUrl = spec.url || spec.urls[spec.urls.length - 1]; + throw new TypeError('Unable to build a path with those params. Supply at least ' + _.keys(minUrl.req).join(', ')); } // build the query string diff --git a/test/angular_build_unit_tests.html b/test/angular_build_unit_tests.html index a9c53a2cb..65ca1caa2 100644 --- a/test/angular_build_unit_tests.html +++ b/test/angular_build_unit_tests.html @@ -8,10 +8,13 @@
- - + - + \ No newline at end of file diff --git a/test/browser_build_unit_tests.html b/test/browser_build_unit_tests.html index a9c53a2cb..5c1f035c6 100644 --- a/test/browser_build_unit_tests.html +++ b/test/browser_build_unit_tests.html @@ -8,10 +8,12 @@
- - - - - + + + \ No newline at end of file diff --git a/test/integration/yaml_suite/yaml_doc.js b/test/integration/yaml_suite/yaml_doc.js index 7016c6813..1830eaa50 100644 --- a/test/integration/yaml_suite/yaml_doc.js +++ b/test/integration/yaml_suite/yaml_doc.js @@ -117,24 +117,34 @@ function YamlDoc(doc, file) { expect(method).to.be.a('function'); if (_.isPlainObject(action.args)) { - action.name += ' ' + _.keys(action.args).join(', '); + action.name += '(' + JSON.stringify(action.args) + ')'; } else if (action.args) { - action.name += ' ' + action.args; + action.name += '(' + action.args + ')'; } // wrap in a check for skipping action.bound = _.bind(method, self, action.args); - // create a function that can be passed to + // create a function that can be passed to mocha or async action.testable = function (done) { if (self.skipping || self.file.skipping) { return done(); } if (method.length > 1) { - action.bound(done); + action.bound(function (err) { + if (err) { + err.message += ' in ' + action.name; + } + done(err); + }); } else { - action.bound(); - done(); + try { + action.bound(); + done(); + } catch (err) { + err.message += ' in ' + action.name; + done(err); + } } }; diff --git a/test/jquery_build_unit_tests.html b/test/jquery_build_unit_tests.html index a9c53a2cb..c9dc14560 100644 --- a/test/jquery_build_unit_tests.html +++ b/test/jquery_build_unit_tests.html @@ -8,10 +8,13 @@
- - - - - + + + + \ No newline at end of file diff --git a/test/unit/browser_test_generic_build.js b/test/unit/browser_test_generic_build.js index e69de29bb..3c5838969 100644 --- a/test/unit/browser_test_generic_build.js +++ b/test/unit/browser_test_generic_build.js @@ -0,0 +1,17 @@ +/* jshint browser:true */ +var expect = require('expect.js'); + +describe('elasticsearch namespace', function () { + var es = window.elasticsearch; + it('is defined on the window', function () { + expect(es).to.be.ok(); + }); + it('has Client, ConnectionPool, Transport, and errors keys', function () { + expect(es).to.have.keys('Client', 'ConnectionPool', 'Transport', 'errors'); + }); + it('can create a client', function () { + var client = new es.Client({ hosts: null }); + expect(client).to.be.a(es.Client); + client.close(); + }); +}); \ No newline at end of file diff --git a/test/unit/browser_test_jquery_build.js b/test/unit/browser_test_jquery_build.js index e69de29bb..b1b96b30d 100644 --- a/test/unit/browser_test_jquery_build.js +++ b/test/unit/browser_test_jquery_build.js @@ -0,0 +1,18 @@ +/* jshint browser:true */ +var expect = require('expect.js'); + +describe('jQuery.es namespace', function () { + var $ = window.jQuery; + + it('is defined on the global jQuery', function () { + expect($.es).to.be.ok(); + }); + it('has Client, ConnectionPool, Transport, and errors keys', function () { + expect($.es).to.have.keys('Client', 'ConnectionPool', 'Transport', 'errors'); + }); + it('can create a client', function () { + var client = new $.es.Client({ hosts: null }); + expect(client).to.be.a($.es.Client); + client.close(); + }); +}); \ No newline at end of file diff --git a/test/unit/test_client_action.js b/test/unit/test_client_action.js index ea44e7aaa..3dbe00727 100644 --- a/test/unit/test_client_action.js +++ b/test/unit/test_client_action.js @@ -98,7 +98,7 @@ describe('Client Action runner', function () { it('handles passing just the callback', function () { var action = makeClientActionProxy(function (params, cb) { - expect(_.isObject(params)).to.be.ok; + expect(_.isObject(params)).to.be.ok(); expect(cb).to.be.a('function'); }); diff --git a/test/unit/test_transport.js b/test/unit/test_transport.js index 4985431bd..add14206c 100644 --- a/test/unit/test_transport.js +++ b/test/unit/test_transport.js @@ -479,6 +479,7 @@ describe('Transport Class', function () { expect(err).to.be.a(errors.ConnectionFault); expect(resp).to.be(undefined); expect(body).to.be(undefined); + trans.close(); done(); }); }; diff --git a/test/utils/server/index.js b/test/utils/server/index.js index e21986cdb..5731a6456 100644 --- a/test/utils/server/index.js +++ b/test/utils/server/index.js @@ -11,7 +11,6 @@ var pkg = require(root + '/package.json'); var defaultFiles = _.transform(pkg.testling.files, function (files, pattern) { [].push.apply(files, _.map(glob.sync(pattern), function (filename) { - console.log('resolving', filename); return path.resolve(root, filename); })); }, []); @@ -25,7 +24,6 @@ var aliasify = require('aliasify').configure({ function browserBuild(name) { return function (req, res, next) { - res.set('Content-Type', 'application/javascript'); var b = browserify(_.union(defaultFiles, [ @@ -66,23 +64,7 @@ app // bundles .get('/angular_build.js', browserBuild('angular')) .get('/jquery_build.js', browserBuild('jquery')) - .get('/browser_build.js', browserBuild('browser')) - - // stupid - .get('/begin!', function (req, res) { - res.set('Content-Type', 'application/javascript'); - res.send([ - 'mocha.run().on(\'end\', function () {', - ' var stats = window.completeTestStats = {};', - ' for (var key in this.stats) {', - ' if (this.stats.hasOwnProperty(key)) {', - ' stats[key] = this.stats[key];', - ' }', - ' }', - ' console && console.dir && console.dir(window.completeTestStats);', - '});' - ].join('\n')); - }); + .get('/browser_build.js', browserBuild('browser')); http.createServer(app).listen(8000, function () { console.log('listening on port 8000');