Skip to content
This repository was archived by the owner on Jan 15, 2026. It is now read-only.

Commit 008ba11

Browse files
Paul Boocockpaulboocock
authored andcommitted
Improve test coverage (close snowplow#861)
1 parent 7100386 commit 008ba11

23 files changed

Lines changed: 2370 additions & 1395 deletions

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Build
33
on:
44
push:
55
branches:
6-
- '**' # Prevents builds on tag
6+
- 'master'
77
pull_request:
88

99
jobs:
@@ -55,7 +55,7 @@ jobs:
5555
if: ${{ env.SAUCE_ACCESS_KEY != '' }}
5656
uses: softprops/turnstyle@v1
5757
with:
58-
poll-interval-seconds: 10
58+
poll-interval-seconds: 20
5959
same-branch-only: false
6060
env:
6161
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/deploy_tracker.yml

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,6 @@ jobs:
5050
- name: Test tracker
5151
run: npm run test:unit
5252

53-
- name: Block Concurrent Executions of E2E Tests
54-
if: ${{ env.SAUCE_ACCESS_KEY != '' }}
55-
uses: softprops/turnstyle@v1
56-
with:
57-
poll-interval-seconds: 10
58-
same-branch-only: false
59-
env:
60-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61-
62-
- name: Add Host for Saucelabs Tunnel
63-
if: ${{ env.SAUCE_ACCESS_KEY != '' }}
64-
run: echo "127.0.0.1 snowplow-js-tracker.local" | sudo tee -a /etc/hosts
65-
66-
- name: Run End to End Tests
67-
run: npm run test:e2e:sauce
68-
if: ${{ env.SAUCE_ACCESS_KEY != '' }}
69-
7053
- name: Get tag and tracker version information
7154
id: version
7255
run: |

src/js/out_queue.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,8 @@ export function OutQueueManager(
382382
executeQueue();
383383
}
384384
}, connectionTimeout);
385+
} else {
386+
executingQueue = false;
385387
}
386388
}
387389

@@ -447,7 +449,7 @@ export function OutQueueManager(
447449

448450
return {
449451
enqueueRequest: enqueueRequest,
450-
executeQueue: executeQueue,
452+
executeQueue: () => { if (!executingQueue) { executeQueue(); } },
451453
setUseLocalStorage: (localStorage) => { useLocalStorage = localStorage; },
452454
setAnonymousTracking: (anonymous) => { anonymousTracking = anonymous; }
453455
};

src/js/tracker.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3081,16 +3081,11 @@ export function Tracker(functionName, namespace, version, mutSnowplowState, argm
30813081
*/
30823082
apiMethods.disableAnonymousTracking = function (stateStorageStrategy) {
30833083
if (stateStorageStrategy) {
3084-
Object.assign(argmap, {
3085-
stateStorageStrategy: stateStorageStrategy,
3086-
anonymousTracking: false,
3087-
});
3088-
3084+
argmap.stateStorageStrategy = stateStorageStrategy;
3085+
argmap.anonymousTracking = false;
30893086
configStateStorageStrategy = getStateStorageStrategy(argmap);
30903087
} else {
3091-
Object.assign(argmap, {
3092-
anonymousTracking: false,
3093-
});
3088+
argmap.anonymousTracking = false;
30943089
}
30953090

30963091
configAnonymousTracking = getAnonymousTracking(argmap);
@@ -3109,9 +3104,7 @@ export function Tracker(functionName, namespace, version, mutSnowplowState, argm
31093104
* Enables anonymous tracking (ie. tracker initialized without `anonymousTracking`)
31103105
*/
31113106
apiMethods.enableAnonymousTracking = function (anonymousArgs) {
3112-
Object.assign(argmap, {
3113-
anonymousTracking: anonymousArgs || true,
3114-
});
3107+
argmap.anonymousTracking = anonymousArgs || true;
31153108

31163109
configAnonymousTracking = getAnonymousTracking(argmap);
31173110
configAnonymousSessionTracking = getAnonymousSessionTracking(argmap);

tests/functional/cookies.spec.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* JavaScript tracker for Snowplow: tests/functional/cookies.spec.js
3+
*
4+
* Significant portions copyright 2010 Anthon Pang. Remainder copyright
5+
* 2012-2020 Snowplow Analytics Ltd. All rights reserved.
6+
*
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are
9+
* met:
10+
*
11+
* * Redistributions of source code must retain the above copyright
12+
* notice, this list of conditions and the following disclaimer.
13+
*
14+
* * Redistributions in binary form must reproduce the above copyright
15+
* notice, this list of conditions and the following disclaimer in the
16+
* documentation and/or other materials provided with the distribution.
17+
*
18+
* * Neither the name of Anthon Pang nor Snowplow Analytics Ltd nor the
19+
* names of their contributors may be used to endorse or promote products
20+
* derived from this software without specific prior written permission.
21+
*
22+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33+
*/
34+
35+
describe('Tracker created domain cookies', () => {
36+
it('contain the expected cookie names', () => {
37+
browser.url('/cookies.html')
38+
browser.waitUntil(
39+
() => $('#init').getText() === 'true',
40+
5000,
41+
'expected init after 5s'
42+
)
43+
44+
browser.waitUntil(
45+
() => $('#cookies').getText() !== '',
46+
5000,
47+
'expected cookie to be set after 5s'
48+
)
49+
50+
const cookies = $('#cookies').getText();
51+
52+
expect(cookies).not.toContain('_sp_0ses.'); // Missing as tests are not HTTPS and `cookieSecure: true` by default
53+
expect(cookies).not.toContain('_sp_0id.');
54+
expect(cookies).not.toContain('_sp_3es.'); // Missing as cookie lifetime is too short (1)
55+
expect(cookies).not.toContain('_sp_3id.');
56+
expect(cookies).not.toContain('_sp_4ses.'); // Missing as anonymous tracking enabled
57+
expect(cookies).not.toContain('_sp_4id.');
58+
expect(cookies).not.toContain('_sp_5ses.'); // Missing as only using local storage
59+
expect(cookies).not.toContain('_sp_5id.');
60+
expect(cookies).not.toContain('_sp_7ses.'); // Can't set a cookie for another domain
61+
expect(cookies).not.toContain('_sp_7id.');
62+
63+
expect(cookies).toContain('_sp_1ses.');
64+
expect(cookies).toContain('_sp_1id.');
65+
expect(cookies).toContain('_sp_2ses.');
66+
expect(cookies).toContain('_sp_2id.');
67+
expect(cookies).toContain('_sp_6ses.');
68+
expect(cookies).toContain('_sp_6id.');
69+
70+
expect($('#getDomainUserId').getText()).toMatch(/\b[0-9a-f]{8}\b-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\b[0-9a-f]{12}\b/i);
71+
expect($('#getDomainUserInfo').getText()).toMatch(/\b[0-9a-f]{8}\b-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\b[0-9a-f]{12}\b.[0-9]+.[0-9].[0-9]+.[0-9]+.\b[0-9a-f]{8}\b-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\b[0-9a-f]{12}\b/i);
72+
expect($('#getUserId').getText()).toBe('Dave');
73+
expect($('#getCookieName').getText()).toMatch(/_sp_1id.[0-9a-z]{4}/i);
74+
expect($('#getPageViewId').getText()).toMatch(/\b[0-9a-f]{8}\b-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\b[0-9a-f]{12}\b/i);
75+
})
76+
})

tests/functional/detectors.spec.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import F from 'lodash/fp'
3535
import moment from 'moment-timezone'
3636

37-
describe('Detectors test', () => {
37+
describe('Detectors', () => {
3838
beforeAll(() => {
3939
browser.url('/detectors.html')
4040
$('body.loaded').waitForExist()
@@ -55,8 +55,7 @@ describe('Detectors test', () => {
5555
})
5656

5757
it('Check localStorage availability', () => {
58-
const supportsLocalStorage = !F.isMatch( { version: '12603.3.8', browserName: 'safari' }, browser.capabilities)
59-
expect($('#localStorageAccessible').getText()).toBe(String(supportsLocalStorage))
58+
expect($('#localStorageAccessible').getText()).toBe('true')
6059
})
6160

6261
it('Check sessionStorage availability', () => {

tests/functional/helpers.spec.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@
3131
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3232
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3333
*/
34-
import F from 'lodash/fp'
3534

36-
describe('Helpers test', () => {
35+
describe('Helpers', () => {
3736
it('Gets page title', () => {
3837
browser.url('/helpers.html')
3938
$('body.loaded').waitForExist()
@@ -55,7 +54,7 @@ describe('Helpers test', () => {
5554
expect(value).toBe('previous')
5655
})
5756

58-
it('Can add an even listener', () => {
57+
it('Can add an event listener', () => {
5958
browser.url('/helpers.html')
6059
$('body.loaded').waitForExist()
6160
$('#click').click()

tests/integration/activityTracking.spec.js

Lines changed: 0 additions & 97 deletions
This file was deleted.

0 commit comments

Comments
 (0)