Skip to content

Commit a541df9

Browse files
authored
Init Playwright Tests (#81)
This PR inits the setup for Playwright tests and adds tests that cover the most important functionality of the app.
1 parent 217ad06 commit a541df9

28 files changed

Lines changed: 1693 additions & 31 deletions

.config/vite.config.js

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,36 @@
11
import { defineConfig } from "vite";
22
import fs from "fs";
3+
import process from "node:process";
34

45
const input = {
56
main: "web/index.html",
67
privacy: "web/privacy.html",
78
powerpoint: "web/powerpoint.html",
89
};
910

10-
export default defineConfig(({ command }) => ({
11-
root: "web",
12-
base: "/pptypst/",
13-
build: {
14-
outDir: "../build/",
15-
emptyOutDir: true,
16-
rollupOptions: {
17-
input,
18-
},
19-
},
20-
server: {
21-
port: 3155,
22-
...(command === "serve" && {
23-
https: {
24-
key: fs.readFileSync("web/certs/localhost.key"),
25-
cert: fs.readFileSync("web/certs/localhost.crt"),
11+
function serverHttpsConfig() {
12+
return {
13+
key: fs.readFileSync("web/certs/localhost.key"),
14+
cert: fs.readFileSync("web/certs/localhost.crt"),
15+
};
16+
}
17+
18+
export default defineConfig(({ command }) => {
19+
const useHttps = command === "serve" && process.env.PPTYPST_USE_HTTPS !== "false";
20+
21+
return {
22+
root: "web",
23+
base: "/pptypst/",
24+
build: {
25+
outDir: "../build/",
26+
emptyOutDir: true,
27+
rollupOptions: {
28+
input,
2629
},
27-
}),
28-
},
29-
}));
30+
},
31+
server: {
32+
port: 3155,
33+
...(useHttps && { https: serverHttpsConfig() }),
34+
},
35+
};
36+
});

.github/workflows/test.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Playwright Tests
2+
3+
on:
4+
push:
5+
branches: [ main, next ]
6+
pull_request:
7+
branches: [ main, next ]
8+
9+
jobs:
10+
test:
11+
environment: testing-review
12+
timeout-minutes: 10
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v6
17+
with:
18+
persist-credentials: false
19+
20+
- uses: actions/setup-node@v6
21+
with:
22+
node-version: lts/*
23+
24+
- name: Install dependencies
25+
run: npm ci # ci: "clean install"
26+
27+
- name: Install Playwright Chromium deps & browser
28+
run: npx playwright install-deps chromium && npx playwright install chromium
29+
30+
- name: Run Playwright tests
31+
run: npx playwright test
32+
33+
- uses: actions/upload-artifact@v7
34+
if: ${{ !cancelled() }}
35+
with:
36+
name: playwright-report
37+
path: playwright-report/
38+
retention-days: 30

.gitignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,11 @@ web/certs/*
33
!web/certs/.gitkeep
44
build/
55
tmp/
6-
manifest.prod.xml
6+
manifest.prod.xml
7+
8+
# Playwright
9+
/test-results/
10+
/playwright-report/
11+
/blob-report/
12+
/playwright/.cache/
13+
/playwright/.auth/

.vscode/extensions.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"recommendations": [
33
"dbaeumer.vscode-eslint",
44
"streetsidesoftware.code-spell-checker",
5+
"ms-playwright.playwright"
56
]
67
}

DEV.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ mkcert -cert-file web/certs/localhost.crt -key-file web/certs/localhost.key loca
3737

3838
If you're on WSL, follow [these steps](https://github.com/microsoft/WSL/issues/3161#issuecomment-451863149). For more background, see [this guide](https://240dc.com/wsl2-add-a-local-ssl-certificate-with-mkcert/), but rather execute the commands as shown in the first link. It's a bit tedious, but you will get there.
3939

40+
Playwright tests do not need those certificates. The local and CI test setup starts Vite over plain `http` because the Office APIs are mocked in that scenario.
41+
4042
### Debug
4143

4244
In PowerPoint, press `Ctrl+Shift+I` when the focus is on the Add-in task pane. This will open the dev console of the embedded web view where you can see network requests, the console output etc.
@@ -47,6 +49,19 @@ In PowerPoint, press `Ctrl+Shift+I` when the focus is on the Add-in task pane. T
4749
npm run validate-manifest
4850
```
4951

52+
## Playwright Tests
53+
54+
```sh
55+
# Install necessary dependencies first
56+
npx playwright install-deps chromium
57+
npx playwright install chromium
58+
59+
# Run tests (or even easier, just use the Playwright VSCode extension)
60+
# Note that a dedicated test webserver will automatically be started for the tests,
61+
# see the playwright.config.ts for details.
62+
npm run test
63+
```
64+
5065
## Test production-like environment
5166

5267
All you have to do is sideload the `manifest.prod.xml` instead of the manifest used for local development `manifest.xml`. To do so, copy the `manifest.prod.xml` to some `tmp/` folder that you have added to the PowerPoint Trust Center (see above) and rename the file to `manifest.xml` such that PowerPoint recognizes it.
@@ -58,3 +73,7 @@ If you have used another manifest beforehand, clear the office cache as describe
5873
```
5974

6075
The production manifest has URLs configured to point to the site hosted on GitHub Pages. This way, you can see if everything works fine. All we ship to the PowerPoint Marketplace is the Manifest file in the end.
76+
77+
## Useful links
78+
79+
- [PowerPoint JS API](https://learn.microsoft.com/en-us/javascript/api/powerpoint) (Preview) & [v10](https://learn.microsoft.com/en-us/javascript/api/powerpoint?view=powerpoint-js-1.10)

package-lock.json

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

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"build": "vite build --config .config/vite.config.js",
88
"start": "office-addin-debugging start manifest.xml desktop",
99
"stop": "office-addin-debugging stop manifest.xml",
10+
"test": "npx playwright test",
1011
"validate": "office-addin-manifest validate manifest.xml",
1112
"validate-prod": "office-addin-manifest validate -p manifest.prod.xml",
1213
"generate-prod-manifest": "sed 's|https://localhost:3155/pptypst/|https://splines.github.io/pptypst/|g' manifest.xml > manifest.prod.xml"
@@ -15,7 +16,9 @@
1516
"@eslint/css": "^1.1",
1617
"@eslint/js": "^10.0.1",
1718
"@html-eslint/eslint-plugin": "^0.59",
19+
"@playwright/test": "^1.58.2",
1820
"@stylistic/eslint-plugin": "^5.7",
21+
"@types/node": "^25.5.0",
1922
"@types/office-js": "^1.0",
2023
"eslint": "^10.2",
2124
"globals": "^17.5",

0 commit comments

Comments
 (0)