feat: writes, procedures, Fastify and Express adapters, documentation
This commit is contained in:
@@ -1,29 +1,30 @@
|
||||
import { test, before, after } from 'node:test';
|
||||
import { describe, test, before, after } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { createRequire } from 'node:module';
|
||||
import { createREST } from '../packages/core/dist/index.js';
|
||||
import { postgres } from '../packages/postgres/dist/index.js';
|
||||
import { examples, run } from './examples.mjs';
|
||||
import { PAGES, OPTIONS } from './pages.mjs';
|
||||
|
||||
const require = createRequire(new URL('../packages/postgres/package.json', import.meta.url));
|
||||
const { Pool } = require('pg');
|
||||
const url = process.env.RESTLOOM_PG_URL;
|
||||
const docs = new URL('../docs/', import.meta.url).pathname;
|
||||
const pages = ['query-grammar.md'];
|
||||
const fixture = readFileSync(new URL('./fixtures/postgres.sql', import.meta.url), 'utf8');
|
||||
|
||||
let pool;
|
||||
let rest;
|
||||
before(async () => {
|
||||
if (!url) return;
|
||||
pool = new Pool({ connectionString: url });
|
||||
await pool.query(readFileSync(new URL('./fixtures/postgres.sql', import.meta.url), 'utf8'));
|
||||
rest = createREST({ db: postgres(pool), expose: { schemas: ['demo'] }, resources: { asset_tags: { expose: false } } });
|
||||
});
|
||||
before(() => { if (url) pool = new Pool({ connectionString: url }); });
|
||||
after(async () => { await pool?.end(); });
|
||||
|
||||
for (const page of pages) {
|
||||
for (const example of examples(docs + page)) {
|
||||
test(`postgres ${example.name}`, { skip: !url && 'RESTLOOM_PG_URL is not set' }, () => run(rest, example, assert));
|
||||
}
|
||||
for (const page of PAGES) {
|
||||
describe(`postgres ${page}`, { skip: !url && 'RESTLOOM_PG_URL is not set' }, () => {
|
||||
let rest;
|
||||
before(async () => {
|
||||
await pool.query(fixture);
|
||||
rest = createREST({ db: postgres(pool), ...OPTIONS });
|
||||
});
|
||||
for (const example of examples(new URL(`../docs/${page}`, import.meta.url).pathname)) {
|
||||
test(example.name, () => run(rest, example, assert));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user