Skip to content

Commit

Permalink
fix: playwright on nix
Browse files Browse the repository at this point in the history
  • Loading branch information
ndom91 committed Oct 26, 2024
1 parent 492a556 commit 5f7f1fa
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 46 deletions.
4 changes: 2 additions & 2 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
"prepare": "svelte-kit sync",
"check": "svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-check --tsconfig ./tsconfig.json --watch",
"test:e2e:playwright": "playwright test"
"test:e2e:web": "playwright test"
},
"devDependencies": {
"@fontsource/fira-mono": "^4.5.10",
"@gitbutler/shared": "workspace:*",
"@gitbutler/ui": "workspace:*",
"@neoconfetti/svelte": "^1.0.0",
"@playwright/test": "^1.47.0",
"@playwright/test": "1.47.0",
"@sveltejs/adapter-auto": "^3.0.0",
"@sveltejs/kit": "catalog:svelte",
"@sveltejs/vite-plugin-svelte": "catalog:svelte",
Expand Down
47 changes: 47 additions & 0 deletions apps/web/tests/perf.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { test, expect } from '@playwright/test';

const limits = {
timeToFirstByte: 800,
domContentLoaded: 2000,
loadComplete: 3000,
firstContentfulPaint: 1500
};

test.describe('Performance Tests', () => {
test('should keep performanceMetrics under limits', async ({ page }) => {
await page.setExtraHTTPHeaders({ Accept: 'text/html' });

const response = await page.goto('/');
expect(response?.status()).toBe(200);

// Get performance metrics using modern APIs
const performanceMetrics = await page.evaluate(() => {
const navigation = performance.getEntriesByType(
'navigation'
)[0] as PerformanceNavigationTiming;
const paintEntries = performance.getEntriesByType('paint');
const firstPaint = paintEntries.find((entry) => entry.name === 'first-paint');
const firstContentfulPaint = paintEntries.find(
(entry) => entry.name === 'first-contentful-paint'
);

return {
// Navigation timing metrics
domContentLoaded: navigation.domContentLoadedEventEnd - navigation.startTime,
loadComplete: navigation.loadEventEnd - navigation.startTime,
timeToFirstByte: navigation.responseStart - navigation.requestStart,
domInteractive: navigation.domInteractive - navigation.startTime,

// Paint timing metrics
firstPaint: firstPaint ? firstPaint.startTime : 0,
firstContentfulPaint: firstContentfulPaint ? firstContentfulPaint.startTime : 0
};
});

// Assert on the metrics
expect(performanceMetrics.timeToFirstByte).toBeLessThan(limits.timeToFirstByte);
expect(performanceMetrics.domContentLoaded).toBeLessThan(limits.domContentLoaded);
expect(performanceMetrics.loadComplete).toBeLessThan(limits.loadComplete);
expect(performanceMetrics.firstContentfulPaint).toBeLessThan(limits.firstContentfulPaint);
});
});
97 changes: 83 additions & 14 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 12 additions & 6 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05";
unstablePkgs.url = "github:nixos/nixpkgs/nixos-unstable";
unstablePkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
nix-playwright-browsers.url = "github:voidus/nix-playwright-browsers";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs = {
nixpkgs.follows = "unstablePkgs";
};
};
};
outputs = { self, unstablePkgs, nixpkgs, flake-utils, rust-overlay }:
outputs = { self, unstablePkgs, nixpkgs, flake-utils, rust-overlay, nix-playwright-browsers }:
flake-utils.lib.eachDefaultSystem
(system:
let
Expand All @@ -19,7 +20,8 @@
inherit system overlays;
};
pkgs = import nixpkgs {
inherit system overlays;
system = system;
overlays = [ nix-playwright-browsers.overlays.${system}.default];
};

rustToolchain = unstable.pkgsBuildHost.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
Expand All @@ -38,6 +40,7 @@
webkitgtk
nodejs_20
corepack_20
pkgs.playwright-browsers_v1_47_0
];

# runtime Deps
Expand All @@ -61,9 +64,12 @@
nativeBuildInputs = packages;
buildInputs = libraries;
shellHook = ''
export LD_LIBRARY_PATH=${unstable.lib.makeLibraryPath libraries}:$LD_LIBRARY_PATH
export XDG_DATA_DIRS=${unstable.gsettings-desktop-schemas}/share/gsettings-schemas/${unstable.gsettings-desktop-schemas.name}:${unstable.gtk3}/share/gsettings-schemas/${unstable.gtk3.name}:$XDG_DATA_DIRS
export GIO_MODULE_DIR="${unstable.glib-networking}/lib/gio/modules/"
LD_LIBRARY_PATH=${unstable.lib.makeLibraryPath libraries}:$LD_LIBRARY_PATH
XDG_DATA_DIRS=${unstable.gsettings-desktop-schemas}/share/gsettings-schemas/${unstable.gsettings-desktop-schemas.name}:${unstable.gtk3}/share/gsettings-schemas/${unstable.gtk3.name}:$XDG_DATA_DIRS
GIO_MODULE_DIR=${unstable.glib-networking}/lib/gio/modules/
PLAYWRIGHT_BROWSERS_PATH=${pkgs.playwright-browsers_v1_47_0}
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS=true
'';
};
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"autoprefixer": "^10.4.19",
"cpy-cli": "^5.0.0",
"dayjs": "^1.11.13",
"playwright": "^1.46.1",
"playwright": "1.47.0",
"postcss": "^8.4.38",
"postcss-cli": "^11.0.0",
"postcss-minify": "^1.1.0",
Expand Down
Loading

0 comments on commit 5f7f1fa

Please sign in to comment.