From tdk-test-api
Generate Playwright TypeScript API test code from testcase files and execution manifest.
How this skill is triggered — by the user, by Claude, or both
Slash command
/tdk-test-api:tdk-test-api-gen-code-playwright-tsThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Read `*.testcases.md` + `test-execution-plan.yaml` + `.specify.json` config and generate production-ready Playwright TypeScript API test code with externalized test data.
Read *.testcases.md + test-execution-plan.yaml + .specify.json config and generate production-ready Playwright TypeScript API test code with externalized test data.
/tdk-test-api-gen-code-playwright-ts {feature-id} # Generate code
/tdk-test-api-gen-code-playwright-ts {feature-id} --sub-workspace backend # Target sub-workspace
/tdk-test-api-gen-code-playwright-ts {feature-id} --force # Overwrite existing
If .api.spec.ts files already exist AND user provides an update description:
npx tsc --noEmit.*.testcases.md — from /tdk-test-api-generate-testcase (required)test-execution-plan.yaml — execution manifest (required).specify.json → test.api block (required)Generated file structure:
tests/api/
├── setup/
│ └── auth.setup.ts # Auth management (strategy-dependent)
├── {resource}/
│ ├── {resource}-{action}.api.spec.ts # Test code per endpoint
│ ├── input.json # Request payloads (user-editable)
│ └── output.json # Expected responses (user-editable)
├── playwright.config.ts # Config with project deps from manifest
├── .gitignore # Exclude auth state, traces, results
└── test-execution-plan.yaml # (from Skill 2, not modified)
| Error | Action |
|---|---|
No *.testcases.md files found | STOP: "Run /tdk-test-api-generate-testcase {feature-id} first" |
test-execution-plan.yaml missing | STOP: "Execution manifest missing" |
test.api config missing | STOP with suggested YAML block |
| Testcase file missing required sections | STOP with list of issues |
| Generated TS has compile errors | Report errors, attempt auto-fix |
Run environment script:
bun .specify/scripts/ts/src/commands/test-api/codegen-env.ts <feature-id> [--sub-workspace {NAME}] [--force]
Parse JSON output -> Store all fields. If error -> STOP and report.
If HAS_EXISTING_SPECS = true AND user provided update prompt:
.api.spec.ts filesnpx tsc --noEmit to verifyIf HAS_EXISTING_SPECS = true AND no update prompt AND FORCE_MODE = false:
If HAS_EXISTING_SPECS = false OR FORCE_MODE = true -> Continue.
From script output, extract:
TEST_API_AUTH_STRATEGY — determines auth.setup.ts patternTEST_API_BASE_URL_ENV — env var for baseURL in configTEST_API_TOKEN_ENV — env var for auth tokenIf HAS_TEST_API_CONFIG = false -> STOP with error + suggested YAML block.
*.testcases.md from TESTCASE_FILEStest-execution-plan.yamlFrom script output, check HAS_PLAYWRIGHT:
Playwright not installed. Run:
npm init playwright@latest
Continue generating code (user can install later).4a. auth.setup.ts — Select pattern from references/auth-strategy-patterns.md:
| Strategy | Pattern |
|---|---|
bearer | Export getAuthToken(role) reading from env vars |
session | Playwright setup project with storageState |
api-key | Export getApiKey() + apiKeyHeaders() |
none | Export no-op functions |
Create {API_TEST_DIR}/setup/auth.setup.ts
4b. .gitignore:
playwright/.auth/
test-results/
playwright-report/
blob-report/
Create {API_TEST_DIR}/.gitignore
4c. Per-resource test data — For each resource directory:
{resource}/input.json — request payloads keyed by action{resource}/output.json — expected response data keyed by actionFor each *.testcases.md, generate co-located .api.spec.ts.
Follow patterns from references/test-code-patterns.md:
test.describe block with:
test.describe.configure({ mode: 'serial' }) for CRUD lifecyclelet variables for IDs captured during create teststest() block:
test('TC-001: {description}', ...)expect(res.status()).toBe({status})bodyimport inputData from './input.json'import { getAuthToken, authHeaders } from '../setup/auth.setup'test.afterAll() to DELETE created resources{resource}/{resource}-{action}.api.spec.tsFollow patterns from references/playwright-config-patterns.md:
test-execution-plan.yamlname -> project namefiles -> testMatch arraydepends_on -> dependencies arrayparallel -> fullyParallel flagbaseURL from TEST_API_BASE_URL_ENV env var{API_TEST_DIR}/playwright.config.tsRun: npx tsc --noEmit --project {API_TEST_DIR}/tsconfig.json (if tsconfig exists)
OR: npx tsc --noEmit {API_TEST_DIR}/**/*.ts
Confirm each test.describe block that creates resources (POST) includes:
test.afterAll() with DELETE call for cleanupPlaywright API Tests Generated
===============================
Auth strategy: {strategy}
Base URL env: {env_var}
Files created:
Setup:
- setup/auth.setup.ts
- .gitignore
Test data:
- {resource}/input.json
- {resource}/output.json
...
Specs:
- {resource}/{resource}-{action}.api.spec.ts ({n} tests)
...
Config:
- playwright.config.ts ({p} projects)
Total: {n} spec files, {tc} test cases
Run tests:
cd {API_TEST_DIR} && npx playwright test
Next steps:
1. Review generated input.json/output.json and adjust test data
2. Set env vars: {BASE_URL_ENV}, {TOKEN_ENV}
3. Run: npx playwright test
| Error | Solution |
|---|---|
| Testcase files not found | Run /tdk-test-api-generate-testcase first |
| Execution manifest missing | Run /tdk-test-api-generate-testcase first |
| test.api config missing | Add test.api block to .specify.json |
| Playwright not installed | npm init playwright@latest |
| TS compile errors | Review generated code, check imports |
/tdk-test-api-plan — Generate API test plan/tdk-test-api-generate-testcase — Generate testcase files (input for this skill)npx claudepluginhub vinhltt/tdk --plugin tdk-test-apiWhole-repo audit for over-engineering: finds dead code, unnecessary abstractions, stdlib-replaceable dependencies. Outputs ranked findings and net line/dep savings.