Files
animaltrack/flake.nix
Petru Paler feca97a796 Add Playwright e2e test infrastructure
Set up browser-based end-to-end testing using pytest-playwright:
- Add playwright-driver and pytest-playwright to nix flake
- Configure PLAYWRIGHT_BROWSERS_PATH for NixOS compatibility
- Create ServerHarness to manage live server for tests
- Add smoke tests for health endpoint and page loading
- Exclude e2e tests from pre-commit hook (require special setup)

Run e2e tests with: pytest tests/e2e/ -v -n 0

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-18 08:11:15 +00:00

105 lines
3.0 KiB
Nix

{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
};
outputs = { self, nixpkgs }:
let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
# Python with custom packages
python = pkgs.python313.override {
self = python;
packageOverrides = pyfinal: pyprev: {
# Leaf packages (no custom dependencies)
mistletoe = pyfinal.callPackage ./packages/mistletoe.nix { };
sse-starlette = pyfinal.callPackage ./packages/sse-starlette.nix { };
fastcore = pyfinal.callPackage ./packages/fastcore.nix { };
# Second level (depend on leaf packages)
apswutils = pyfinal.callPackage ./packages/apswutils.nix { };
fastlite = pyfinal.callPackage ./packages/fastlite.nix { };
fastmigrate = pyfinal.callPackage ./packages/fastmigrate.nix { };
# Top level (depend on second level)
python-fasthtml = pyfinal.callPackage ./packages/python-fasthtml.nix { };
monsterui = pyfinal.callPackage ./packages/monsterui.nix { };
};
};
# Shared Python environment for both dev and Docker
pythonEnv = python.withPackages (ps: with ps; [
# From nixpkgs
uvicorn
starlette
httpx
pydantic
pydantic-settings
anyio
beautifulsoup4
python-dateutil
oauthlib
itsdangerous
python-multipart
lxml
apsw
packaging
python-ulid
xxhash
# Custom packages
fastcore
apswutils
fastlite
fastmigrate
sse-starlette
python-fasthtml
monsterui
mistletoe
# Dev-only (not needed in Docker, but fine to include)
pytest
pytest-xdist
pytest-playwright
requests
ruff
filelock
]);
in
{
packages.${system} = {
dockerImage = let
buildDate = let
d = self.lastModifiedDate or "00000000000000";
in "${builtins.substring 0 4 d}-${builtins.substring 4 2 d}-${builtins.substring 6 2 d}";
buildCommit = self.shortRev or self.dirtyShortRev or "unknown";
in import ./docker.nix { inherit pkgs pythonEnv python buildDate buildCommit; };
};
devShells.${system}.default = pkgs.mkShell {
buildInputs = [
pythonEnv
# Tools
pkgs.jq
pkgs.sqlite
pkgs.skopeo # For pushing Docker images
pkgs.lefthook # Git hooks manager
pkgs.playwright-driver # Browser binaries for e2e tests
];
# Playwright browser configuration for NixOS
PLAYWRIGHT_BROWSERS_PATH = "${pkgs.playwright-driver.browsers}";
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD = "1";
shellHook = ''
export PYTHONPATH="$PWD/src:$PYTHONPATH"
export PATH="$PWD/bin:$PATH"
echo "AnimalTrack development environment ready!"
echo "Run 'animaltrack serve' to start the app"
'';
};
};
}