Skip to content
This repository was archived by the owner on Apr 28, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 6 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
# Task args.
#

BROWSER ?= chrome,firefox,safari
PORT ?= 0
BROWSER ?= ie:9
TESTS = $(wildcard test/*.js)
SRC = $(wildcard lib/*.js)
MINIFY = $(BINS)/uglifyjs
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.
Expand Down Expand Up @@ -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

Expand All @@ -58,7 +59,7 @@ test-sauce: $(BUILD)
#

test-browser: $(BUILD)
@$(DUOT) browser default
@$(DUOT) browser

#
# Phony targets.
Expand Down
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
36 changes: 21 additions & 15 deletions test/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ describe('Analytics', function () {
});

describe('#page', function () {
var head = document.getElementsByTagName('head')[0];
var defaults;

beforeEach(function () {
Expand Down Expand Up @@ -384,18 +385,18 @@ 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);
});

it('should append querystring to canonical url', 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);
Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -1077,7 +1081,7 @@ describe('Analytics', function () {
});

after(function () {
delete window.jQuery;
window.jQuery = null;
});

beforeEach(function () {
Expand All @@ -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);
});

Expand All @@ -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 () {
Expand Down
6 changes: 2 additions & 4 deletions test/server/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
</head>
<body>
<div id="mocha"></div>
<script src="/saucelabs.js"></script>
<script>m = window.mochaPhantomJS || mocha</script>
<script>s = window.saucelabs || function(){}</script>
<script>s(m.run())</script>
<script src="/duotest.js"></script>
<script>duotest(mocha.run())</script>
</body>
</html>