diff options
author | 2024-05-22 09:16:49 +0100 | |
---|---|---|
committer | 2024-05-22 09:16:49 +0100 | |
commit | 05ef10cdc38878746c91e9032ccb57002ad66963 (patch) | |
tree | a12d925e7b54d6535dc5c1c2097fcefb3dd08aae /packages/db/test/basics.test.js | |
parent | 9ddd6387a7e70d1111dd4a60450d3c710325380c (diff) | |
download | astro-05ef10cdc38878746c91e9032ccb57002ad66963.tar.gz astro-05ef10cdc38878746c91e9032ccb57002ad66963.tar.zst astro-05ef10cdc38878746c91e9032ccb57002ad66963.zip |
chore(db): move tests to node runner (#11109)
Diffstat (limited to 'packages/db/test/basics.test.js')
-rw-r--r-- | packages/db/test/basics.test.js | 57 |
1 files changed, 37 insertions, 20 deletions
diff --git a/packages/db/test/basics.test.js b/packages/db/test/basics.test.js index d944b1c48..58e23ac7f 100644 --- a/packages/db/test/basics.test.js +++ b/packages/db/test/basics.test.js @@ -1,4 +1,5 @@ -import { expect } from 'chai'; +import { describe, it, before, after } from "node:test"; +import assert from "node:assert/strict"; import { load as cheerioLoad } from 'cheerio'; import testAdapter from '../../astro/test/test-adapter.js'; import { loadFixture } from '../../astro/test/test-utils.js'; @@ -30,8 +31,14 @@ describe('astro:db', () => { const $ = cheerioLoad(html); const ul = $('.authors-list'); - expect(ul.children()).to.have.a.lengthOf(5); - expect(ul.children().eq(0).text()).to.equal('Ben'); + assert.equal( + ul.children().length, + 5 + ); + assert.match( + ul.children().eq(0).text(), + /Ben/ + ) }); it('Allows expression defaults for date columns', async () => { @@ -39,7 +46,7 @@ describe('astro:db', () => { const $ = cheerioLoad(html); const themeAdded = $($('.themes-list .theme-added')[0]).text(); - expect(new Date(themeAdded).getTime()).to.not.be.NaN; + assert.equal(Number.isNaN(new Date(themeAdded).getTime()), false); }); it('Defaults can be overridden for dates', async () => { @@ -47,7 +54,7 @@ describe('astro:db', () => { const $ = cheerioLoad(html); const themeAdded = $($('.themes-list .theme-added')[1]).text(); - expect(new Date(themeAdded).getTime()).to.not.be.NaN; + assert.equal(Number.isNaN(new Date(themeAdded).getTime()), false); }); it('Allows expression defaults for text columns', async () => { @@ -55,7 +62,7 @@ describe('astro:db', () => { const $ = cheerioLoad(html); const themeOwner = $($('.themes-list .theme-owner')[0]).text(); - expect(themeOwner).to.equal(''); + assert.equal(themeOwner, ''); }); it('Allows expression defaults for boolean columns', async () => { @@ -63,20 +70,20 @@ describe('astro:db', () => { const $ = cheerioLoad(html); const themeDark = $($('.themes-list .theme-dark')[0]).text(); - expect(themeDark).to.equal('dark mode'); + assert.match(themeDark, /dark mode/); }); it('text fields an be used as references', async () => { const html = await fixture.fetch('/login').then((res) => res.text()); const $ = cheerioLoad(html); - expect($('.session-id').text()).to.equal('12345'); - expect($('.username').text()).to.equal('Mario'); + assert.match($('.session-id').text(), /12345/); + assert.match($('.username').text(), /Mario/); }); it('Prints authors from raw sql call', async () => { const json = await fixture.fetch('run.json').then((res) => res.json()); - expect(json).to.deep.equal({ + assert.deepEqual(json, { columns: ['_id', 'name', 'age2'], columnTypes: ['INTEGER', 'TEXT', 'INTEGER'], rows: [ @@ -111,8 +118,14 @@ describe('astro:db', () => { const $ = cheerioLoad(html); const ul = $('.authors-list'); - expect(ul.children()).to.have.a.lengthOf(5); - expect(ul.children().eq(0).text()).to.equal('Ben'); + assert.equal( + ul.children().length, + 5 + ); + assert.match( + ul.children().eq(0).text(), + /Ben/ + ) }); it('Allows expression defaults for date columns', async () => { @@ -120,7 +133,7 @@ describe('astro:db', () => { const $ = cheerioLoad(html); const themeAdded = $($('.themes-list .theme-added')[0]).text(); - expect(new Date(themeAdded).getTime()).to.not.be.NaN; + assert.equal(Number.isNaN(new Date(themeAdded).getTime()), false); }); it('Defaults can be overridden for dates', async () => { @@ -128,7 +141,7 @@ describe('astro:db', () => { const $ = cheerioLoad(html); const themeAdded = $($('.themes-list .theme-added')[1]).text(); - expect(new Date(themeAdded).getTime()).to.not.be.NaN; + assert.equal(Number.isNaN(new Date(themeAdded).getTime()), false); }); it('Allows expression defaults for text columns', async () => { @@ -136,7 +149,8 @@ describe('astro:db', () => { const $ = cheerioLoad(html); const themeOwner = $($('.themes-list .theme-owner')[0]).text(); - expect(themeOwner).to.equal(''); + assert.equal(themeOwner, ''); + }); it('Allows expression defaults for boolean columns', async () => { @@ -144,20 +158,21 @@ describe('astro:db', () => { const $ = cheerioLoad(html); const themeDark = $($('.themes-list .theme-dark')[0]).text(); - expect(themeDark).to.equal('dark mode'); + assert.match(themeDark, /dark mode/); + }); it('text fields an be used as references', async () => { const html = await fixture.fetch('/login').then((res) => res.text()); const $ = cheerioLoad(html); - expect($('.session-id').text()).to.equal('12345'); - expect($('.username').text()).to.equal('Mario'); + assert.match($('.session-id').text(), /12345/); + assert.match($('.username').text(), /Mario/); }); it('Prints authors from raw sql call', async () => { const json = await fixture.fetch('run.json').then((res) => res.json()); - expect(json).to.deep.equal({ + assert.deepEqual(json, { columns: ['_id', 'name', 'age2'], columnTypes: ['INTEGER', 'TEXT', 'INTEGER'], rows: [ @@ -195,7 +210,9 @@ describe('astro:db', () => { const $ = cheerioLoad(html); const ul = $('.authors-list'); - expect(ul.children()).to.have.a.lengthOf(5); + assert.equal( + ul.children().length,5 + ) }); }); }); |