From a56e2d9b9bc1fcb3a671e14cab70e4e36c1ed196 Mon Sep 17 00:00:00 2001 From: Amir Abushareb Date: Tue, 7 Oct 2014 18:32:17 +0300 Subject: [PATCH] add cross browser tests --- .travis.yml | 15 ++++----------- Makefile | 11 ++++++----- package.json | 6 ++---- test/analytics.js | 36 +++++++++++++++++++++--------------- test/server/index.html | 6 ++---- 5 files changed, 35 insertions(+), 39 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4cd7fde0d..2380eae3f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,14 +12,7 @@ env: - BROWSER=chrome - BROWSER=firefox - BROWSER=safari - # TODO: add those back once tests are fixed - # - BROWSER=ie11 - # - BROWSER=ie10 - # - BROWSER=ie9 - # TODO: iphone? - # TODO: android? - # TODO: opera - # TODO: once duo-test supports 8-6 - # - BROWSER=ie8 - # - BROWSER=ie7 - # - BROWSER=ie6 + - BROWSER=ie:11 + - BROWSER=ie:10 + - BROWSER=ie:9 + - BROWSER=ie:8 diff --git a/Makefile b/Makefile index 9d3655da5..08b659d57 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,8 @@ # Task args. # -BROWSER ?= chrome,firefox,safari +PORT ?= 0 +BROWSER ?= ie:9 TESTS = $(wildcard test/*.js) SRC = $(wildcard lib/*.js) MINIFY = $(BINS)/uglifyjs @@ -11,7 +12,7 @@ PID = test/server/pid.txt BINS = node_modules/.bin BUILD = build.js DUO = $(BINS)/duo -DUOT = $(BINS)/duo-test +DUOT = $(BINS)/duo-test -p test/server -R spec -P $(PORT) -c "make build.js" # # Default target. @@ -40,14 +41,14 @@ version: component.json # test: $(BUILD) - @$(DUOT) phantomjs test/server + @$(DUOT) phantomjs # # Test with saucelabs # test-sauce: $(BUILD) - @$(DUOT) saucelabs test/server \ + @$(DUOT) saucelabs \ --browsers $(BROWSER) \ --title analytics.js @@ -58,7 +59,7 @@ test-sauce: $(BUILD) # test-browser: $(BUILD) - @$(DUOT) browser default + @$(DUOT) browser # # Phony targets. diff --git a/package.json b/package.json index 1a8444a73..2206dbcd7 100644 --- a/package.json +++ b/package.json @@ -15,12 +15,10 @@ "dependencies": {}, "devDependencies": { "duo": "0.8", - "duo-test": "0.2", - "mocha-phantomjs": "3.1.2", - "phantomjs": "~1.9.2-0", + "duo-test": "0.3", "uglify-js": ">= 1.3.4" }, "scripts": { "test": "make test" } -} \ No newline at end of file +} diff --git a/test/analytics.js b/test/analytics.js index 277f98f8b..67ceef008 100644 --- a/test/analytics.js +++ b/test/analytics.js @@ -337,6 +337,7 @@ describe('Analytics', function () { }); describe('#page', function () { + var head = document.getElementsByTagName('head')[0]; var defaults; beforeEach(function () { @@ -384,10 +385,10 @@ describe('Analytics', function () { var el = document.createElement('link'); el.rel = 'canonical'; el.href = 'baz.com'; - document.head.appendChild(el); + head.appendChild(el); analytics.page(); var page = analytics._invoke.args[0][1]; - assert('baz.com' == page.properties().url); + assert.equal('baz.com' + window.location.search, page.properties().url); el.parentNode.removeChild(el); }); @@ -395,7 +396,7 @@ describe('Analytics', function () { var el = document.createElement('link'); el.rel = 'canonical'; el.href = 'baz.com'; - document.head.appendChild(el); + head.appendChild(el); analytics.page({ search: '?querystring' }); var page = analytics._invoke.args[0][1]; assert('baz.com?querystring' == page.properties().url); @@ -999,10 +1000,13 @@ describe('Analytics', function () { beforeEach(function () { sinon.spy(analytics, 'track'); link = document.createElement('a'); + link.href = '#'; + document.body.appendChild(link); }); afterEach(function () { window.location.hash = ''; + document.body.removeChild(link); }); it('should trigger a track on an element click', function () { @@ -1077,7 +1081,7 @@ describe('Analytics', function () { }); after(function () { - delete window.jQuery; + window.jQuery = null; }); beforeEach(function () { @@ -1088,22 +1092,24 @@ describe('Analytics', function () { submit = document.createElement('input'); submit.type = 'submit'; form.appendChild(submit); + document.body.appendChild(form); }); afterEach(function () { window.location.hash = ''; + document.body.removeChild(form); }); it('should trigger a track on a form submit', function () { analytics.trackForm(form); - trigger(submit, 'click'); + submit.click(); assert(analytics.track.called); }); it('should accept a jquery object for an element', function () { var $form = jQuery(form); analytics.trackForm(form); - trigger(submit, 'click'); + submit.click(); assert(analytics.track.called); }); @@ -1112,51 +1118,51 @@ describe('Analytics', function () { assert.throws(function(){ analytics.trackForm(str); }, TypeError, 'Must pass HTMLElement to `analytics.trackForm`.'); - trigger(submit, 'click'); + submit.click(); assert(!analytics.track.called); }); it('should send an event and properties', function () { analytics.trackForm(form, 'event', { property: true }); - trigger(submit, 'click'); + submit.click(); assert(analytics.track.calledWith('event', { property: true })); }); it('should accept an event function', function () { function event (el) { return 'event'; } analytics.trackForm(form, event); - trigger(submit, 'click'); + submit.click(); assert(analytics.track.calledWith('event')); }); it('should accept a properties function', function () { function properties (el) { return { property: true }; } analytics.trackForm(form, 'event', properties); - trigger(submit, 'click'); + submit.click(); assert(analytics.track.calledWith('event', { property: true })); }); it('should call submit after a timeout', function (done) { - var spy = sinon.spy(form, 'submit'); + var spy = form.submit = sinon.spy(); analytics.trackForm(form); - trigger(submit, 'click'); + submit.click(); setTimeout(function () { assert(spy.called); done(); - }); + }, 50); }); it('should trigger an existing submit handler', function (done) { bind(form, 'submit', function () { done(); }); analytics.trackForm(form); - trigger(submit, 'click'); + submit.click(); }); it('should trigger an existing jquery submit handler', function (done) { var $form = jQuery(form); $form.submit(function () { done(); }); analytics.trackForm(form); - trigger(submit, 'click'); + submit.click(); }); it('should track on a form submitted via jquery', function () { diff --git a/test/server/index.html b/test/server/index.html index 296fc77fc..fb6161678 100644 --- a/test/server/index.html +++ b/test/server/index.html @@ -10,9 +10,7 @@
- - - - + +