Skip to content

Commit b7e38d2

Browse files
committed
feat: add Chrome 113 browser E2E testing
1 parent f69f3c6 commit b7e38d2

13 files changed

+322
-125
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ coverage
6060
/libpeerconnection.log
6161
testem.log
6262
/typings
63+
packages/kit-headless/browsers/chrome/*
6364

6465
# System Files
6566
.DS_Store
@@ -74,4 +75,4 @@ Thumbs.db
7475

7576
# Verdaccio
7677
tmp
77-
.nx/cache
78+
.nx/cache

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"test.headless": "nx component-test headless",
3636
"test.visual.headless": "nx visual-test headless",
3737
"test.pw.headless": "nx e2e headless",
38+
"test.pw.headless-chrome-113": "nx e2e-chrome-113 headless",
3839
"test.pw.headless.ci": "nx e2e headless",
3940
"test.headless.ci": "nx component-test-ci headless",
4041
"test.utils": "nx test utils"
@@ -89,6 +90,7 @@
8990
"@swc-node/register": "~1.6.7",
9091
"@swc/core": "~1.3.85",
9192
"@testing-library/cypress": "9.0.0",
93+
"@types/decompress": "4.2.7",
9294
"@types/eslint": "^8.44.2",
9395
"@types/estree-jsx": "^1.0.3",
9496
"@types/jest": "^29.4.0",
@@ -117,6 +119,7 @@
117119
"cypress-real-events": "1.10.3",
118120
"cz-conventional-changelog": "^3.3.0",
119121
"danger": "^11.2.8",
122+
"decompress": "4.2.1",
120123
"dotenv": "16.3.1",
121124
"eslint": "^8.48.0",
122125
"eslint-config-prettier": "9.0.0",

packages/kit-headless/package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
"module": "./index.qwik.mjs",
1111
"types": "./index.d.ts",
1212
"type": "module",
13+
"scripts": {
14+
"setup.chrome.113": "npx tsx ./scripts/prepare-chrome-113.ts"
15+
},
1316
"exports": {
1417
".": {
1518
"types": "./index.d.ts",
@@ -24,5 +27,7 @@
2427
"peerDependencies": {
2528
"@builder.io/qwik": "^1.4.0"
2629
},
27-
"scripts": {}
30+
"devDependencies": {
31+
"tsx": "4.7.2"
32+
}
2833
}

packages/kit-headless/playwright.config.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,34 @@
11
import { workspaceRoot } from '@nx/devkit';
22
import { nxE2EPreset } from '@nx/playwright/preset';
33
import { defineConfig, devices } from '@playwright/test';
4+
import path, { dirname } from 'path';
45
import { fileURLToPath } from 'url';
6+
import os from 'os';
57

68
const __filename = fileURLToPath(import.meta.url);
79
// For CI, you may want to set BASE_URL to the deployed application.
810
const baseURL = process.env['BASE_URL'] || 'http://localhost:5173';
911

12+
const dirName = dirname(__filename);
13+
14+
const currentPlatform = os.platform();
15+
16+
let binaryPath;
17+
18+
switch (currentPlatform) {
19+
case 'darwin':
20+
binaryPath = './browsers/chrome/113/chrome-darwin/Chromium.app';
21+
break;
22+
case 'win32':
23+
binaryPath = './browsers/chrome/113/chrome-win32/chrome.exe';
24+
break;
25+
case 'linux':
26+
binaryPath = './browsers/chrome/113/chrome-linux/chrome';
27+
break;
28+
default:
29+
throw new Error('Cannot install Chrome 13 on unknown platform');
30+
}
31+
1032
/**
1133
* Read environment variables from file.
1234
* https://github.com/motdotla/dotenv
@@ -41,6 +63,16 @@ export default defineConfig({
4163
grepInvert: /@Visual.*/,
4264
},
4365

66+
{
67+
name: 'popover-chrome-113',
68+
use: {
69+
launchOptions: {
70+
executablePath: path.resolve(dirName, binaryPath),
71+
},
72+
},
73+
grep: /popover/,
74+
},
75+
4476
{
4577
name: 'visual',
4678
use: { ...devices['Desktop Chrome'] },

packages/kit-headless/project.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,21 @@
8888
"project": ["logic"]
8989
}
9090
},
91+
"setup-chrome-113": {
92+
"executor": "nx:run-script",
93+
"options": {
94+
"script": "setup.chrome.113"
95+
}
96+
},
97+
"e2e-chrome-113": {
98+
"executor": "@nx/playwright:playwright",
99+
"outputs": ["{workspaceRoot}/dist/.playwright/packages/kit-headless"],
100+
"dependsOn": ["setup-chrome-113"],
101+
"options": {
102+
"config": "packages/kit-headless/playwright.config.ts",
103+
"project": ["popover-chrome-113"]
104+
}
105+
},
91106
"visual-test": {
92107
"executor": "@nx/playwright:playwright",
93108
"outputs": ["{workspaceRoot}/dist/.playwright/packages/kit-headless"],
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import os from 'os';
2+
import decompress from 'decompress';
3+
import fs from 'fs';
4+
5+
let progressValue = 0;
6+
7+
function printProgress(progress: number) {
8+
if (progress % 5 === 0 && progressValue !== progress) {
9+
console.log(`Download ${progress}% complete ⏬`);
10+
progressValue = progress;
11+
}
12+
}
13+
14+
async function prepareChrome113() {
15+
const path = `browsers/chrome/113/chrome-${os.platform()}`;
16+
17+
if (fs.existsSync(path)) {
18+
console.log('Chrome 113 already exists. Skipping unzip ⏩');
19+
} else {
20+
console.log('Creating directory to save the browser 🌐');
21+
fs.mkdirSync(path, { recursive: true });
22+
23+
const downloadResponse = await fetch(
24+
`https://github.com/qwikifiers/qwik-ui-polyfill-browsers/raw/main/chrome/113/chrome-${os.platform()}.zip`,
25+
);
26+
27+
const contentLength = downloadResponse.headers.get('content-length');
28+
const total = parseInt(contentLength ?? '0', 10);
29+
let loaded = 0;
30+
31+
const res = new Response(
32+
new ReadableStream({
33+
async start(controller) {
34+
if (!downloadResponse.body) {
35+
throw new Error(
36+
'Invalid response received when trying to download Chrome 113',
37+
);
38+
}
39+
40+
const reader = downloadResponse.body.getReader();
41+
for (;;) {
42+
const { done, value } = await reader.read();
43+
if (done) break;
44+
loaded += value.byteLength;
45+
printProgress(Math.round((loaded / total) * 100));
46+
47+
controller.enqueue(value);
48+
}
49+
controller.close();
50+
},
51+
}),
52+
);
53+
54+
await decompress(
55+
Buffer.from(await res.arrayBuffer()),
56+
`browsers/chrome/113/chrome-${os.platform()}`,
57+
{ strip: 1 },
58+
);
59+
}
60+
}
61+
62+
await prepareChrome113();
Loading
Loading
6.2 KB
Loading
6.2 KB
Loading

0 commit comments

Comments
 (0)