From 172aa9633e617ce6286e439161f7dfc1b49faac2 Mon Sep 17 00:00:00 2001 From: Roman Radchenko Date: Tue, 30 Dec 2025 02:33:19 +0200 Subject: [PATCH] chore(auth): release version 0.2.0 with breaking changes to authTest and createAuthTest options --- .github/workflows/release-auth.yml | 46 +++++++++++++++++++ README.md | 7 ++- RELEASING.md | 36 +++++++++++++++ lefthook.yml | 8 ++++ package-lock.json | 2 +- packages/auth/CHANGELOG.md | 5 ++ packages/auth/README.md | 3 +- packages/auth/package.json | 2 +- .../auth/src/__tests__/argParsing.test.ts | 1 - packages/auth/src/cli/args.ts | 7 --- packages/auth/src/cli/commands/authEnsure.ts | 2 - packages/auth/src/cli/help.ts | 6 +-- packages/auth/src/cli/main.ts | 1 - packages/auth/src/fixtures/createAuthTest.ts | 18 +------- .../authTest-use-options-type.test.ts | 20 ++++++++ 15 files changed, 130 insertions(+), 34 deletions(-) create mode 100644 .github/workflows/release-auth.yml create mode 100644 RELEASING.md create mode 100644 packages/auth/type-tests/authTest-use-options-type.test.ts diff --git a/.github/workflows/release-auth.yml b/.github/workflows/release-auth.yml new file mode 100644 index 0000000..53cc92b --- /dev/null +++ b/.github/workflows/release-auth.yml @@ -0,0 +1,46 @@ +name: release-auth + +on: + push: + tags: + - "@playwright-kit/auth@*" + +permissions: + contents: write + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: 20 + cache: npm + registry-url: "https://registry.npmjs.org" + + - name: Install dependencies + run: npm ci + + - name: Verify tag matches package version + shell: bash + run: | + TAG="${GITHUB_REF_NAME}" + VERSION="$(node -p "require('./packages/auth/package.json').version")" + EXPECTED="@playwright-kit/auth@${VERSION}" + if [ "${TAG}" != "${EXPECTED}" ]; then + echo "Tag mismatch: got '${TAG}', expected '${EXPECTED}'" + exit 1 + fi + + - name: Publish to npm + run: npm -w packages/auth publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + + - name: Create GitHub Release + uses: softprops/action-gh-release@v2 + with: + generate_release_notes: true + diff --git a/README.md b/README.md index 863eebb..16a099e 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,10 @@ This repo is a small monorepo of production-ready utilities built on top of Play - npm: `https://www.npmjs.com/package/@playwright-kit/auth` - Examples: `examples/next-admin-auth`, `examples/vite-react-auth` +## Releasing + +See `RELEASING.md`. + ## Auth (@playwright-kit/auth) Infrastructure utilities for managing Playwright `storageState` auth artifacts *before* running tests. @@ -224,7 +228,8 @@ Or: playwright-kit auth ensure --dotenv-path .env.ci ``` -This requires `dotenv` to be installed in your project (`npm i -D dotenv`). +Notes: +- `.env` loading is provided via the `dotenv` package. ### Using in tests diff --git a/RELEASING.md b/RELEASING.md new file mode 100644 index 0000000..0e2bb43 --- /dev/null +++ b/RELEASING.md @@ -0,0 +1,36 @@ +## Releasing + +This repo is a monorepo. The root package is private; only packages under `packages/*` are published. + +### One-time GitHub setup + +1) Create an npm automation token that can publish `@playwright-kit/*`. +2) Add it to the GitHub repo secrets as `NPM_TOKEN`. + +### Release `@playwright-kit/auth` + +1) Update `packages/auth/CHANGELOG.md` (optional but recommended). +2) Bump the version in `packages/auth/package.json` (and commit it): + +```bash +cd packages/auth +npm version patch --no-git-tag-version +cd ../.. +git add packages/auth/package.json packages/auth/CHANGELOG.md +git commit -m "release(auth): v$(node -p \"require('./packages/auth/package.json').version\")" +``` + +3) Create and push a tag in the format `@playwright-kit/auth@`: + +```bash +git tag "@playwright-kit/auth@$(node -p \"require('./packages/auth/package.json').version\")" +git push origin main +git push origin --tags +``` + +That tag triggers the GitHub Action that: +- runs `npm ci` +- verifies the tag matches `packages/auth/package.json#version` +- publishes `@playwright-kit/auth` to npm +- creates a GitHub Release for the tag + diff --git a/lefthook.yml b/lefthook.yml index bf71420..450954d 100644 --- a/lefthook.yml +++ b/lefthook.yml @@ -1,4 +1,12 @@ pre-commit: + parallel: true + commands: + lint: + run: npm run lint + typecheck: + run: npm run typecheck + +pre-push: commands: check: run: npm run check diff --git a/package-lock.json b/package-lock.json index 8a47469..5d3b7ff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2994,7 +2994,7 @@ }, "packages/auth": { "name": "@playwright-kit/auth", - "version": "0.1.2", + "version": "0.2.0", "license": "MIT", "dependencies": { "dotenv": "^16.4.7", diff --git a/packages/auth/CHANGELOG.md b/packages/auth/CHANGELOG.md index c4e0d95..810bca6 100644 --- a/packages/auth/CHANGELOG.md +++ b/packages/auth/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 0.2.0 + +- Breaking: removed `baseTest` / `baseExpect` options from `authTest()` and `createAuthTest()` to keep types strictly aligned with Playwright’s default `test`. +- CLI: removed `--fail-fast` (undocumented) to keep `ensure` behavior consistent and deterministic across multiple profiles. + ## 0.1.0 - CLI: `playwright-kit auth setup/ensure` with failure artifacts and optional `webServer` + `dotenv`. diff --git a/packages/auth/README.md b/packages/auth/README.md index d2a8e87..0992d1c 100644 --- a/packages/auth/README.md +++ b/packages/auth/README.md @@ -210,7 +210,8 @@ Or: playwright-kit auth ensure --dotenv-path .env.ci ``` -This requires `dotenv` to be installed in your project (`npm i -D dotenv`). +Notes: +- `.env` loading is provided via the `dotenv` package. ## Using in tests diff --git a/packages/auth/package.json b/packages/auth/package.json index 8c0ccce..ca47d74 100644 --- a/packages/auth/package.json +++ b/packages/auth/package.json @@ -1,6 +1,6 @@ { "name": "@playwright-kit/auth", - "version": "0.1.2", + "version": "0.2.0", "description": "Small, production-ready authentication utilities for Playwright.", "license": "MIT", "sideEffects": false, diff --git a/packages/auth/src/__tests__/argParsing.test.ts b/packages/auth/src/__tests__/argParsing.test.ts index 75b0282..714e406 100644 --- a/packages/auth/src/__tests__/argParsing.test.ts +++ b/packages/auth/src/__tests__/argParsing.test.ts @@ -59,7 +59,6 @@ test("parseArgs: ensure supports repeated --profile", () => { kind: "ensure", profiles: ["a", "b"], configPath: undefined, - failFast: false, headed: false, browser: undefined, webServer: undefined, diff --git a/packages/auth/src/cli/args.ts b/packages/auth/src/cli/args.ts index 32da394..3c8d60d 100644 --- a/packages/auth/src/cli/args.ts +++ b/packages/auth/src/cli/args.ts @@ -35,7 +35,6 @@ export type ParsedArgs = kind: "ensure"; profiles?: string[]; configPath?: string; - failFast: boolean; headed: boolean; browser?: BrowserName; webServer?: WebServerArgs; @@ -290,7 +289,6 @@ export function parseArgs(argv: string[]): ParsedArgs { if (command === "ensure") { const profiles: string[] = []; let configPath: string | undefined; - let failFast = false; let headed = false; let browser: BrowserName | undefined; const webServer = parseWebServerArgs(rest); @@ -322,10 +320,6 @@ export function parseArgs(argv: string[]): ParsedArgs { i++; continue; } - if (arg === "--fail-fast") { - failFast = true; - continue; - } if (arg === "--headed") { headed = true; continue; @@ -377,7 +371,6 @@ export function parseArgs(argv: string[]): ParsedArgs { kind: "ensure", profiles: profiles.length > 0 ? profiles : undefined, configPath, - failFast, headed, browser, webServer, diff --git a/packages/auth/src/cli/commands/authEnsure.ts b/packages/auth/src/cli/commands/authEnsure.ts index 149341d..dc8de45 100644 --- a/packages/auth/src/cli/commands/authEnsure.ts +++ b/packages/auth/src/cli/commands/authEnsure.ts @@ -9,7 +9,6 @@ export async function authEnsure(options: { loaded: AuthConfigLoadResult; profileNames?: string[]; headed: boolean; - failFast: boolean; browserName?: "chromium" | "firefox" | "webkit"; env: NodeJS.ProcessEnv; onLog?: (line: string) => void; @@ -80,7 +79,6 @@ export async function authEnsure(options: { const message = error instanceof Error ? error.message : String(error); log(`auth ensure: "${profileName}" failed: ${message}`); failures.push({ profile: profileName, error }); - if (options.failFast) break; } } diff --git a/packages/auth/src/cli/help.ts b/packages/auth/src/cli/help.ts index a375917..397629a 100644 --- a/packages/auth/src/cli/help.ts +++ b/packages/auth/src/cli/help.ts @@ -9,11 +9,11 @@ playwright-kit auth Usage: playwright-kit auth setup --profile [--config ] [--headed] [--browser ] - playwright-kit auth ensure [--profile ...] [--config ] [--fail-fast] [--headed] [--browser ] + playwright-kit auth ensure [--profile ...] [--config ] [--headed] [--browser ] Env (optional): - --dotenv Load .env from current working directory (requires "dotenv"). - --dotenv-path Load env from a specific file path (requires "dotenv"). + --dotenv Load .env from current working directory. + --dotenv-path Load env from a specific file path. Web server (optional): --web-server-command Command to start your app/server (quote if it contains spaces). diff --git a/packages/auth/src/cli/main.ts b/packages/auth/src/cli/main.ts index 86a0313..3a619fa 100644 --- a/packages/auth/src/cli/main.ts +++ b/packages/auth/src/cli/main.ts @@ -71,7 +71,6 @@ async function run(argv: string[]): Promise { loaded, profileNames: parsed.profiles, headed: parsed.headed, - failFast: parsed.failFast, browserName: parsed.browser, env: process.env, }), diff --git a/packages/auth/src/fixtures/createAuthTest.ts b/packages/auth/src/fixtures/createAuthTest.ts index 494eaa3..3659f9f 100644 --- a/packages/auth/src/fixtures/createAuthTest.ts +++ b/packages/auth/src/fixtures/createAuthTest.ts @@ -15,7 +15,6 @@ type BaseTestArgs = PlaywrightTestArgs & PlaywrightTestOptions; type BaseWorkerArgs = PlaywrightWorkerArgs & PlaywrightWorkerOptions; type StorageStateOption = PlaywrightTestOptions["storageState"]; -type DefaultBaseTest = typeof playwrightTest; type DefaultExpect = typeof playwrightExpect; type AuthFixtures = { @@ -66,20 +65,15 @@ export interface AuthTestOptions { /** Alias for statesDir (kept for ergonomics). */ stateDir?: string; defaultProfile: string; - baseTest?: DefaultBaseTest; - baseExpect?: DefaultExpect; } export function authTest(options: AuthTestOptions): AuthTestWithExpect { - const baseTest = options.baseTest ?? playwrightTest; - const expect = options.baseExpect ?? playwrightExpect; - const statesDir = options.statesDir ?? options.stateDir ?? ".auth"; const defaultProfile = options.defaultProfile; const authOption: [string, { option: true }] = [defaultProfile, { option: true }]; - const testBase = baseTest.extend({ + const testBase = playwrightTest.extend({ auth: authOption, _authStatePath: async ({ auth }, use) => { if (!auth) { @@ -123,23 +117,18 @@ export function authTest(options: AuthTestOptions): AuthTestWithExpect { derived(title, fn); }; - return Object.assign(testBase, { withAuth, auth, expect }); + return Object.assign(testBase, { withAuth, auth, expect: playwrightExpect }); } export interface CreateAuthTestOptions { statesDir?: string; defaultProfile?: string; - baseTest?: DefaultBaseTest; - baseExpect?: DefaultExpect; } export function createAuthTest(options: CreateAuthTestOptions = {}): { test: AuthTest; expect: DefaultExpect; } { - const baseTest = options.baseTest ?? playwrightTest; - const baseExpect = options.baseExpect ?? playwrightExpect; - const defaultProfile = options.defaultProfile; if (!defaultProfile) { throw new Error( @@ -150,10 +139,7 @@ export function createAuthTest(options: CreateAuthTestOptions = {}): { const test = authTest({ defaultProfile, statesDir: options.statesDir, - baseTest, - baseExpect, }); return { test, expect: test.expect }; } - diff --git a/packages/auth/type-tests/authTest-use-options-type.test.ts b/packages/auth/type-tests/authTest-use-options-type.test.ts new file mode 100644 index 0000000..26898f8 --- /dev/null +++ b/packages/auth/type-tests/authTest-use-options-type.test.ts @@ -0,0 +1,20 @@ +import type { PlaywrightTestOptions } from "@playwright/test"; + +import { authTest } from "../src/fixtures/createAuthTest"; + +const test = authTest({ defaultProfile: "user" }); + +test.use({ auth: "admin" }); + +const storageState: PlaywrightTestOptions["storageState"] = { + cookies: [], + origins: [], +}; +test.use({ storageState }); + +test("options keep Playwright types", async ({ page, baseURL, storageState: state }) => { + void page; + void baseURL; + void state; +}); +