0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-06 22:10:10 -05:00

Add a very basic test

This commit is contained in:
Matthew Phillips 2024-01-08 15:31:05 -05:00 committed by Nate Moore
parent c538999cde
commit 4b0829825a
5 changed files with 84 additions and 0 deletions

View file

@ -0,0 +1,27 @@
import { expect } from 'chai';
import { load as cheerioLoad } from 'cheerio';
import { isWindows, loadFixture } from '../../../astro/test/test-utils.js';
describe('astro:db', () => {
let fixture;
before(async () => {
fixture = await loadFixture({
root: new URL('./fixtures/basics/', import.meta.url),
});
});
describe('build', () => {
before(async () => {
await fixture.build();
});
it('Prints the list of authors', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerioLoad(html);
const ul = $('ul');
expect(ul).to.have.a.lengthOf(5);
expect($('li').text()).to.equal('Ben');
});
});
});

View file

@ -0,0 +1,16 @@
import { defineConfig } from 'astro/config';
import { db, field } from '@astro/db';
// https://astro.build/config
export default defineConfig({
integrations: [db()],
db: {
collections: {
Author: {
fields: {
name: field.text(),
},
}
}
}
});

View file

@ -0,0 +1,21 @@
import { Author, db } from 'astro:db';
const authors: Array<typeof Author.$inferInsert> = [
{
name: 'Ben',
},
{
title: 'Nate',
},
{
title: 'Erika',
},
{
title: 'Bjorn',
},
{
title: 'Sarah',
},
];
await db.insert(Author).values(authors);

View file

@ -0,0 +1,9 @@
{
"name": "@test/db-aliases",
"version": "0.0.0",
"private": true,
"dependencies": {
"@astrojs/db": "workspace:*",
"astro": "workspace:*"
}
}

View file

@ -0,0 +1,11 @@
---
import { Author, db } from 'astro:db';
const authors = await db.select().from(Author);
---
<ul>
{authors.map(author => (
<li>{author.name}</li>
))}
</ul>