0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00
astro/packages/db/test/local-prod.test.js
Matthew Phillips f5df12cfeb
Provide guidance when --remote is omitted (#10579)
* Provide guidance when --remote is omitted

* Only restrict to server mode

* Use an AstroError

* Update code
2024-03-27 15:20:11 -04:00

65 lines
1.7 KiB
JavaScript

import { expect } from 'chai';
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', () => {
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);
expect(response.status).to.equal(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();
} catch(err) {
buildError = err;
}
expect(buildError).to.be.an('Error');
});
it('should throw during the build for hybrid output', async () => {
let fixture2 = await loadFixture({
root: new URL('./fixtures/local-prod/', import.meta.url),
output: 'hybrid',
adapter: testAdapter(),
});
delete process.env.ASTRO_DATABASE_FILE;
let buildError = null;
try {
await fixture2.build();
} catch(err) {
buildError = err;
}
expect(buildError).to.be.an('Error');
});
});
});