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

Function loadSchemaWithError

packages/testtools/src/schema.ts:175–197  ·  view source on GitHub ↗
(schema: string, error: string | RegExp)

Source from the content-addressed store, hash-verified

173}
174
175export async function loadSchemaWithError(schema: string, error: string | RegExp) {
176 if (!schema.includes('datasource ')) {
177 schema = `${makePrelude('sqlite')}\n\n${schema}`;
178 }
179
180 // create a temp file
181 const tempFile = path.join(os.tmpdir(), `zenstack-schema-${crypto.randomUUID()}.zmodel`);
182 fs.writeFileSync(tempFile, schema);
183 const r = await loadDocumentWithPlugins(tempFile);
184 expect(r.success).toBe(false);
185 invariant(!r.success);
186 if (typeof error === 'string') {
187 expect(r).toSatisfy(
188 (r) => r.errors.some((e: any) => e.toString().toLowerCase().includes(error.toLowerCase())),
189 `Expected error message to include "${error}" but got: ${r.errors.map((e: any) => e.toString()).join(', ')}`,
190 );
191 } else {
192 expect(r).toSatisfy(
193 (r) => r.errors.some((e: any) => error.test(e)),
194 `Expected error message to match "${error}" but got: ${r.errors.map((e: any) => e.toString()).join(', ')}`,
195 );
196 }
197}

Callers 10

issue-283.test.tsFile · 0.90
issue-1758.test.tsFile · 0.90
issue-1984.test.tsFile · 0.90
issue-177.test.tsFile · 0.90
issue-804.test.tsFile · 0.90
issue-925.test.tsFile · 0.90
issue-965.test.tsFile · 0.90
issue-756.test.tsFile · 0.90
toplevel.test.tsFile · 0.90

Calls 4

loadDocumentWithPluginsFunction · 0.90
invariantFunction · 0.90
makePreludeFunction · 0.85
toStringMethod · 0.45

Tested by

no test coverage detected