Skip to content

Commit 80ef0be

Browse files
Migrate consent integration tests to Playwright (#1292)
Co-authored-by: Neelkanth Kaushik <[email protected]>
1 parent edcfc0e commit 80ef0be

File tree

23 files changed

+1387
-4109
lines changed

23 files changed

+1387
-4109
lines changed

.buildkite/pipeline.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,21 @@ steps:
149149
plugins:
150150
- ssh://[email protected]/segmentio/cache-buildkite-plugin#v2.0.0:
151151
key: "v1.1-cache-dev-{{ checksum 'yarn.lock' }}"
152+
153+
- label: '[Consent] Integration Tests'
154+
agents:
155+
queue: v1
156+
commands:
157+
- npm config set "//registry.npmjs.org/:_authToken" $${NPM_TOKEN}
158+
- echo "--- Install dependencies"
159+
- HUSKY=0 yarn install --immutable
160+
- echo "--- Build + Test"
161+
- yarn turbo run --filter='./packages/consent/consent-tools-integration-tests' test:int
152162

163+
plugins:
164+
- ssh://[email protected]/segmentio/cache-buildkite-plugin#v2.0.0:
165+
key: "v1.1-cache-dev-{{ checksum 'yarn.lock' }}"
166+
153167
- label: '[Signals] Lint + Test'
154168
agents:
155169
queue: v1

.eslintrc.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
/** @type { import('eslint').Linter.Config } */
22
module.exports = {
33
root: true,
4-
ignorePatterns: ['node_modules', 'dist'],
4+
ignorePatterns: require('eslint-gitignore').readGitignoreFiles({
5+
cwd: __dirname,
6+
}),
57
parserOptions: {
68
ecmaVersion: 2020,
79
},

.github/workflows/ci.yml

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,3 @@ jobs:
5555
restore-keys: |
5656
${{ runner.os }}-turbo-
5757
- run: yarn turbo run --filter='./packages/node-integration-tests' test:cloudflare-workers
58-
consent-intg-tests:
59-
name: Consent Integration Tests
60-
runs-on: ubuntu-latest
61-
steps:
62-
- uses: actions/checkout@v3
63-
64-
- uses: browser-actions/setup-chrome@v1
65-
- uses: actions/setup-node@v3
66-
with:
67-
node-version: 16 # UPDATE TO NODE 20!!!
68-
cache: 'yarn'
69-
- run: yarn install --immutable
70-
- name: Turbo cache
71-
uses: actions/cache@v3
72-
with:
73-
path: node_modules/.cache/turbo
74-
key: ${{ runner.os }}-turbo-${{ github.sha }}
75-
restore-keys: |
76-
${{ runner.os }}-turbo-
77-
- run: yarn turbo run --filter='./packages/consent/consent-tools-integration-tests' test:int

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"concurrently": "^7.6.0",
5151
"eslint": "^8.14.0",
5252
"eslint-config-prettier": "^8.5.0",
53+
"eslint-gitignore": "^0.1.0",
5354
"eslint-plugin-import": "^2.27.5",
5455
"eslint-plugin-jest": "^27.2.2",
5556
"eslint-plugin-prettier": "^4.0.0",
Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
Why is this using wd.io instead of playwright?
2-
3-
- Webdriver.io is committed to the Webdriver Protocol, which is a community-driven spec (as opposed to Chrome Webdriver Protocol.). Playwright uses the Chrome Webdriver protocol for chrome and it's own [custom protocol](https://github.com/microsoft/playwright/issues/4862) for safari / edge.
4-
- Webdriver.io protocol allows for much better device support-- such as ie11.
5-
- Webdriver.io has native support for lighthouse and lots of other cool stuff!
1+
# @internal/consent-tools-integration-tests"
62

73
## Project structure
84
- `/public` - Test server root
@@ -18,12 +14,3 @@ Why is this using wd.io instead of playwright?
1814
```
1915
yarn . test:int
2016
```
21-
22-
### Debugging Tips:
23-
- Webdriver.io has the handy `browser.debug()` command.
24-
25-
- You can serve the static pages by themselves (without webdriver.io) with the following:
26-
```
27-
yarn webpack -w &
28-
npx live-server .
29-
```

packages/consent/consent-tools-integration-tests/package.json

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,28 @@
33
"private": true,
44
"scripts": {
55
".": "yarn run -T turbo run --filter=@internal/consent-tools-integration-tests...",
6-
"test:int": "yarn wdio:local",
6+
"test:int": "playwright test",
7+
"test:int-debug": "playwright test --debug",
78
"build": "webpack",
89
"watch": "yarn build --watch",
9-
"wdio:local": "wdio wdio.conf.local.ts",
1010
"lint": "yarn concurrently 'yarn:eslint .' 'yarn:tsc --noEmit'",
1111
"eslint": "yarn run -T eslint",
1212
"tsc": "tsc",
13-
"concurrently": "yarn run -T concurrently --raw"
13+
"concurrently": "yarn run -T concurrently --raw",
14+
"serve": "http-server --port 5432"
1415
},
1516
"installConfig": {
1617
"hoistingLimits": "workspaces"
1718
},
1819
"devDependencies": {
1920
"@internal/test-helpers": "workspace:^",
21+
"@playwright/test": "^1.28.1",
2022
"@segment/analytics-consent-tools": "workspace:^",
2123
"@segment/analytics-consent-wrapper-onetrust": "workspace:^",
2224
"@segment/analytics-next": "workspace:^",
23-
"@wdio/cli": "^8.10.6",
24-
"@wdio/devtools-service": "^8.10.6",
25-
"@wdio/local-runner": "^8.10.6",
26-
"@wdio/mocha-framework": "^8.10.6",
27-
"@wdio/spec-reporter": "^8.10.6",
28-
"@wdio/static-server-service": "^8.10.6",
29-
"@wdio/types": "8",
3025
"expect": "^29.4.1",
3126
"globby": "^11.0.2",
32-
"wdio-intercept-service": "^4.4.0",
27+
"http-server": "14.1.1",
3328
"webpack": "^5.94.0",
3429
"webpack-cli": "^4.8.0"
3530
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import type { PlaywrightTestConfig } from '@playwright/test'
2+
import { devices } from '@playwright/test'
3+
import path from 'path'
4+
5+
/**
6+
* See https://playwright.dev/docs/test-configuration.
7+
*/
8+
const config: PlaywrightTestConfig = {
9+
webServer: {
10+
command: 'yarn serve',
11+
url: 'http://127.0.0.1:5432',
12+
reuseExistingServer: !process.env.CI,
13+
},
14+
testDir: './src/tests',
15+
globalSetup: path.resolve(__dirname, 'playwright.global-setup.ts'),
16+
/* Maximum time one test can run for. */
17+
timeout: 30 * 1000,
18+
expect: {
19+
/**
20+
* Maximum time expect() should wait for the condition to be met.
21+
* For example in `await expect(locator).toHaveText();`
22+
*/
23+
timeout: 5000,
24+
},
25+
/* Run tests in files in parallel */
26+
fullyParallel: true,
27+
/* Fail the build on CI if you accidentally left test.only in the source code. */
28+
forbidOnly: !!process.env.CI,
29+
/* Retry on CI only */
30+
retries: process.env.CI ? 2 : 0,
31+
/* Opt out of parallel tests on CI. */
32+
workers: process.env.CI ? 1 : undefined,
33+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
34+
reporter: [['html', { open: 'never' }]],
35+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
36+
use: {
37+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
38+
baseURL: `http://127.0.0.1:5432`,
39+
trace: 'on',
40+
},
41+
42+
/* Configure projects for major browsers */
43+
projects: [
44+
{
45+
name: 'chromium',
46+
use: {
47+
...devices['Desktop Chrome'],
48+
},
49+
},
50+
],
51+
}
52+
53+
export default config
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import type { FullConfig } from '@playwright/test'
2+
import { execSync } from 'child_process'
3+
4+
export default function globalSetup(_cfg: FullConfig) {
5+
console.log('Executing global setup...')
6+
execSync('yarn build', { stdio: 'inherit' })
7+
console.log('Finished global setup.')
8+
}

packages/consent/consent-tools-integration-tests/public/onetrust.html renamed to packages/consent/consent-tools-integration-tests/public/consent-tools-onetrust.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
<script src="https://cdn.cookielaw.org/scripttemplates/otSDKStub.js" type="text/javascript" charset="UTF-8"
66
data-domain-script="80ca7b5c-e72f-4bd0-972a-b74d052a0820-test"></script>
77

8-
<script src="/node_modules/@segment/analytics-consent-wrapper-onetrust/dist/umd/analytics-onetrust.umd.js"></script>
9-
10-
<script>
8+
<!-- <script src="/node_modules/@segment/analytics-consent-wrapper-onetrust/dist/umd/analytics-onetrust.umd.js"></script> -->
9+
<script src="dist/onetrust.bundle.js"></script>
10+
<!-- <script>
1111
!(function () {
1212
var analytics = (window.analytics = window.analytics || [])
1313
if (!analytics.initialize)
@@ -67,7 +67,7 @@
6767
analytics.page()
6868
}
6969
})()
70-
</script>
70+
</script> -->
7171
</head>
7272

7373
<body>
@@ -76,4 +76,4 @@ <h2>Please Check Network tab</h2>
7676
<p>This page can used as playground or run by webdriver.io</p>
7777
</body>
7878

79-
</html>
79+
</html>

packages/consent/consent-tools-integration-tests/public/consent-tools-vanilla-opt-in.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<body>
55
<h1>Hello World - Serving Analytics</h1>
66
<h2>Please Check Network tab</h2>
7-
<p>This page can used as playground or run by webdriver.io</p>
8-
<script src="/public/dist/consent-tools-vanilla-opt-in.bundle.js"></script>
7+
<p>This page can used as playground or run by Playwright</p>
8+
<script src="dist/consent-tools-vanilla-opt-in.bundle.js"></script>
99
</body>
1010

1111
</html>

packages/consent/consent-tools-integration-tests/public/consent-tools-vanilla-opt-out.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<body>
55
<h1>Hello World - Serving Analytics (Consent Tools Vanilla Opt Out)</h1>
66
<h2>Please Check Network tab</h2>
7-
<p>This page can used as playground or run by webdriver.io</p>
8-
<script src="/public/dist/consent-tools-vanilla-opt-out.bundle.js"></script>
7+
<p>This page can used as playground or run by Playwright</p>
8+
<script src="dist/consent-tools-vanilla-opt-out.bundle.js"></script>
99
</body>
1010

1111
</html>

packages/consent/consent-tools-integration-tests/src/page-bundles/consent-tools-vanilla-opt-out/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const analytics = new AnalyticsBrowser()
1010

1111
withMockCMP(analytics).load(
1212
{
13-
writeKey: '9lSrez3BlfLAJ7NOChrqWtILiATiycoc',
13+
writeKey: 'foo',
1414
},
1515
{ initialPageview: true }
1616
)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { AnalyticsBrowser } from '@segment/analytics-next'
2+
import { withOneTrust } from '@segment/analytics-consent-wrapper-onetrust'
3+
4+
const analytics = new AnalyticsBrowser()
5+
6+
withOneTrust(analytics).load(
7+
{
8+
writeKey: 'foo',
9+
},
10+
{ initialPageview: true }
11+
)
12+
;(window as any).analytics = analytics

0 commit comments

Comments
 (0)