diff --git a/packages/consent/consent-tools-integration-tests/README.md b/packages/consent/consent-tools-integration-tests/README.md index 17d448633..9c31b5125 100644 --- a/packages/consent/consent-tools-integration-tests/README.md +++ b/packages/consent/consent-tools-integration-tests/README.md @@ -9,7 +9,7 @@ Why is this using wd.io instead of playwright? - `/dist` - Holds the webpacked page-bundles that will be injected into each html page - `/src` - Test suite files - - `/page-bundles` - JS that will be injected into the test page (this will be built by webpack -> public/dist) + - `/page-bundles` - For testing libraries that don't have a UMD bundle (i.e analytics-consent-tools) - `/page-objects` - Page objects for the test suite - `/page-tests ` - Tests that will be run on the page diff --git a/packages/consent/consent-tools-integration-tests/package.json b/packages/consent/consent-tools-integration-tests/package.json index 10bf68e2e..d67ff3cd8 100644 --- a/packages/consent/consent-tools-integration-tests/package.json +++ b/packages/consent/consent-tools-integration-tests/package.json @@ -7,12 +7,15 @@ "build": "webpack", "watch": "yarn build --watch", "test:local": "wdio wdio.conf.local.ts", - "start-server-and-test": "yarn concurrently -k 'yarn build serve' 'sleep 5 && yarn test:local'", + "start-server-and-test": "yarn build && yarn test:local", "lint": "yarn concurrently 'yarn:eslint .' 'yarn:tsc --noEmit'", "eslint": "yarn run -T eslint", "tsc": "tsc", "concurrently": "yarn run -T concurrently --raw" }, + "installConfig": { + "hoistingLimits": "workspaces" + }, "devDependencies": { "@segment/analytics-consent-tools": "workspace:^", "@segment/analytics-consent-wrapper-onetrust": "workspace:^", @@ -21,6 +24,7 @@ "@wdio/local-runner": "^8.10.6", "@wdio/mocha-framework": "^8.10.6", "@wdio/spec-reporter": "^8.10.6", + "@wdio/static-server-service": "^8.10.6", "@wdio/types": "8", "expect": "^29.4.1", "globby": "^11.0.2", diff --git a/packages/consent/consent-tools-integration-tests/public/basic.html b/packages/consent/consent-tools-integration-tests/public/consent-tools-vanilla.html similarity index 77% rename from packages/consent/consent-tools-integration-tests/public/basic.html rename to packages/consent/consent-tools-integration-tests/public/consent-tools-vanilla.html index 92f865a97..b7ba6dcc3 100644 --- a/packages/consent/consent-tools-integration-tests/public/basic.html +++ b/packages/consent/consent-tools-integration-tests/public/consent-tools-vanilla.html @@ -2,7 +2,7 @@ - + diff --git a/packages/consent/consent-tools-integration-tests/public/onetrust.html b/packages/consent/consent-tools-integration-tests/public/onetrust.html index 2c812bebb..c35a261e6 100644 --- a/packages/consent/consent-tools-integration-tests/public/onetrust.html +++ b/packages/consent/consent-tools-integration-tests/public/onetrust.html @@ -13,8 +13,72 @@ } }) - + + diff --git a/packages/consent/consent-tools-integration-tests/public/snippet.html b/packages/consent/consent-tools-integration-tests/public/snippet.html deleted file mode 100644 index 3b0cea644..000000000 --- a/packages/consent/consent-tools-integration-tests/public/snippet.html +++ /dev/null @@ -1,89 +0,0 @@ - - - - - - - - - - - - -

Hello World - Serving Analytics (from snippet)

-

Please open devtools

-

Note: analytics.load() has been deleted from the snippet, since that initialization will be handled only by the consent wrapper.

-

This page can used as playground or run by webdriver.io

- - - - diff --git a/packages/consent/consent-tools-integration-tests/src/page-bundles/basic/index.ts b/packages/consent/consent-tools-integration-tests/src/page-bundles/consent-tools-vanilla/index.ts similarity index 100% rename from packages/consent/consent-tools-integration-tests/src/page-bundles/basic/index.ts rename to packages/consent/consent-tools-integration-tests/src/page-bundles/consent-tools-vanilla/index.ts diff --git a/packages/consent/consent-tools-integration-tests/src/page-bundles/onetrust/index.ts b/packages/consent/consent-tools-integration-tests/src/page-bundles/onetrust/index.ts deleted file mode 100644 index 04c7f2ce2..000000000 --- a/packages/consent/consent-tools-integration-tests/src/page-bundles/onetrust/index.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { AnalyticsBrowser } from '@segment/analytics-next' -import { withOneTrust } from '@segment/analytics-consent-wrapper-onetrust' - -export const analytics = new AnalyticsBrowser() - -withOneTrust(analytics, { - disableConsentChangedEvent: false, - integrationCategoryMappings: { - Fullstory: ['C0001'], - 'Actions Amplitude': ['C0004'], - }, -}).load({ writeKey: '9lSrez3BlfLAJ7NOChrqWtILiATiycoc' }) -;(window as any).analytics = analytics -void window.analytics.page().then(console.log) diff --git a/packages/consent/consent-tools-integration-tests/src/page-bundles/snippet/index.ts b/packages/consent/consent-tools-integration-tests/src/page-bundles/snippet/index.ts deleted file mode 100644 index 89b0648f7..000000000 --- a/packages/consent/consent-tools-integration-tests/src/page-bundles/snippet/index.ts +++ /dev/null @@ -1,12 +0,0 @@ -/* eslint-disable @typescript-eslint/no-floating-promises */ -import { withOneTrust } from '@segment/analytics-consent-wrapper-onetrust' - -withOneTrust(window.analytics, { - integrationCategoryMappings: { - Fullstory: ['C0001'], - 'Actions Amplitude': ['C0004'], - }, -}) - -window.analytics.load('9lSrez3BlfLAJ7NOChrqWtILiATiycoc') -window.analytics.track('Hello from the snippet') diff --git a/packages/consent/consent-tools-integration-tests/src/page-objects/basic.ts b/packages/consent/consent-tools-integration-tests/src/page-objects/basic.ts deleted file mode 100644 index 80bf69c58..000000000 --- a/packages/consent/consent-tools-integration-tests/src/page-objects/basic.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { BasePage } from './base-page' - -class BasicPage extends BasePage { - constructor() { - super('basic.html') - } -} - -export default new BasicPage() diff --git a/packages/consent/consent-tools-integration-tests/src/page-objects/consent-tools-vanilla.ts b/packages/consent/consent-tools-integration-tests/src/page-objects/consent-tools-vanilla.ts new file mode 100644 index 000000000..c90a14700 --- /dev/null +++ b/packages/consent/consent-tools-integration-tests/src/page-objects/consent-tools-vanilla.ts @@ -0,0 +1,9 @@ +import { BasePage } from './base-page' + +class ConsentToolsVanilla extends BasePage { + constructor() { + super('consent-tools-vanilla.html') + } +} + +export default new ConsentToolsVanilla() diff --git a/packages/consent/consent-tools-integration-tests/src/tests/consent-stamping.test.ts b/packages/consent/consent-tools-integration-tests/src/tests/consent-tools-vanilla.test.ts similarity index 80% rename from packages/consent/consent-tools-integration-tests/src/tests/consent-stamping.test.ts rename to packages/consent/consent-tools-integration-tests/src/tests/consent-tools-vanilla.test.ts index b2e59929c..5fe348f8d 100644 --- a/packages/consent/consent-tools-integration-tests/src/tests/consent-stamping.test.ts +++ b/packages/consent/consent-tools-integration-tests/src/tests/consent-tools-vanilla.test.ts @@ -1,7 +1,9 @@ -import page from '../page-objects/basic' +import page from '../page-objects/consent-tools-vanilla' import { expect } from 'expect' import { Context } from '@segment/analytics-next' +// Verify that the consent tools wrapper is working as expected (no OneTrust) + it('should stamp each event', async () => { await page.load() @@ -13,6 +15,7 @@ it('should stamp each event', async () => { `analytics.identify("bar", { bar: 123 })`, ] + await browser.pause(1000) const responses = await Promise.all( commands.map((cmd) => browser.execute(cmd)) ) diff --git a/packages/consent/consent-tools-integration-tests/src/tests/onetrust.test.ts b/packages/consent/consent-tools-integration-tests/src/tests/onetrust.test.ts index 746b5dd4a..40b73aa76 100644 --- a/packages/consent/consent-tools-integration-tests/src/tests/onetrust.test.ts +++ b/packages/consent/consent-tools-integration-tests/src/tests/onetrust.test.ts @@ -1,7 +1,8 @@ +// Verify that @segment/analytics-consent-wrapper-onetrust is working as expected + /* eslint-disable @typescript-eslint/no-floating-promises */ import page from '../page-objects/onetrust' import { expect } from 'expect' -import { Context } from '@segment/analytics-next' declare global { interface Window { @@ -13,28 +14,6 @@ afterEach(async () => { await page.clearStorage() }) -it('should stamp each event', async () => { - await page.load() - const commands = [ - `analytics.track("hello world")`, - `analytics.alias("foo", "bar")`, - `analytics.page()`, - `analytics.group("foo", { bar: 123 })`, - `analytics.identify("bar", { bar: 123 })`, - ] - - const eventsP = Promise.all( - commands.map((cmd) => browser.execute(cmd)) - ) - - await page.clickAcceptButtonAndClosePopup() - ;(await eventsP).forEach((ctx) => { - expect( - Object.keys((ctx.event.context as any).consent.categoryPreferences).length - ).toBeGreaterThan(0) - }) -}) - it('should send a consent changed event when user clicks accept on popup', async () => { await page.load() diff --git a/packages/consent/consent-tools-integration-tests/wdio.conf.local.ts b/packages/consent/consent-tools-integration-tests/wdio.conf.local.ts index e9b46d89c..3f7bc0844 100644 --- a/packages/consent/consent-tools-integration-tests/wdio.conf.local.ts +++ b/packages/consent/consent-tools-integration-tests/wdio.conf.local.ts @@ -1,5 +1,7 @@ import type { Options } from '@wdio/types' +const PORT = 4567 + export const config: Options.Testrunner = { afterTest(test, _, { error, passed }) { console.log( @@ -10,7 +12,25 @@ export const config: Options.Testrunner = { ].join('\n') ) }, - services: ['intercept'], + services: [ + 'intercept', + [ + 'static-server', + { + port: PORT, + folders: [ + { + mount: '/', + path: './public', + }, + { + mount: '/@segment', + path: './node_modules/@segment', + }, + ], + }, + ], + ], // services: [ /* Using webpack-dev-server instead */ // [ // 'static-server', @@ -25,7 +45,7 @@ export const config: Options.Testrunner = { // }, // ], // ], - baseUrl: 'http://localhost:9000', + baseUrl: `http://localhost:${PORT}`, // WebdriverIO allows it to run your tests in arbitrary locations (e.g. locally or // on a remote machine). runner: 'local', diff --git a/packages/consent/consent-tools-integration-tests/webpack.config.ts b/packages/consent/consent-tools-integration-tests/webpack.config.ts index ac652ec9e..a00a02946 100644 --- a/packages/consent/consent-tools-integration-tests/webpack.config.ts +++ b/packages/consent/consent-tools-integration-tests/webpack.config.ts @@ -2,9 +2,6 @@ import path from 'path' import globby from 'globby' import type { Configuration as WebpackConfiguration } from 'webpack' -// in case you run into any typescript error when configuring `devServer` -import 'webpack-dev-server' - // This config is for bundling fixtures in order to serve the pages that webdriver.io will use in its tests. const files = globby.sync('src/page-bundles/*/index.ts', { cwd: __dirname }) @@ -18,12 +15,6 @@ const entries = files.reduce((acc, file) => { }, {}) const config: WebpackConfiguration = { - devServer: { - static: { - directory: path.join(__dirname, 'public'), - }, - port: 9000, - }, mode: 'development', devtool: 'source-map', entry: entries, diff --git a/yarn.lock b/yarn.lock index 087d4e0a1..d24e9f27b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2366,6 +2366,7 @@ __metadata: "@wdio/local-runner": ^8.10.6 "@wdio/mocha-framework": ^8.10.6 "@wdio/spec-reporter": ^8.10.6 + "@wdio/static-server-service": ^8.10.6 "@wdio/types": 8 expect: ^29.4.1 globby: ^11.0.2 @@ -5802,6 +5803,18 @@ __metadata: languageName: node linkType: hard +"@wdio/static-server-service@npm:^8.10.6": + version: 8.16.3 + resolution: "@wdio/static-server-service@npm:8.16.3" + dependencies: + "@wdio/logger": 8.11.0 + "@wdio/types": 8.16.3 + express: ^4.14.0 + morgan: ^1.7.0 + checksum: dbb65d22da719f9aea1c761c1744ff0cde68d74f32edb3c91fba8a57f2df8ee78c59cc3944c11c5c25e7349754d2566ff12bb7ede67f8e59057bb8c5a2b6d7c8 + languageName: node + linkType: hard + "@wdio/types@npm:8, @wdio/types@npm:8.10.4": version: 8.10.4 resolution: "@wdio/types@npm:8.10.4" @@ -5811,6 +5824,15 @@ __metadata: languageName: node linkType: hard +"@wdio/types@npm:8.16.3": + version: 8.16.3 + resolution: "@wdio/types@npm:8.16.3" + dependencies: + "@types/node": ^20.1.0 + checksum: c50be3244a80f24f905a16b58e1f2f45d8d00ba4304459386e0c00b3ee852e5a2ddcd0e2fffe35d38a4aa4bd33c65bae3f129203f69d343baa9a7c2b2a096381 + languageName: node + linkType: hard + "@wdio/utils@npm:8.11.0": version: 8.11.0 resolution: "@wdio/utils@npm:8.11.0" @@ -7168,7 +7190,7 @@ __metadata: languageName: node linkType: hard -"basic-auth@npm:^2.0.1": +"basic-auth@npm:^2.0.1, basic-auth@npm:~2.0.1": version: 2.0.1 resolution: "basic-auth@npm:2.0.1" dependencies: @@ -8718,7 +8740,7 @@ __metadata: languageName: node linkType: hard -"depd@npm:2.0.0": +"depd@npm:2.0.0, depd@npm:~2.0.0": version: 2.0.0 resolution: "depd@npm:2.0.0" checksum: abbe19c768c97ee2eed6282d8ce3031126662252c58d711f646921c9623f9052e3e1906443066beec1095832f534e57c523b7333f8e7e0d93051ab6baef5ab3a @@ -10130,7 +10152,7 @@ __metadata: languageName: node linkType: hard -"express@npm:^4.17.3, express@npm:^4.18.2": +"express@npm:^4.14.0, express@npm:^4.17.3, express@npm:^4.18.2": version: 4.18.2 resolution: "express@npm:4.18.2" dependencies: @@ -14257,6 +14279,19 @@ __metadata: languageName: node linkType: hard +"morgan@npm:^1.7.0": + version: 1.10.0 + resolution: "morgan@npm:1.10.0" + dependencies: + basic-auth: ~2.0.1 + debug: 2.6.9 + depd: ~2.0.0 + on-finished: ~2.3.0 + on-headers: ~1.0.2 + checksum: fb41e226ab5a1abf7e8909e486b387076534716d60207e361acfb5df78b84d703a7b7ea58f3046a9fd0b83d3c94bfabde32323341a1f1b26ce50680abd2ea5dd + languageName: node + linkType: hard + "ms@npm:2.0.0": version: 2.0.0 resolution: "ms@npm:2.0.0" @@ -14749,6 +14784,15 @@ __metadata: languageName: node linkType: hard +"on-finished@npm:~2.3.0": + version: 2.3.0 + resolution: "on-finished@npm:2.3.0" + dependencies: + ee-first: 1.1.1 + checksum: 1db595bd963b0124d6fa261d18320422407b8f01dc65863840f3ddaaf7bcad5b28ff6847286703ca53f4ec19595bd67a2f1253db79fc4094911ec6aa8df1671b + languageName: node + linkType: hard + "on-headers@npm:~1.0.2": version: 1.0.2 resolution: "on-headers@npm:1.0.2"