From bb3c2e05ef78c418f1d3a8504b2fb5d2d23e1fbc Mon Sep 17 00:00:00 2001 From: Robert Ing Date: Tue, 3 Oct 2023 15:05:14 -0400 Subject: [PATCH] ci: POC - Add BrowserStack config files (#783) --- .gitignore | 3 +- package.json | 3 + .../browserstack/browserstack.karma.config.js | 74 +++++++++++++++++++ .../test-cross-browser.js | 8 ++ test/src/tests-main.js | 53 ++++++------- 5 files changed, 114 insertions(+), 27 deletions(-) create mode 100644 test/cross-browser-testing/browserstack/browserstack.karma.config.js create mode 100644 test/cross-browser-testing/test-cross-browser.js diff --git a/.gitignore b/.gitignore index b963d12a..873992c2 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ out/ test/reports test/test-bundle.js.map test/stub/test-stub-bundle.js -**/dist \ No newline at end of file +**/dist +test/cross-browser-testing/browserstack/reports \ No newline at end of file diff --git a/package.json b/package.json index 6b914197..8bc337e7 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,8 @@ "build:webpack:module": "webpack --config test/integrations/module/webpack/webpack.config.js", "build:ts": "tsc -p .", "test": "npm run build && npm run build:test-bundle && cross-env DEBUG=false karma start test/karma.config.js", + "test:browserstack": "karma start test/cross-browser-testing/browserstack/browserstack.karma.config.js", + "test:browserstack:debug": "cross-env DEBUG=true karma start test/cross-browser-testing/browserstack/browserstack.karma.config.js", "test:debug": "cross-env DEBUG=true karma start test/karma.config.js", "test:stub": "cross-env TESTTYPE=stub ENVIRONMENT=prod rollup --config rollup.test.config.js && karma start test/stub/karma.stub.config.js", "test:integrations": "npm run test:requirejs && npm run test:integrations:cjs && npm run test:integrations:module", @@ -110,6 +112,7 @@ "jest": "^29.5.0", "jest-environment-jsdom": "^29.5.0", "karma": "^6.3.2", + "karma-browserstack-launcher": "^1.6.0", "karma-chai": "^0.1.0", "karma-chrome-launcher": "^3.1.0", "karma-edge-launcher": "^0.4.1", diff --git a/test/cross-browser-testing/browserstack/browserstack.karma.config.js b/test/cross-browser-testing/browserstack/browserstack.karma.config.js new file mode 100644 index 00000000..cbd31019 --- /dev/null +++ b/test/cross-browser-testing/browserstack/browserstack.karma.config.js @@ -0,0 +1,74 @@ +const { DEBUG } = process.env; + +const files = [ + '../../lib/mockhttprequest.js', + '../../lib/geomock.js', + '../../../node_modules/fetch-mock/dist/es5/client-bundle.js', + '../../../node_modules/sinon-browser-only/sinon.js', + '../../config.js', + '../../../dist/mparticle.js', + '../../test-bundle.js' +]; + +const singleRun = true; + +let captureConsole = false; +let browserConsoleLogOptions = {}; + +// Allows console logs to appear when doing npm run test:debug +if (DEBUG === 'true') { + browserConsoleLogOptions = { + level: 'log', + format: '%b %T: %m', + terminal: true, + }; + captureConsole = true; +} else { + browserConsoleLogOptions = { + terminal: false, + }; +} + +module.exports = function(config) { + config.set({ + browserStack: { + username: process.env.BS_USERNAME, + accessKey: process.env.BS_ACCESS_KEY + }, + // define browsers + customLaunchers: { + // Firefox 21 fails non-es6 tests + bs_firefox_mac_21: { + base: 'BrowserStack', + browser: 'firefox', + browser_version: '21.0', + os: 'OS X', + os_version: 'Snow Leopard' + }, + bs_firefox_mac_100: { + base: 'BrowserStack', + browser: 'firefox', + browser_version: '100.0', + os: 'OS X', + os_version: 'Ventura' + } + }, + browsers: ['bs_firefox_mac_21', 'bs_firefox_mac_100'], + frameworks: ['mocha', 'should'], + files, + reporters: ['progress', 'junit'], + colors: true, + concurrency: Infinity, + singleRun, + debug: true, + logLevel: config.LOG_INFO, + browserConsoleLogOptions, + client: { + captureConsole, + }, + junitReporter: { + outputDir: 'reports/', + outputFile: 'test-karma.xml', + }, + }); +}; diff --git a/test/cross-browser-testing/test-cross-browser.js b/test/cross-browser-testing/test-cross-browser.js new file mode 100644 index 00000000..42a67425 --- /dev/null +++ b/test/cross-browser-testing/test-cross-browser.js @@ -0,0 +1,8 @@ +describe('test browserstack integration', function() { + it('should pass', function() { + true.should.equal(true); + }); + it('should not pass on older browsers', function() { + 'foo-bar'.replaceAll('o', 0).should.equal('f00-bar'); + }); +}); \ No newline at end of file diff --git a/test/src/tests-main.js b/test/src/tests-main.js index 55977bc8..7335cacf 100644 --- a/test/src/tests-main.js +++ b/test/src/tests-main.js @@ -31,30 +31,31 @@ afterEach(function() { window.fetchMock.restore(); }); +import '../cross-browser-testing/test-cross-browser'; import './tests-core-sdk'; -import './tests-batchUploader'; -import './tests-beaconUpload'; -import './tests-kit-blocking'; -import './tests-persistence'; -import './tests-forwarders'; -import './tests-helpers'; -import './tests-identity'; -import './tests-event-logging'; -import './tests-eCommerce'; -import './tests-cookie-syncing'; -import './tests-identities-attributes'; -import './tests-native-sdk'; -import './tests-consent'; -import './tests-serverModel'; -import './tests-mockBatchCreator.ts'; -import './tests-mParticleUser'; -import './tests-self-hosting-specific'; -import './tests-runtimeToBatchEventsDTO'; -import './tests-apiClient'; -import './tests-mparticle-instance-manager'; -import './tests-queue-public-methods'; -import './tests-validators'; -import './tests-utils'; -import './tests-session-manager'; -import './tests-store'; -import './tests-config-api-client'; +// import './tests-batchUploader'; +// import './tests-beaconUpload'; +// import './tests-kit-blocking'; +// import './tests-persistence'; +// import './tests-forwarders'; +// import './tests-helpers'; +// import './tests-identity'; +// import './tests-event-logging'; +// import './tests-eCommerce'; +// import './tests-cookie-syncing'; +// import './tests-identities-attributes'; +// import './tests-native-sdk'; +// import './tests-consent'; +// import './tests-serverModel'; +// import './tests-mockBatchCreator.ts'; +// import './tests-mParticleUser'; +// import './tests-self-hosting-specific'; +// import './tests-runtimeToBatchEventsDTO'; +// import './tests-apiClient'; +// import './tests-mparticle-instance-manager'; +// import './tests-queue-public-methods'; +// import './tests-validators'; +// import './tests-utils'; +// import './tests-session-manager'; +// import './tests-store'; +// import './tests-config-api-client';