(schema: string)
| 8 | const pluginDocs = [path.resolve(__dirname, '../../plugins/policy/plugin.zmodel')]; |
| 9 | |
| 10 | export async function loadSchema(schema: string) { |
| 11 | // create a temp file |
| 12 | const tempFile = path.join(os.tmpdir(), `zenstack-schema-${crypto.randomUUID()}.zmodel`); |
| 13 | fs.writeFileSync(tempFile, schema); |
| 14 | const r = await loadDocument(tempFile, pluginDocs); |
| 15 | expect(r).toSatisfy( |
| 16 | (r) => r.success, |
| 17 | `Failed to load schema: ${(r as any).errors?.map((e) => e.toString()).join(', ')}`, |
| 18 | ); |
| 19 | invariant(r.success); |
| 20 | return r.model; |
| 21 | } |
| 22 | |
| 23 | export async function loadSchemaWithError(schema: string, error: string | RegExp) { |
| 24 | // create a temp file |
no test coverage detected