diff --git a/packages/db/test/basics.test.js b/packages/db/test/basics.test.js new file mode 100644 index 0000000000..a3547cf2ff --- /dev/null +++ b/packages/db/test/basics.test.js @@ -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'); + }); + }); +}); diff --git a/packages/db/test/fixtures/basics/astro.config.mjs b/packages/db/test/fixtures/basics/astro.config.mjs new file mode 100644 index 0000000000..7941a2210a --- /dev/null +++ b/packages/db/test/fixtures/basics/astro.config.mjs @@ -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(), + }, + } + } + } +}); diff --git a/packages/db/test/fixtures/basics/db.seed.ts b/packages/db/test/fixtures/basics/db.seed.ts new file mode 100644 index 0000000000..cd1cd89492 --- /dev/null +++ b/packages/db/test/fixtures/basics/db.seed.ts @@ -0,0 +1,21 @@ +import { Author, db } from 'astro:db'; + +const authors: Array = [ + { + name: 'Ben', + }, + { + title: 'Nate', + }, + { + title: 'Erika', + }, + { + title: 'Bjorn', + }, + { + title: 'Sarah', + }, +]; + +await db.insert(Author).values(authors); diff --git a/packages/db/test/fixtures/basics/package.json b/packages/db/test/fixtures/basics/package.json new file mode 100644 index 0000000000..f537f998df --- /dev/null +++ b/packages/db/test/fixtures/basics/package.json @@ -0,0 +1,9 @@ +{ + "name": "@test/db-aliases", + "version": "0.0.0", + "private": true, + "dependencies": { + "@astrojs/db": "workspace:*", + "astro": "workspace:*" + } +} diff --git a/packages/db/test/fixtures/basics/src/pages/index.astro b/packages/db/test/fixtures/basics/src/pages/index.astro new file mode 100644 index 0000000000..d3e1ecf715 --- /dev/null +++ b/packages/db/test/fixtures/basics/src/pages/index.astro @@ -0,0 +1,11 @@ +--- +import { Author, db } from 'astro:db'; + +const authors = await db.select().from(Author); +--- + +