0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-06 22:10:10 -05:00
astro/packages/db/test/local-prod.test.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

90 lines
2.5 KiB
JavaScript
Raw Normal View History

2024-05-22 03:17:53 -05:00
import assert from 'node:assert/strict';
2024-08-15 09:52:26 -05:00
import { relative } from 'node:path';
2024-08-15 09:53:15 -05:00
import { after, before, describe, it } from 'node:test';
2024-08-15 09:52:26 -05:00
import { fileURLToPath } from 'node:url';
import testAdapter from '../../astro/test/test-adapter.js';
import { loadFixture } from '../../astro/test/test-utils.js';
describe('astro:db local database', () => {
let fixture;
before(async () => {
fixture = await loadFixture({
root: new URL('./fixtures/local-prod/', import.meta.url),
output: 'server',
adapter: testAdapter(),
});
});
describe('build (not remote) with DATABASE_FILE env (file URL)', () => {
const prodDbPath = new URL('./fixtures/basics/dist/astro.db', import.meta.url).toString();
before(async () => {
process.env.ASTRO_DATABASE_FILE = prodDbPath;
await fixture.build();
});
after(async () => {
delete process.env.ASTRO_DATABASE_FILE;
});
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);
});
});
[db] Fix duplicate calls to recreate tables on startup (#10919) * fix: move recreateTables() to integration hooks * feat: recreate and seed at load, not in virtual runtime * feat: eager build db on startup and seed file change * fix: respect database_file in dbUrl * chore: remove duplicate recreateTables call * chore: remove now self-explanatory comments * fix: remove invalidateModule call for eager loading * feat: respect seed package paths * fix: remove duplicate recreateTables() call * refactor: move recreateTables() to vite-plugin-db * refactor: move queries.ts from runtime/ to core/ * fix: update test import to core/queries * refactor: move executeSeedFile to vite-plugin-db * refactor: extract seeding and recreating to helper fns * chore: changeset * chore: revert connectToStudio refactor * wip: log db url * fix(test): normalize astro_database_file flag for windows * Revert "wip: log db url" This reverts commit 558e2de67a09a611377929b625127c649b8504d6. * Revert "Revert "wip: log db url"" This reverts commit ffd004e00dff485b7bc5ddde0278dde6ff058b9e. * fix: correctly resolve relative paths with unit test * chore: remove unused dbDirPath Co-authored-by: Chris Swithinbank <swithinbank@gmail.com> * chore: remove unused import Co-authored-by: Chris Swithinbank <swithinbank@gmail.com> * chore: remove unused type Co-authored-by: Chris Swithinbank <swithinbank@gmail.com> * fix: remove bad import * [db] Load seed files with vite dev server (#10941) * feat: load seed files with full vite dev server * chore: remove unused export --------- Co-authored-by: Chris Swithinbank <swithinbank@gmail.com>
2024-05-03 10:08:50 -05:00
describe('build (not remote) with DATABASE_FILE env (relative file path)', () => {
const absoluteFileUrl = new URL('./fixtures/basics/dist/astro.db', import.meta.url);
const prodDbPath = relative(process.cwd(), fileURLToPath(absoluteFileUrl));
before(async () => {
process.env.ASTRO_DATABASE_FILE = prodDbPath;
await fixture.build();
});
after(async () => {
delete process.env.ASTRO_DATABASE_FILE;
});
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 (not remote)', () => {
it('should throw during the build for server output', async () => {
delete process.env.ASTRO_DATABASE_FILE;
let buildError = null;
try {
await fixture.build();
2024-03-27 14:21:30 -05:00
} catch (err) {
buildError = err;
}
2024-05-22 03:17:53 -05:00
assert.equal(buildError instanceof Error, true);
});
it('should throw during the build for hybrid output', async () => {
let fixture2 = await loadFixture({
root: new URL('./fixtures/local-prod/', import.meta.url),
output: 'static',
adapter: testAdapter(),
});
delete process.env.ASTRO_DATABASE_FILE;
let buildError = null;
try {
await fixture2.build();
2024-03-27 14:21:30 -05:00
} catch (err) {
buildError = err;
}
2024-05-22 03:17:53 -05:00
assert.equal(buildError instanceof Error, true);
});
});
});