MCPcopy Index your code
hub / github.com/zenstackhq/zenstack / loadSchemaWithError

Function loadSchemaWithError

packages/language/test/utils.ts:23–42  ·  view source on GitHub ↗
(schema: string, error: string | RegExp)

Source from the content-addressed store, hash-verified

21}
22
23export 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}

Calls 3

loadDocumentFunction · 0.90
invariantFunction · 0.90
toStringMethod · 0.45

Tested by

no test coverage detected