summaryrefslogtreecommitdiff
path: root/packages/db/test/libsql-remote.test.js
diff options
context:
space:
mode:
authorGravatar Luiz Ferraz <luiz@lferraz.com> 2024-10-07 10:17:26 -0300
committerGravatar GitHub <noreply@github.com> 2024-10-07 10:17:26 -0300
commit6e06e6ed4f1c983f842527d7e3561a45a4407777 (patch)
treef57dd5f7d233a77827dd7db2d24b287593683f53 /packages/db/test/libsql-remote.test.js
parentfef0b8cce1a157edd9a57238c024b08aea102f46 (diff)
downloadastro-6e06e6ed4f1c983f842527d7e3561a45a4407777.tar.gz
astro-6e06e6ed4f1c983f842527d7e3561a45a4407777.tar.zst
astro-6e06e6ed4f1c983f842527d7e3561a45a4407777.zip
Fix problems with local libSQL DB (#12089)
Co-authored-by: Matthew Phillips <361671+matthewp@users.noreply.github.com> Co-authored-by: Emanuele Stoppa <602478+ematipico@users.noreply.github.com>
Diffstat (limited to '')
-rw-r--r--packages/db/test/libsql-remote.test.js77
1 files changed, 77 insertions, 0 deletions
diff --git a/packages/db/test/libsql-remote.test.js b/packages/db/test/libsql-remote.test.js
new file mode 100644
index 000000000..db0995a7b
--- /dev/null
+++ b/packages/db/test/libsql-remote.test.js
@@ -0,0 +1,77 @@
+import assert from 'node:assert/strict';
+import { relative } from 'node:path';
+import { rm } from 'node:fs/promises';
+import { after, before, describe, it } from 'node:test';
+import { fileURLToPath } from 'node:url';
+import testAdapter from '../../astro/test/test-adapter.js';
+import { loadFixture } from '../../astro/test/test-utils.js';
+import { clearEnvironment, initializeRemoteDb } from './test-utils.js';
+
+describe('astro:db local database', () => {
+ let fixture;
+ before(async () => {
+ fixture = await loadFixture({
+ root: new URL('./fixtures/libsql-remote/', import.meta.url),
+ output: 'server',
+ adapter: testAdapter(),
+ });
+ });
+
+ describe('build --remote with local libSQL file (absolute path)', () => {
+ before(async () => {
+ clearEnvironment();
+
+ const absoluteFileUrl = new URL('./fixtures/libsql-remote/dist/absolute.db', import.meta.url);
+ // Remove the file if it exists to avoid conflict between test runs
+ await rm(absoluteFileUrl, { force: true });
+
+ process.env.ASTRO_INTERNAL_TEST_REMOTE = true;
+ process.env.ASTRO_DB_REMOTE_URL = absoluteFileUrl.toString();
+ await fixture.build();
+ await initializeRemoteDb(fixture.config);
+ });
+
+ after(async () => {
+ delete process.env.ASTRO_INTERNAL_TEST_REMOTE;
+ delete process.env.ASTRO_DB_REMOTE_URL;
+ });
+
+ it('Can render page', async () => {
+ const app = await fixture.loadTestAdapterApp();
+ const request = new Request('http://example.com/');
+ const response = await app.render(request);
+ assert.equal(response.status, 200);
+ });
+ });
+
+ describe('build --remote with local libSQL file (relative path)', () => {
+ before(async () => {
+ clearEnvironment();
+
+ const absoluteFileUrl = new URL('./fixtures/libsql-remote/dist/relative.db', import.meta.url);
+ const prodDbPath = relative(
+ fileURLToPath(fixture.config.root),
+ fileURLToPath(absoluteFileUrl),
+ );
+ // Remove the file if it exists to avoid conflict between test runs
+ await rm(prodDbPath, { force: true });
+
+ process.env.ASTRO_INTERNAL_TEST_REMOTE = true;
+ process.env.ASTRO_DB_REMOTE_URL = `file:${prodDbPath}`;
+ await fixture.build();
+ await initializeRemoteDb(fixture.config);
+ });
+
+ after(async () => {
+ delete process.env.ASTRO_INTERNAL_TEST_REMOTE;
+ delete process.env.ASTRO_DB_REMOTE_URL;
+ });
+
+ it('Can render page', async () => {
+ const app = await fixture.loadTestAdapterApp();
+ const request = new Request('http://example.com/');
+ const response = await app.render(request);
+ assert.equal(response.status, 200);
+ });
+ });
+});