| 56 | } |
| 57 | |
| 58 | function runExpectations( |
| 59 | exp: NonNullable<E2ECase["expectations"]>, |
| 60 | finalText: string | undefined, |
| 61 | errors: string[], |
| 62 | prefix = "", |
| 63 | ): void { |
| 64 | const tag = prefix ? `${prefix}: ` : ""; |
| 65 | if (exp.finalContains) { |
| 66 | for (const needle of exp.finalContains) { |
| 67 | if (!(finalText ?? "").toLowerCase().includes(needle.toLowerCase())) { |
| 68 | errors.push(`${tag}missing: ${JSON.stringify(needle)}`); |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | if (exp.finalNotContains) { |
| 73 | for (const needle of exp.finalNotContains) { |
| 74 | if ((finalText ?? "").toLowerCase().includes(needle.toLowerCase())) { |
| 75 | errors.push(`${tag}contained forbidden: ${JSON.stringify(needle)}`); |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | if (exp.balancedBrackets && finalText && !isBalanced(finalText)) { |
| 80 | errors.push(`${tag}text has unbalanced brackets`); |
| 81 | } |
| 82 | if (exp.minLength && (finalText?.length ?? 0) < exp.minLength) { |
| 83 | errors.push( |
| 84 | `${tag}too short (${finalText?.length ?? 0} < ${exp.minLength})`, |
| 85 | ); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | async function runCase(spec: E2ECase): Promise<CaseResult> { |
| 90 | const errors: string[] = []; |