From 1190210957633582527b2ae3197e472ebf33881a Mon Sep 17 00:00:00 2001 From: Robert Ing Date: Wed, 15 Nov 2023 15:10:40 -0500 Subject: [PATCH] ci: Add Browserstack GIthub workflow, change legacy browsers (#798) --- .github/workflows/cross-browser-testing.yml | 40 +++++++++++++++++++ .../browserstack.karma.config.js | 37 +++++++++++++---- test/src/tests-core-sdk.js | 22 +++++----- 3 files changed, 79 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/cross-browser-testing.yml diff --git a/.github/workflows/cross-browser-testing.yml b/.github/workflows/cross-browser-testing.yml new file mode 100644 index 00000000..7c9b1150 --- /dev/null +++ b/.github/workflows/cross-browser-testing.yml @@ -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 diff --git a/test/cross-browser-testing/browserstack.karma.config.js b/test/cross-browser-testing/browserstack.karma.config.js index 79b2d3d7..556f0998 100644 --- a/test/cross-browser-testing/browserstack.karma.config.js +++ b/test/cross-browser-testing/browserstack.karma.config.js @@ -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' }, diff --git a/test/src/tests-core-sdk.js b/test/src/tests-core-sdk.js index e667fff6..5fc409dc 100644 --- a/test/src/tests-core-sdk.js +++ b/test/src/tests-core-sdk.js @@ -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) {