refactor: sql-tools (#19717)

This commit is contained in:
Jason Rasmussen 2025-07-03 10:59:17 -04:00 committed by GitHub
parent 484529e61e
commit 6044663e26
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
160 changed files with 1120 additions and 1186 deletions

View file

@ -0,0 +1,46 @@
import { readdirSync } from 'node:fs';
import { join } from 'node:path';
import { schemaFromCode } from 'src/sql-tools/schema-from-code';
import { describe, expect, it } from 'vitest';
describe(schemaFromCode.name, () => {
it('should work', () => {
expect(schemaFromCode({ reset: true })).toEqual({
databaseName: 'postgres',
schemaName: 'public',
functions: [],
enums: [],
extensions: [],
parameters: [],
tables: [],
warnings: [],
});
});
describe('test files', () => {
const errorStubs = readdirSync('test/sql-tools/errors', { withFileTypes: true });
for (const file of errorStubs) {
const filePath = join(file.parentPath, file.name);
it(filePath, async () => {
const module = await import(filePath);
expect(module.message).toBeDefined();
expect(() => schemaFromCode({ reset: true })).toThrowError(module.message);
});
}
const stubs = readdirSync('test/sql-tools', { withFileTypes: true });
for (const file of stubs) {
if (file.isDirectory()) {
continue;
}
const filePath = join(file.parentPath, file.name);
it(filePath, async () => {
const module = await import(filePath);
expect(module.description).toBeDefined();
expect(module.schema).toBeDefined();
expect(schemaFromCode({ reset: true }), module.description).toEqual(module.schema);
});
}
});
});