(schema: string, error: string | RegExp)
| 21 | } |
| 22 | |
| 23 | export async function loadSchemaWithError(schema: string, error: string | RegExp) { |
| 24 | // create a temp file |
| 25 | const tempFile = path.join(os.tmpdir(), `zenstack-schema-${crypto.randomUUID()}.zmodel`); |
| 26 | fs.writeFileSync(tempFile, schema); |
| 27 | |
| 28 | const r = await loadDocument(tempFile, pluginDocs); |
| 29 | expect(r.success).toBe(false); |
| 30 | invariant(!r.success); |
| 31 | if (typeof error === 'string') { |
| 32 | expect(r).toSatisfy( |
| 33 | (r) => r.errors.some((e) => e.toString().toLowerCase().includes(error.toLowerCase())), |
| 34 | `Expected error message to include "${error}" but got: ${r.errors.map((e) => e.toString()).join(', ')}`, |
| 35 | ); |
| 36 | } else { |
| 37 | expect(r).toSatisfy( |
| 38 | (r) => r.errors.some((e) => error.test(e)), |
| 39 | `Expected error message to match "${error}" but got: ${r.errors.map((e) => e.toString()).join(', ')}`, |
| 40 | ); |
| 41 | } |
| 42 | } |
no test coverage detected