Skip to content

Commit

Permalink
ci: Add Browserstack GIthub workflow, change legacy browsers (#798)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmi22186 committed Jan 3, 2024
1 parent 31a0715 commit 1190210
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 20 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/cross-browser-testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: 'BrowserStack Test'
on: [push, pull_request, workflow_dispatch]

jobs:
ubuntu-job:
name: 'BrowserStack Test on Ubuntu'
runs-on: ubuntu-latest # Can be self-hosted runner also
steps:

- name: 'BrowserStack Env Setup' # Invokes the setup-env action
uses: browserstack/github-actions/setup-env@master
with:
username: ${{ secrets.BROWSERSTACK_USERNAME }}
access-key: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}

- name: 'BrowserStack Local Tunnel Setup' # Invokes the setup-local action
uses: browserstack/github-actions/setup-local@master
with:
local-testing: start
local-identifier: random

# The next 3 steps are for building the web application to be tested and starting the web server on the runner environment

- name: 'Checkout the repository'
uses: actions/checkout@v3

- name: 'Run NPM CI'
run: npm ci

# ensures the tests are es5 compatible
- name: 'Run NPM build:cbt'
run: npm run build:cbt

- name: 'Run Browserstack Tests'
run: npm run test:browserstack

- name: 'BrowserStackLocal Stop' # Terminating the BrowserStackLocal tunnel connection
uses: browserstack/github-actions/setup-local@master
with:
local-testing: stop
37 changes: 30 additions & 7 deletions test/cross-browser-testing/browserstack.karma.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,42 @@ if (DEBUG === 'true') {

const customLaunchers = {
// Full list of supported browsers - https://www.browserstack.com/list-of-browsers-and-platforms/live
// Fails a few tests related to setTimeout
bs_chrome_mac_48: {
// https://www.w3schools.com/js/js_versions.asp shows a list of browsers that support ES6.
// The below list is primarily the version just before that, or if that version was not available on Browserstack to test, the next version was
// All versions below, including earlier versions of each browser, have a combined ~0.37% market share according to
// www.browserslist.dev. Query for "opera < 38, safari < 12, chrome < 51, firefox <52, edge < 15"
bs_chrome_mac_50: {
base: 'BrowserStack',
browser: 'chrome',
browser_version: '48.0',
browser_version: '50.0',
os: 'OS X',
os_version: 'Mojave'
},
// Oldest Chrome version to pass all tests
bs_chrome_mac_49: {
bs_firefox_mac_51: {
base: 'BrowserStack',
browser: 'chrome',
browser_version: '49.0',
browser: 'firefox',
browser_version: '51.0',
os: 'OS X',
os_version: 'Mojave'
},
bs_edge_windows_15: {
base: 'BrowserStack',
browser: 'edge',
browser_version: '15.0',
os: 'Windows',
os_version: '10'
},
bs_safari_mac_11: {
base: 'BrowserStack',
browser: 'safari',
browser_version: '11.1',
os: 'OS X',
os_version: 'High Sierra'
},
bs_opera_mac_37: {
base: 'BrowserStack',
browser: 'opera',
browser_version: '37.0',
os: 'OS X',
os_version: 'Mojave'
},
Expand Down
22 changes: 9 additions & 13 deletions test/src/tests-core-sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,24 +100,20 @@ describe('core SDK', function() {
});

it('creates a new dateLastEventSent when logging an event, and retains the previous one when ending session', function(done) {
const clock = sinon.useFakeTimers();
mParticle.logEvent('Test Event1');
const testEvent1 = findEventFromRequest(fetchMock.calls(), 'Test Event1');
clock.tick(100);

setTimeout(function() {
mParticle.logEvent('Test Event2');
const testEvent2 = findEventFromRequest(fetchMock.calls(), 'Test Event2');

mParticle.endSession();
const sessionEndEvent = findEventFromRequest(fetchMock.calls(), 'session_end');

const result1 = testEvent1.data.timestamp_unixtime_ms === testEvent2.data.timestamp_unixtime_ms;
const result2 = testEvent2.data.timestamp_unixtime_ms === sessionEndEvent.data.timestamp_unixtime_ms;
mParticle.logEvent('Test Event2');
const testEvent2 = findEventFromRequest(fetchMock.calls(), 'Test Event2');

Should(result1).not.be.ok();
Should(result2).be.ok();
mParticle.endSession();
const sessionEndEvent = findEventFromRequest(fetchMock.calls(), 'session_end');
Should(testEvent1.data.timestamp_unixtime_ms).not.equal(testEvent2.data.timestamp_unixtime_ms);
Should(testEvent2.data.timestamp_unixtime_ms).equal(sessionEndEvent.data.timestamp_unixtime_ms);

done();
}, 5);
done();
});

it('should process ready queue when initialized', function(done) {
Expand Down

0 comments on commit 1190210

Please sign in to comment.