Typescript playwright
This finalizes the typescript-playwright generator (started on this branch), which
generates Playwright API tests and a typed client from an
OpenAPI specification.
What it generates
A self-contained, type-checkable Playwright test project:
apis/ typed API client classes (one per tag), driven by Playwright's APIRequestContext
models/ request/response models with (de)serializers
runtime.ts BaseAPI + helpers wrapping Playwright's request fixture
spec/apis/.spec.ts one describe block per API, one test per operation
spec/models/.spec.ts model type tests
playwright.config.ts Playwright config (baseURL via BASE_URL env)
package.json / tsconfig.json
Each generated test uses Playwright's request fixture, calls the operation and
asserts on the response status:
test('addPet', async ({ request }) => {
const api = new PetApi(request);
const response = await api.addPetRaw({ pet: {} as unknown as Pet });
expect(response.raw.status()).toBe(200);
});
Changes
- Rewrote the runtime around Playwright's APIRequestContext (was a fetch-based copy
of typescript-fetch); the client constructor now takes the request fixture.
- Replaced api_test.mustache (which was a byte-for-byte duplicate of the client) with
real Playwright spec generation; placeholder example values per parameter are computed
so generated specs type-check.
- Made the output a self-contained project (always emits package.json, tsconfig.json,
playwright.config.ts); dropped the src/ nesting.
- Fixed the sample output path typo (typescript-wright → typescript-playwright).
- Added TypeScriptPlaywrightClientCodegenTest.
Testing done
- TypeScriptPlaywrightClientCodegenTest: 3/3 pass.
- Generated sample: npm install + tsc --noEmit passes; npx playwright test --list
compiles and discovers all 26 tests; the model specs run green. (API specs issue real
compiles and discovers all 26 tests; the model specs run green. (API specs issue real
requests and need a live BASE_URL, by design.)
cc @leonyu (TypeScript Fetch, which this derives from)
<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Finalizes the `typescript-playwright` generator to emit a self-contained, runnable Playwright test project—a typed API client plus generated API and model specs—instead of a fetch-based client copied from `typescript-fetch`.
- The client wraps Playwright's `APIRequestContext`; the `BaseAPI` constructor takes the `request` fixture, and each API spec issues one real request per operation and asserts the status.
- Output is a runnable project (`package.json`, `tsconfig.json`, `playwright.config.ts`) with no `src/` nesting; generated code type-checks via `tsc --noEmit`.
- Runtime resolves the target server from the `BASE_URL` env var, builds multipart bodies from `FormData`, JSON-encodes bare-primitive bodies for JSON content types, and escapes operation summaries and enum example values.
- Removed the redux-saga/immutablejs templates and the `sagasAndRecords` feature; `package.json` requires TypeScript >= 4.7.
- Added `TypeScriptPlaywrightClientCodegenTest`, fixed the sample output path typo, and added a CI workflow that runs the generated API specs against an echo server, waiting for the server to be ready before starting the tests.
- Fixed `samples-r.yaml` by passing `working-directory` as a `with` input.
<!-- End of auto-generated description by cubic. -->