$npx -y skills add wrtnlabs/autobe --skill fix-testFix Test compilation errors
| 1 | # Fix Test Errors |
| 2 | |
| 3 | Fix test file compilation errors according to code conventions. |
| 4 | |
| 5 | ## FORBIDDEN |
| 6 | |
| 7 | **NEVER use:** |
| 8 | - `as` keyword (type assertion) |
| 9 | - `any` type |
| 10 | - `typia.random<EmptyType>()` - generates invalid data |
| 11 | |
| 12 | --- |
| 13 | |
| 14 | ## Purpose |
| 15 | |
| 16 | Fix compilation errors in test files to ensure `npm run build:test` passes. |
| 17 | |
| 18 | ## Workflow |
| 19 | |
| 20 | ``` |
| 21 | ┌─────────────────────────────────────┐ |
| 22 | │ Step 1: Run Build │ |
| 23 | │ npm run build:test │ |
| 24 | └───────────────┬─────────────────────┘ |
| 25 | │ |
| 26 | ▼ |
| 27 | ┌─────────────────────────────────────┐ |
| 28 | │ Step 2: Parse Test Errors │ |
| 29 | │ - Empty prepare functions │ |
| 30 | │ - Type mismatches │ |
| 31 | │ - Missing imports │ |
| 32 | └───────────────┬─────────────────────┘ |
| 33 | │ |
| 34 | ▼ |
| 35 | ┌─────────────────────────────────────┐ |
| 36 | │ Step 3: Fix by Convention │ |
| 37 | │ - Fill prepare functions │ |
| 38 | │ - Create generate functions │ |
| 39 | │ - Fix import paths │ |
| 40 | └───────────────┬─────────────────────┘ |
| 41 | │ |
| 42 | ▼ |
| 43 | ┌─────────────────────────────────────┐ |
| 44 | │ Step 4: Re-run Build │ |
| 45 | │ Loop until 0 errors │ |
| 46 | └─────────────────────────────────────┘ |
| 47 | ``` |
| 48 | |
| 49 | --- |
| 50 | |
| 51 | ## Step 1: Run Build |
| 52 | |
| 53 | ```bash |
| 54 | npm run build:test 2>&1 | head -100 |
| 55 | ``` |
| 56 | |
| 57 | Capture test-related errors. |
| 58 | |
| 59 | --- |
| 60 | |
| 61 | ## Step 2: Find Issues |
| 62 | |
| 63 | ```bash |
| 64 | # Find empty returns |
| 65 | grep -rn "return {}" test/prepare/ --include="*.ts" |
| 66 | |
| 67 | # Find typia.random with potentially empty types |
| 68 | grep -rn "typia.random<" test/ --include="*.ts" |
| 69 | ``` |
| 70 | |
| 71 | --- |
| 72 | |
| 73 | ## Step 3: Fix by Convention |
| 74 | |
| 75 | ### Fix Empty prepare_random Function |
| 76 | |
| 77 | ```typescript |
| 78 | // Before |
| 79 | export function prepare_random_{prefix}_{entity}( |
| 80 | input?: DeepPartial<I{Prefix}{Entity}.ICreate> | undefined, |
| 81 | ): I{Prefix}{Entity}.ICreate { |
| 82 | return {}; // WRONG |
| 83 | } |
| 84 | |
| 85 | // After |
| 86 | import { I{Prefix}{Entity} } from "@ORGANIZATION/PROJECT-api/lib/structures/I{Prefix}{Entity}"; |
| 87 | import { DeepPartial } from "@ORGANIZATION/PROJECT-api/lib/typings/DeepPartial"; |
| 88 | import { RandomGenerator } from "@nestia/e2e"; |
| 89 | import { randint } from "tstl"; |
| 90 | import { v4 } from "uuid"; |
| 91 | |
| 92 | export function prepare_random_{prefix}_{entity}( |
| 93 | input?: DeepPartial<I{Prefix}{Entity}.ICreate> | undefined, |
| 94 | ): I{Prefix}{Entity}.ICreate { |
| 95 | return { |
| 96 | parent_id: input?.parent_id ?? v4(), |
| 97 | name: input?.name ?? RandomGenerator.name(2), |
| 98 | title: input?.title ?? RandomGenerator.paragraph(1), |
| 99 | content: input?.content ?? RandomGenerator.paragraph(3), |
| 100 | is_public: input?.is_public ?? true, |
| 101 | status: input?.status ?? "active", |
| 102 | }; |
| 103 | } |
| 104 | ``` |
| 105 | |
| 106 | ### Create Missing generate_random Function |
| 107 | |
| 108 | ```typescript |
| 109 | import { I{Prefix}{Entity} } from "@ORGANIZATION/PROJECT-api/lib/structures/I{Prefix}{Entity}"; |
| 110 | import { DeepPartial } from "@ORGANIZATION/PROJECT-api/lib/typings/DeepPartial"; |
| 111 | import api from "@ORGANIZATION/PROJECT-api"; |
| 112 | |
| 113 | import { prepare_random_{prefix}_{entity} } from "../prepare/prepare_random_{prefix}_{entity}"; |
| 114 | |
| 115 | export async function generate_random_{prefix}_{entity}( |
| 116 | connection: api.IConnection, |
| 117 | input?: DeepPartial<I{Prefix}{Entity}.ICreate> | undefined, |
| 118 | ): Promise<I{Prefix}{Entity}> { |
| 119 | const body = prepare_random_{prefix}_{entity}(input); |
| 120 | return api.functional.{prefix}.{path}.create(connection, body); |
| 121 | } |
| 122 | ``` |
| 123 | |
| 124 | ### Field Generation Patterns |
| 125 | |
| 126 | | Field Type | Generation Pattern | |
| 127 | |------------|-------------------| |
| 128 | | UUID | `v4()` | |
| 129 | | Name/Title | `RandomGenerator.name(2)` | |
| 130 | | Paragraph | `RandomGenerator.paragraph(1)` | |
| 131 | | Email | `` `${RandomGenerator.string(8)}@example.com` `` | |
| 132 | | URL | `` `https://example.com/${RandomGenerator.string(10)}` `` | |
| 133 | | Integer | `randint(min, max)` | |
| 134 | | Boolean | `Math.random() > 0.5` | |
| 135 | | Date (ISO) | `new Date().toISOString()` | |
| 136 | | Union Type | `(["val1", "val2"] as const)[randint(0, 1)]` | |
| 137 | |
| 138 | ### Replace typia.random with prepare function |
| 139 | |
| 140 | ```typescript |
| 141 | // Before |
| 142 | const data = typia.random<I{Prefix}{Entity}.ICreate>(); |
| 143 | |
| 144 | // After |
| 145 | import { prepare_random_{prefix}_{entity} } from "../prepare/prepare_random_{prefix}_{entity}"; |
| 146 | |
| 147 | const data = prepare_random_{prefix}_{entity}({ |
| 148 | status: "active", // Can override specific values |
| 149 | }); |
| 150 | ``` |
| 151 | |
| 152 | --- |
| 153 | |
| 154 | ## Step 4: Verify |
| 155 | |
| 156 | ```bash |
| 157 | npm run build:test |
| 158 | ``` |
| 159 | |
| 160 | Repeat Steps 2-4 until no test build errors. |
| 161 | |
| 162 | --- |
| 163 | |
| 164 | ## Common Fixes |
| 165 | |
| 166 | | Error Pattern | Fix | |
| 167 | |---------------|-----| |
| 168 | | Empty `return {}` | Fill with proper random generators | |
| 169 | | `typia.random<EmptyType>` | Use prepare_random function | |
| 170 | | Missing generate function | Create matching generate_random | |
| 171 | | Import error | Fix import path | |
| 172 | |
| 173 | --- |
| 174 | |
| 175 | ## Exit Condition |
| 176 | |
| 177 | - `npm run build:test` completes with no errors |
| 178 | - All prepare functions return complete objects |
| 179 | - All generate functions exist for prepare functions |
| 180 | - No `typia.random` with empty types |