Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

Save screenshots during playwright (#32)

Myles Scolnick2065b4d4e2fc
diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml
index c0c85c07d6..35ed2f8a83 100644
--- a/.github/workflows/playwright.yml
+++ b/.github/workflows/playwright.yml
@@ -76,6 +76,28 @@ jobs:
working-directory: ./frontend
run: npx playwright test
+ - name: 📸 Save screenshots
+ uses: getsentry/action-visual-snapshot@main
+ # Only save on main
+ if: github.ref == 'refs/heads/main'
+ # Beta: Don't fail the build
+ continue-on-error: true
+ with:
+ save-only: true
+ snapshot-path: frontend/e2e-tests/screenshots
+
+ - name: 📊 Diff screenshots
+ uses: getsentry/action-visual-snapshot@main
+ id: visual-snapshots-diff
+ # Only diff on PRs
+ if: github.ref != 'refs/heads/main' && github.event_name == 'pull_request'
+ # Beta: Don't fail the build
+ continue-on-error: true
+ with:
+ save-only: true
+ base-branch: main
+ snapshot-path: frontend/e2e-tests/screenshots
+
- uses: actions/upload-artifact@v3
if: always()
with:
diff --git a/frontend/.gitignore b/frontend/.gitignore
index 29d3a7ecd0..a534798791 100644
--- a/frontend/.gitignore
+++ b/frontend/.gitignore
@@ -17,3 +17,4 @@
/test-results/
/playwright-report/
/playwright/.cache/
+e2e-tests/screenshots
diff --git a/frontend/e2e-tests/helper.ts b/frontend/e2e-tests/helper.ts
index 48434e17f7..ac128359e1 100644
--- a/frontend/e2e-tests/helper.ts
+++ b/frontend/e2e-tests/helper.ts
@@ -1,5 +1,6 @@
/* Copyright 2023 Marimo. All rights reserved. */
import { Page, expect } from "@playwright/test";
+import path from "node:path";
export async function createCellBelow(opts: {
page: Page;
@@ -42,3 +43,21 @@ export async function runCell(opts: { page: Page; cellSelector: string }) {
// Run the new cell
await page.getByTestId("run-button").locator(":visible").first().click();
}
+
+const countsForName: Record<string, number> = {};
+/**
+ * Take a screenshot of the page.
+ * @example
+ * await takeScreenshot(page, __filename);
+ */
+export async function takeScreenshot(page: Page, filename: string) {
+ const clean = path.basename(filename).replace(".spec.ts", "");
+
+ const count = countsForName[clean] || 0;
+ countsForName[clean] = count + 1;
+ const fullName = `${clean}.${count}`;
+ await page.screenshot({
+ path: `e2e-tests/screenshots/${fullName}.png`,
+ fullPage: true,
+ });
+}
diff --git a/frontend/e2e-tests/mode.spec.ts b/frontend/e2e-tests/mode.spec.ts
index 7f12a24b54..109b927f81 100644
--- a/frontend/e2e-tests/mode.spec.ts
+++ b/frontend/e2e-tests/mode.spec.ts
@@ -1,6 +1,7 @@
/* Copyright 2023 Marimo. All rights reserved. */
import { test, expect } from "@playwright/test";
import { getAppUrl } from "../playwright.config";
+import { takeScreenshot } from "./helper";
test("page renders edit feature in edit mode", async ({ page }) => {
const appUrl = getAppUrl("title.py");
@@ -11,6 +12,8 @@ test("page renders edit feature in edit mode", async ({ page }) => {
// Can see output
await expect(page.locator("h1").getByText("Hello Marimo!")).toBeVisible();
+
+ await takeScreenshot(page, __filename);
});
test("can toggle to read mode", async ({ page }) => {
@@ -35,6 +38,8 @@ test("can toggle to read mode", async ({ page }) => {
// Can see output and code
await expect(page.locator("h1").getByText("Hello Marimo!")).toBeVisible();
await expect(page.getByText("# Hello Marimo!")).toBeVisible();
+
+ await takeScreenshot(page, __filename);
});
test("page renders read only view in read mode", async ({ page }) => {
@@ -48,4 +53,6 @@ test("page renders read only view in read mode", async ({ page }) => {
// Can see output
await expect(page.locator("h1").getByText("UI Elements")).toBeVisible();
+
+ await takeScreenshot(page, __filename);
});
diff --git a/frontend/e2e-tests/tsconfig.json b/frontend/e2e-tests/tsconfig.json
new file mode 100644
index 0000000000..7026481f54
--- /dev/null
+++ b/frontend/e2e-tests/tsconfig.json
@@ -0,0 +1,20 @@
+{
+ "compilerOptions": {
+ "lib": ["ES2022", "DOM"],
+ "noEmit": true,
+ "module": "ESNext",
+ "moduleResolution": "node",
+ "types": ["node"],
+ "esModuleInterop": true,
+ "forceConsistentCasingInFileNames": true,
+ "strict": true,
+ "noImplicitAny": true,
+ "noImplicitThis": true,
+ "noUnusedLocals": true,
+ "noFallthroughCasesInSwitch": true,
+ "noImplicitOverride": true,
+ "useUnknownInCatchVariables": true,
+ "skipLibCheck": true
+ },
+ "include": ["*"]
+}
diff --git a/frontend/package.json b/frontend/package.json
index 4bf047eb54..04ca527a12 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -117,6 +117,7 @@
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.4.3",
"@types/katex": "^0.16.2",
+ "@types/node": "^20.5.6",
"@types/react": "^18.2.21",
"@types/react-dom": "^18.2.7",
"@types/timestring": "^6.0.2",
diff --git a/frontend/playwright.config.ts b/frontend/playwright.config.ts
index 0ce0e049f4..a0258a7ef3 100644
--- a/frontend/playwright.config.ts
+++ b/frontend/playwright.config.ts
@@ -1,3 +1,4 @@
+/* Copyright 2023 Marimo. All rights reserved. */
import type { PlaywrightTestConfig } from "@playwright/test";
import { devices } from "@playwright/test";
import path from "node:path";
diff --git a/frontend/pnpm-lock.yaml b/frontend/pnpm-lock.yaml
index 17e5aa96b5..9a6a6fabee 100644
--- a/frontend/pnpm-lock.yaml
+++ b/frontend/pnpm-lock.yaml
@@ -235,6 +235,9 @@ devDependencies:
'@types/katex':
specifier: ^0.16.2
version: 0.16.2
+ '@types/node':
+ specifier: ^20.5.6
+ version: 20.5.6
'@types/react':
specifier: ^18.2.21
version: 18.2.21
@@ -318,7 +321,7 @@ devDependencies:
version: 5.1.6
vite:
specifier: ^4.4.9
- version: 4.4.9(@types/[email protected])([email protected])
+ version: 4.4.9(@types/[email protected])([email protected])
vite-tsconfig-paths:
specifier: ^4.2.0
@@ -2536,7 +2539,7 @@ packages:
dependencies:
'@types/istanbul-lib-coverage': 2.0.4
'@types/istanbul-reports': 3.0.1
- '@types/node': 17.0.19
+ '@types/node': 20.5.6
'@types/yargs': 16.0.5
chalk: 4.1.2
dev: true
@@ -2548,7 +2551,7 @@ packages:
'@jest/schemas': 29.6.0
'@types/istanbul-lib-coverage': 2.0.4
'@types/istanbul-reports': 3.0.1
- '@types/node': 17.0.19
+ '@types/node': 20.5.6
'@types/yargs': 17.0.24
chalk: 4.1.2
dev: true
@@ -2567,7 +2570,7 @@ packages:
magic-string: 0.27.0
react-docgen-typescript: 2.2.2([email protected])
typescript: 5.1.6
- vite: 4.4.9(@types/[email protected])([email protected])
+ vite: 4.4.9(@types/[email protected])([email protected])
dev: true
/@jridgewell/[email protected]:
@@ -2864,7 +2867,7 @@ packages:
engines: {node: '>=16'}
hasBin: true
dependencies:
- '@types/node': 17.0.19
+ '@types/node': 20.5.6
playwright-core: 1.37.1
optionalDependencies:
fsevents: 2.3.2
@@ -4585,7 +4588,7 @@ packages:
remark-slug: 6.1.0
rollup: 3.28.0
typescript: 5.1.6
- vite: 4.4.9(@types/[email protected])([email protected])
+ vite: 4.4.9(@types/[email protected])([email protected])
transitivePeerDependencies:
- encoding
- supports-color
@@ -4997,7 +5000,7 @@ packages:
react: 18.2.0
react-docgen: 6.0.0-alpha.3
react-dom: 18.2.0([email protected])
- vite: 4.4.9(@types/[email protected])([email protected])
+ vite: 4.4.9(@types/[email protected])([email protected])
transitivePeerDependencies:
- '@preact/preset-vite'
- encoding
@@ -5385,7 +5388,7 @@ packages:
resolution: {integrity: sha512-ALYone6pm6QmwZoAgeyNksccT9Q4AWZQ6PvfwR37GT6r6FWUPguq6sUmNGSMV2Wr761oQoBxwGGa6DR5o1DC9g==}
dependencies:
'@types/connect': 3.4.35
- '@types/node': 17.0.19
+ '@types/node': 20.5.6
resolution: {integrity: sha512-frBecisrNGz+F4T6bcc+NLeolfiojh5FxW2klu669+8BARtyQv2C/GkNW6FUodVe4BroGMP/wER/YDGc7rEllw==}
@@ -5400,7 +5403,7 @@ packages:
resolution: {integrity: sha512-cdeYyv4KWoEgpBISTxWvqYsVy444DOqehiF3fM3ne10AmJ62RSyNkUnxMJXHQWRQQX2eR94m5y1IZyDwBjV9FQ==}
dependencies:
- '@types/node': 17.0.19
+ '@types/node': 20.5.6
resolution: {integrity: sha512-XW/Aa8APYr6jSVVA1y/DEIZX0/GMKLEVekNG727R8cs56ahETkRAy/3DR7+fJyh7oUgGwNQaRfXCun0+KbWY7Q==}
@@ -5409,7 +5412,7 @@ packages:
resolution: {integrity: sha512-KuwNhp3eza+Rhu8IFI5HUXRP0LIhqH5cAjubUvGXXthh4YYBuP2ntwEX+Cz8GJoZUHlKo247wPWOfA9LYEq4cw==}
dependencies:
- '@types/node': 17.0.19
+ '@types/node': 20.5.6
dev: true
@@ -5462,7 +5465,7 @@ packages:
resolution: {integrity: sha512-wALWQwrgiB2AWTT91CB62b6Yt0sNHpznUXeZEcnPU3DRdlDIz74x8Qg1UUYKSVFi+va5vKOLYRBI1bRKiLLKIg==}
dependencies:
- '@types/node': 17.0.19
+ '@types/node': 20.5.6
'@types/qs': 6.9.7
'@types/range-parser': 1.2.4
'@types/send': 0.17.1
@@ -5482,13 +5485,13 @@ packages:
resolution: {integrity: sha512-ZUxbzKl0IfJILTS6t7ip5fQQM/J3TJYubDm3nMbgubNNYS62eXeUpoLUC8/7fJNiFYHTrGPQn7hspDUzIHX3UA==}
dependencies:
'@types/minimatch': 5.1.2
- '@types/node': 17.0.19
+ '@types/node': 20.5.6
dev: true
resolution: {integrity: sha512-Sig0SNORX9fdW+bQuTEovKj3uHcUL6LQKbCrrqb1X7J6/ReAbhCXRAhc+SMejhLELFj2QcyuxmUooZ4bt5ReSw==}
dependencies:
- '@types/node': 17.0.19
+ '@types/node': 20.5.6
dev: true
@@ -5559,14 +5562,14 @@ packages:
resolution: {integrity: sha512-1ZX9fcN4Rvkvgv4E6PAY5WXUFWFcRWxZa3EW83UjycOB9ljJCedb2CupIP4RZMEwF/M3eTcCihbBRgwtGbg5Rg==}
dependencies:
- '@types/node': 17.0.19
+ '@types/node': 20.5.6
form-data: 3.0.1
resolution: {integrity: sha512-8egDX8dE50XyXWH6C6PRCNkTP106DuUrvdrednFouDSmCi7IOvrqr0frznfZaHifHH/3aq/7a7v9N4wdXMqhBQ==}
- resolution: {integrity: sha512-PfeQhvcMR4cPFVuYfBN4ifG7p9c+Dlh3yUZR6k+5yQK7wX3gDgVxBly4/WkBRs9x4dmcy1TVl08SY67wwtEvmA==}
+ resolution: {integrity: sha512-Gi5wRGPbbyOTX+4Y2iULQ27oUPrefaB0PxGQJnfyWN3kvEDGM3mIB5M/gQLmitZf7A9FmLeaqxD3L1CXpm3VKQ==}
resolution: {integrity: sha512-Gj7cI7z+98M282Tqmp2K5EIsoouUEzbBJhQQzDE3jSIRk6r9gsz0oUokqIUR4u1R3dMHo0pDHM7sNOHyhulypw==}
@@ -5622,18 +5625,18 @@ packages:
resolution: {integrity: sha512-Cwo8LE/0rnvX7kIIa3QHCkcuF21c05Ayb0ZfxPiv0W8VRiZiNW/WuRupHKpqqGVGf7SUA44QSOUKaEd9lIrd/Q==}
dependencies:
'@types/mime': 1.3.2
- '@types/node': 17.0.19
+ '@types/node': 20.5.6
resolution: {integrity: sha512-NUo5XNiAdULrJENtJXZZ3fHtfMolzZwczzBbnAeBbqBwG+LaG6YaJtuwzwGSQZ2wsCrxjEhNNjAkKigy3n8teQ==}
dependencies:
'@types/mime': 1.3.2
- '@types/node': 17.0.19
+ '@types/node': 20.5.6
resolution: {integrity: sha512-fBZgytwhYAUkj/jC/FAV4RQ5EerRup1YQsXQCh8rZfiHkc4UahC192oH0smGwsXol3cL3A5oETuAHeQHmhXM4w==}
dependencies:
- '@types/node': 17.0.19
+ '@types/node': 20.5.6
dev: true
@@ -5875,7 +5878,7 @@ packages:
vite: ^4
dependencies:
'@swc/core': 1.3.62
- vite: 4.4.9(@types/[email protected])([email protected])
+ vite: 4.4.9(@types/[email protected])([email protected])
transitivePeerDependencies:
- '@swc/helpers'
dev: true
@@ -5891,7 +5894,7 @@ packages:
'@babel/plugin-transform-react-jsx-source': 7.19.6(@babel/[email protected])
magic-string: 0.27.0
react-refresh: 0.14.0
- vite: 4.4.9(@types/[email protected])([email protected])
+ vite: 4.4.9(@types/[email protected])([email protected])
transitivePeerDependencies:
- supports-color
dev: true
@@ -9448,7 +9451,7 @@ packages:
dependencies:
'@jest/types': 29.6.1
'@types/graceful-fs': 4.1.6
- '@types/node': 17.0.19
+ '@types/node': 20.5.6
anymatch: 3.1.3
fb-watchman: 2.0.2
graceful-fs: 4.2.10
@@ -9466,7 +9469,7 @@ packages:
engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0}
dependencies:
'@jest/types': 27.5.1
- '@types/node': 17.0.19
+ '@types/node': 20.5.6
dev: true
@@ -9479,7 +9482,7 @@ packages:
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
dependencies:
'@jest/types': 29.6.1
- '@types/node': 17.0.19
+ '@types/node': 20.5.6
chalk: 4.1.2
ci-info: 3.8.0
graceful-fs: 4.2.10
@@ -9490,7 +9493,7 @@ packages:
resolution: {integrity: sha512-7vuh85V5cdDofPyxn58nrPjBktZo0u9x1g8WtjQol+jZDaE+fhN+cIvTj11GndBnMnyfrUOG1sZQxCdjKh+DKg==}
engines: {node: '>= 10.13.0'}
dependencies:
- '@types/node': 17.0.19
+ '@types/node': 20.5.6
merge-stream: 2.0.0
supports-color: 8.1.1
dev: false
@@ -9499,7 +9502,7 @@ packages:
resolution: {integrity: sha512-NcrQnevGoSp4b5kg+akIpthoAFHxPBcb5P6mYPY0fUNT+sSvmtu6jlkEle3anczUKIKEbMxFimk9oTP/tpIPgA==}
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
dependencies:
- '@types/node': 17.0.19
+ '@types/node': 20.5.6
jest-util: 29.6.1
merge-stream: 2.0.0
supports-color: 8.1.1
@@ -13132,7 +13135,7 @@ packages:
engines: {node: '>= 0.8'}
dev: true
resolution: {integrity: sha512-+0TzJf1g0tYXj6tR2vEyiA42OPq68QkRZCu/ERSo2PtsDJfBpDyEfuKbRvLmZqi/CgC7SCBtyC+WjTGNMRIaig==}
engines: {node: '>=v14.18.0'}
hasBin: true
@@ -13142,7 +13145,7 @@ packages:
mlly: 1.4.0
pathe: 1.1.1
picocolors: 1.0.0
- vite: 4.4.9(@types/[email protected])([email protected])
+ vite: 4.4.9(@types/[email protected])([email protected])
transitivePeerDependencies:
- '@types/node'
- less
@@ -13165,13 +13168,13 @@ packages:
debug: 4.3.4
globrex: 0.1.2
tsconfck: 2.1.1([email protected])
- vite: 4.4.9(@types/[email protected])([email protected])
+ vite: 4.4.9(@types/[email protected])([email protected])
transitivePeerDependencies:
- supports-color
- typescript
dev: true
resolution: {integrity: sha512-2mbUn2LlUmNASWwSCNSJ/EG2HuSRTnVNaydp6vMCm5VIqJsjMfbIWtbH2kDuwUVW5mMUKKZvGPX/rqeqVvv1XA==}
engines: {node: ^14.18.0 || >=16.0.0}
hasBin: true
@@ -13199,7 +13202,7 @@ packages:
terser:
optional: true
dependencies:
- '@types/node': 17.0.19
+ '@types/node': 20.5.6
esbuild: 0.18.16
less: 4.1.3
postcss: 8.4.28
@@ -13241,7 +13244,7 @@ packages:
dependencies:
'@types/chai': 4.3.5
'@types/chai-subset': 1.3.3
- '@types/node': 17.0.19
+ '@types/node': 20.5.6
'@vitest/expect': 0.34.3
'@vitest/runner': 0.34.3
'@vitest/snapshot': 0.34.3
@@ -13261,8 +13264,8 @@ packages:
strip-literal: 1.0.1
tinybench: 2.5.0
tinypool: 0.7.0
- vite: 4.4.9(@types/[email protected])([email protected])
- vite-node: 0.34.3(@types/[email protected])([email protected])
+ vite: 4.4.9(@types/[email protected])([email protected])
+ vite-node: 0.34.3(@types/[email protected])([email protected])
why-is-node-running: 2.2.2
transitivePeerDependencies:
- less