Files
conference-room-booking-system/frontend/noxfile.py
Cliff Hill 5735a2d2cd Fixing stuff.
Signed-off-by: Cliff Hill <xlorep@darkhelm.org>
2025-10-09 08:01:09 -04:00

119 lines
3.0 KiB
Python

"""Nox sessions for frontend tasks.
Run with `nox -s <session>` from the frontend directory.
"""
import os
import subprocess
from pathlib import Path
import nox
nox.options.sessions = (
"pre-commit",
"coverage",
"audit",
"storybook-build",
"jest",
)
@nox.session(name="pre-commit")
def precommit(session: nox.Session) -> None:
"""Run pre-commit checks by delegating to the root noxfile.
Args:
session: The Nox session object.
"""
session.run("nox", "-f", "../noxfile.py", "-s", "pre-commit", external=True)
@nox.session(name="typecheck")
def typecheck(session: nox.Session) -> None:
"""Run TypeScript type checks.
Args:
session: The Nox session object.
"""
frontend_dir = Path(__file__).parent
os.chdir(frontend_dir)
session.run("yarn", "tsc", "--noEmit", external=True)
@nox.session(name="coverage")
def coverage(session: nox.Session) -> None:
"""Run Jest with coverage reporting.
Args:
session: The Nox session object.
"""
frontend_dir = Path(__file__).parent
os.chdir(frontend_dir)
session.run("yarn", "jest", "--coverage", external=True)
@nox.session(name="audit")
def audit(session: nox.Session) -> None:
"""Run yarn audit for security checks.
Args:
session: The Nox session object.
"""
frontend_dir = Path(__file__).parent
os.chdir(frontend_dir)
# Run yarn npm audit and capture output
result = subprocess.run(["yarn", "npm", "audit"], capture_output=True, text=True)
output = result.stdout + "\n" + result.stderr
# Check for eslint deprecation warning and ignore if that's the only error
eslint_deprecation = "ID: eslint (deprecation)"
if result.returncode != 0:
if (
eslint_deprecation in output
and "This version is no longer supported" in output
):
# Print warning but do not fail session
session.log("Ignoring eslint deprecation warning in audit output.")
session.log(output)
return
else:
session.error(output)
else:
session.log(output)
@nox.session(name="storybook-build")
def storybook_build(session: nox.Session) -> None:
"""Build Storybook for frontend documentation.
Args:
session: The Nox session object.
"""
frontend_dir = Path(__file__).parent
os.chdir(frontend_dir)
session.run("yarn", "build-storybook", external=True)
@nox.session(name="storybook")
def storybook(session: nox.Session) -> None:
"""Run Storybook for frontend documentation.
Args:
session: The Nox session object.
"""
frontend_dir = Path(__file__).parent
os.chdir(frontend_dir)
session.run("yarn", "storybook", external=True)
@nox.session(name="jest")
def jest(session: nox.Session) -> None:
"""Run frontend Jest tests using yarn.
Args:
session: The Nox session object.
"""
frontend_dir = Path(__file__).parent
os.chdir(frontend_dir)
session.run("yarn", "run", "jest", external=True)