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:
parent
c538999cde
commit
4b0829825a
5 changed files with 84 additions and 0 deletions
27
packages/db/test/basics.test.js
Normal file
27
packages/db/test/basics.test.js
Normal 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');
|
||||
});
|
||||
});
|
||||
});
|
16
packages/db/test/fixtures/basics/astro.config.mjs
vendored
Normal file
16
packages/db/test/fixtures/basics/astro.config.mjs
vendored
Normal 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(),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
21
packages/db/test/fixtures/basics/db.seed.ts
vendored
Normal file
21
packages/db/test/fixtures/basics/db.seed.ts
vendored
Normal 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);
|
9
packages/db/test/fixtures/basics/package.json
vendored
Normal file
9
packages/db/test/fixtures/basics/package.json
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"name": "@test/db-aliases",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@astrojs/db": "workspace:*",
|
||||
"astro": "workspace:*"
|
||||
}
|
||||
}
|
11
packages/db/test/fixtures/basics/src/pages/index.astro
vendored
Normal file
11
packages/db/test/fixtures/basics/src/pages/index.astro
vendored
Normal 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>
|
Loading…
Reference in a new issue