Skip to content

Commit 1a91012

Browse files
authored
Merge pull request GoogleChromeLabs#7 from f3bot/e2e-tests
Feature: Add End-To-End testing showcase
2 parents 422c94b + 2f43834 commit 1a91012

File tree

10 files changed

+11350
-1864
lines changed

10 files changed

+11350
-1864
lines changed

vite-iwa-template/jest.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/** @type {import('ts-jest').JestConfigWithTsJest} */
2+
export default {
3+
preset: "ts-jest",
4+
testEnvironment: "node",
5+
};

vite-iwa-template/package-lock.json

Lines changed: 5114 additions & 255 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vite-iwa-template/package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,23 @@
88
"dev": "vite",
99
"build": "tsc && vite build",
1010
"preview": "vite preview",
11-
"prettier": "prettier -w ."
11+
"prettier": "prettier -w .",
12+
"test": "tsc && jest"
1213
},
1314
"devDependencies": {
15+
"@puppeteer/browsers": "^2.10.10",
16+
"@types/jest": "^30.0.0",
1417
"@types/trusted-types": "^2.0.7",
1518
"dompurify": "^3.2.6",
1619
"dotenv": "^17.2.0",
20+
"jest": "^30.2.0",
1721
"prettier": "^3.6.2",
22+
"puppeteer-core": "^24.22.3",
1823
"rollup-plugin-webbundle": "^0.2.0",
24+
"ts-jest": "^29.4.4",
1925
"typescript": "~5.8.3",
2026
"vite": "^7.0.4",
2127
"vite-plugin-html-inject": "^1.1.2",
22-
"wbn-sign": "^0.2.1"
28+
"wbn-sign": "^0.2.4"
2329
}
2430
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import * as puppeteer from "puppeteer-core";
2+
import * as path from "path";
3+
import * as wbnSign from "wbn-sign";
4+
import * as fs from "fs";
5+
6+
/*
7+
If you want to debug E2E tests, you will need to create a custom debug launch configuration
8+
https://code.visualstudio.com/docs/debugtest/debugging-configuration
9+
10+
Alternatively, you can use a test runner extension.
11+
https://marketplace.visualstudio.com/items?itemName=firsttris.vscode-jest-runner
12+
*/
13+
describe("E2E Tests", () => {
14+
let browser: puppeteer.Browser;
15+
let session: puppeteer.CDPSession;
16+
let manifestID: string;
17+
18+
const bundlePath = path.join(process.cwd(), "dist", "iwa-template.swbn");
19+
test("IWA Should be installed and launched correctly", async () => {
20+
const bundleContent = new Uint8Array(await fs.promises.readFile(bundlePath));
21+
manifestID = wbnSign.getBundleId(bundleContent);
22+
23+
browser = await puppeteer.launch({
24+
executablePath: puppeteer.executablePath("chrome"),
25+
headless: false,
26+
pipe: true,
27+
args: ["--enable-features=IsolatedWebApps,IsolatedWebAppDevMode"],
28+
});
29+
30+
session = await browser.target().createCDPSession();
31+
32+
await session.send("PWA.install", {
33+
manifestId: `isolated-app://${manifestID}`,
34+
installUrlOrBundleUrl: `file://${bundlePath}`,
35+
});
36+
37+
await session.send("PWA.launch", {
38+
manifestId: `isolated-app://${manifestID}`,
39+
});
40+
41+
await browser.close();
42+
}, 300000);
43+
});

vite-iwa-template/tsconfig.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"types": ["trusted-types"],
3+
"types": ["trusted-types", "jest"],
44
"target": "ES2022",
55
"useDefineForClassFields": true,
66
"module": "ESNext",
@@ -10,7 +10,6 @@
1010
/* Bundler mode */
1111
"moduleResolution": "bundler",
1212
"allowImportingTsExtensions": true,
13-
"verbatimModuleSyntax": true,
1413
"moduleDetection": "force",
1514
"noEmit": true,
1615

@@ -22,5 +21,5 @@
2221
"noFallthroughCasesInSwitch": true,
2322
"noUncheckedSideEffectImports": true
2423
},
25-
"include": ["src"]
24+
"include": ["src", "tests"]
2625
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/** @type {import('ts-jest').JestConfigWithTsJest} */
2+
export default {
3+
preset: "ts-jest",
4+
testEnvironment: "node",
5+
};

0 commit comments

Comments
 (0)