0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-06 22:10:10 -05:00
astro/packages/db/test/static-remote.test.js
Luiz Ferraz d6611e8bb0
Add support for LibSQL remote (#11385)
* Add support for remote LibSQL

* Add support for local memory DB

* Add some tests

* Add push support

* Fix switch cascading

* Update .changeset/healthy-boxes-poke.md

Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>

* Update packages/db/src/runtime/db-client.ts

[skip ci]

Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>

* Use independent env vars for LibSQL and Studio backends

* Expand comment regarding missing table

* Apply suggestions from code review

Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>

---------

Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
2024-08-28 12:15:33 +01:00

69 lines
1.7 KiB
JavaScript

import assert from 'node:assert/strict';
import { after, before, describe, it } from 'node:test';
import { load as cheerioLoad } from 'cheerio';
import { loadFixture } from '../../astro/test/test-utils.js';
import { setupRemoteDbServer } from './test-utils.js';
describe('astro:db', () => {
let fixture;
before(async () => {
fixture = await loadFixture({
root: new URL('./fixtures/static-remote/', import.meta.url),
output: 'static',
});
});
describe('static build --remote', () => {
let remoteDbServer;
before(async () => {
remoteDbServer = await setupRemoteDbServer(fixture.config);
await fixture.build();
});
after(async () => {
await remoteDbServer?.stop();
});
it('Can render page', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerioLoad(html);
assert.equal($('li').length, 1);
});
it('Returns correct shape from db.run()', async () => {
const html = await fixture.readFile('/run/index.html');
const $ = cheerioLoad(html);
assert.match($('#row').text(), /1/);
});
});
describe('static build --remote with custom LibSQL', () => {
let remoteDbServer;
before(async () => {
process.env.ASTRO_DB_REMOTE_URL = `memory:`;
await fixture.build();
});
after(async () => {
await remoteDbServer?.stop();
});
it('Can render page', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerioLoad(html);
assert.equal($('li').length, 1);
});
it('Returns correct shape from db.run()', async () => {
const html = await fixture.readFile('/run/index.html');
const $ = cheerioLoad(html);
assert.match($('#row').text(), /1/);
});
});
});