From f134358bcf29aed9e830acb18613645e0cc367df Mon Sep 17 00:00:00 2001 From: ktym4a Date: Thu, 15 Feb 2024 19:49:28 +0700 Subject: [PATCH] chore: move test to node (#10125) * chore: move test to node * `strictEqual` to `strict` --- ....js => get-static-paths-pages.nodetest.js} | 7 +++--- ...css.test.js => glob-pages-css.nodetest.js} | 5 ++-- ...ion.test.js => head-injection.nodetest.js} | 25 ++++++++++--------- ...ts.test.js => hoisted-imports.nodetest.js} | 7 +++--- ...ace.test.js => hydration-race.nodetest.js} | 11 ++++---- 5 files changed, 30 insertions(+), 25 deletions(-) rename packages/astro/test/{get-static-paths-pages.test.js => get-static-paths-pages.nodetest.js} (77%) rename packages/astro/test/{glob-pages-css.test.js => glob-pages-css.nodetest.js} (79%) rename packages/astro/test/{head-injection.test.js => head-injection.nodetest.js} (68%) rename packages/astro/test/{hoisted-imports.test.js => hoisted-imports.nodetest.js} (91%) rename packages/astro/test/{hydration-race.test.js => hydration-race.nodetest.js} (68%) diff --git a/packages/astro/test/get-static-paths-pages.test.js b/packages/astro/test/get-static-paths-pages.nodetest.js similarity index 77% rename from packages/astro/test/get-static-paths-pages.test.js rename to packages/astro/test/get-static-paths-pages.nodetest.js index dd8499ae42..b807310fcc 100644 --- a/packages/astro/test/get-static-paths-pages.test.js +++ b/packages/astro/test/get-static-paths-pages.nodetest.js @@ -1,4 +1,5 @@ -import { expect } from 'chai'; +import assert from 'node:assert/strict'; +import { describe, before, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; @@ -16,12 +17,12 @@ describe('getStaticPaths with trailingSlash: ignore', () => { it('includes index page', async () => { let html = await fixture.readFile('/index.html'); let $ = cheerio.load(html); - expect($('h1').text()).to.equal('Page 1'); + assert.equal($('h1').text(), 'Page 1'); }); it('includes paginated page', async () => { let html = await fixture.readFile('/2/index.html'); let $ = cheerio.load(html); - expect($('h1').text()).to.equal('Page 2'); + assert.equal($('h1').text(), 'Page 2'); }); }); diff --git a/packages/astro/test/glob-pages-css.test.js b/packages/astro/test/glob-pages-css.nodetest.js similarity index 79% rename from packages/astro/test/glob-pages-css.test.js rename to packages/astro/test/glob-pages-css.nodetest.js index 3c2bb5454e..85813029f5 100644 --- a/packages/astro/test/glob-pages-css.test.js +++ b/packages/astro/test/glob-pages-css.nodetest.js @@ -1,4 +1,5 @@ -import { expect } from 'chai'; +import assert from 'node:assert/strict'; +import { describe, before, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; @@ -18,6 +19,6 @@ describe('Astro.glob on pages/ directory', () => { let html = await fixture.readFile('/index.html'); let $ = cheerio.load(html); - expect($('link[rel=stylesheet]')).to.have.a.lengthOf(1); + assert.equal($('link[rel=stylesheet]').length, 1); }); }); diff --git a/packages/astro/test/head-injection.test.js b/packages/astro/test/head-injection.nodetest.js similarity index 68% rename from packages/astro/test/head-injection.test.js rename to packages/astro/test/head-injection.nodetest.js index 139c97005c..fc27da0e42 100644 --- a/packages/astro/test/head-injection.test.js +++ b/packages/astro/test/head-injection.nodetest.js @@ -1,4 +1,5 @@ -import { expect } from 'chai'; +import assert from 'node:assert/strict'; +import { describe, before, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; @@ -24,7 +25,7 @@ describe('Head injection', () => { const html = await fixture.readFile(`/index.html`); const $ = cheerio.load(html); - expect($('head link[rel=stylesheet]')).to.have.a.lengthOf(1); + assert.equal($('head link[rel=stylesheet]').length, 1); }); }); @@ -33,40 +34,40 @@ describe('Head injection', () => { const html = await fixture.readFile('/with-slot-in-slot/index.html'); const $ = cheerio.load(html); - expect($('head link[rel=stylesheet]')).to.have.a.lengthOf(1); - expect($('body link[rel=stylesheet]')).to.have.a.lengthOf(0); + assert.equal($('head link[rel=stylesheet]').length, 1); + assert.equal($('body link[rel=stylesheet]').length, 0); }); it('Using slots with Astro.slots.render()', async () => { const html = await fixture.readFile('/with-slot-render/index.html'); const $ = cheerio.load(html); - expect($('head link[rel=stylesheet]')).to.have.a.lengthOf(1); - expect($('body link[rel=stylesheet]')).to.have.a.lengthOf(0); + assert.equal($('head link[rel=stylesheet]').length, 1); + assert.equal($('body link[rel=stylesheet]').length, 0); }); it('Using slots within slots using Astro.slots.render()', async () => { const html = await fixture.readFile('/with-slot-in-render-slot/index.html'); const $ = cheerio.load(html); - expect($('head link[rel=stylesheet]')).to.have.a.lengthOf(2); - expect($('body link[rel=stylesheet]')).to.have.a.lengthOf(0); + assert.equal($('head link[rel=stylesheet]').length, 2); + assert.equal($('body link[rel=stylesheet]').length, 0); }); it('Using slots in Astro.slots.render() inside head buffering', async () => { const html = await fixture.readFile('/with-render-slot-in-head-buffer/index.html'); const $ = cheerio.load(html); - expect($('head link[rel=stylesheet]')).to.have.a.lengthOf(2); - expect($('body link[rel=stylesheet]')).to.have.a.lengthOf(0); + assert.equal($('head link[rel=stylesheet]').length, 2); + assert.equal($('body link[rel=stylesheet]').length, 0); }); it('Using slots with Astro.slots.render() (layout)', async () => { const html = await fixture.readFile('/with-slot-render2/index.html'); const $ = cheerio.load(html); - expect($('head link[rel=stylesheet]')).to.have.a.lengthOf(1); - expect($('body link[rel=stylesheet]')).to.have.a.lengthOf(0); + assert.equal($('head link[rel=stylesheet]').length, 1); + assert.equal($('body link[rel=stylesheet]').length, 0); }); }); }); diff --git a/packages/astro/test/hoisted-imports.test.js b/packages/astro/test/hoisted-imports.nodetest.js similarity index 91% rename from packages/astro/test/hoisted-imports.test.js rename to packages/astro/test/hoisted-imports.nodetest.js index 9fc76cac1e..b30351378f 100644 --- a/packages/astro/test/hoisted-imports.test.js +++ b/packages/astro/test/hoisted-imports.nodetest.js @@ -1,4 +1,5 @@ -import { expect } from 'chai'; +import assert from 'node:assert/strict'; +import { describe, before, it } from 'node:test'; import { loadFixture } from './test-utils.js'; import * as cheerio from 'cheerio'; @@ -52,11 +53,11 @@ describe('Hoisted Imports', () => { function expectScript(scripts, letter) { const regex = new RegExp(`console.log\\(['"]${letter}['"]\\)`); - expect(scripts, 'missing component ' + letter).to.match(regex); + assert.match(scripts, regex, 'missing component ' + letter); } function expectNotScript(scripts, letter) { const regex = new RegExp(`console.log\\(['"]${letter}['"]\\)`); - expect(scripts, "shouldn't include component " + letter).to.not.match(regex); + assert.doesNotMatch(scripts, regex, "shouldn't include component " + letter); } it('includes all imported scripts', async () => { diff --git a/packages/astro/test/hydration-race.test.js b/packages/astro/test/hydration-race.nodetest.js similarity index 68% rename from packages/astro/test/hydration-race.test.js rename to packages/astro/test/hydration-race.nodetest.js index d356815577..66e791bca9 100644 --- a/packages/astro/test/hydration-race.test.js +++ b/packages/astro/test/hydration-race.nodetest.js @@ -1,4 +1,5 @@ -import { expect } from 'chai'; +import assert from 'node:assert/strict'; +import { describe, before, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; @@ -15,15 +16,15 @@ describe('Hydration script ordering', async () => { let $ = cheerio.load(html); // First, let's make sure all islands rendered (or test is bad) - expect($('astro-island')).to.have.a.lengthOf(3); + assert.equal($('astro-island').length, 3); // Now let's make sure the hydration script is placed before the first component let firstIsland = $($('astro-island').get(0)); let prevSibling = firstIsland.prev(); - expect(prevSibling.prop('tagName')).to.equal('SCRIPT'); + assert.equal(prevSibling.prop('tagName'), 'SCRIPT'); // Sanity check that we're only rendering them once. - expect($('style')).to.have.a.lengthOf(1, 'hydration style added once'); - expect($('script')).to.have.a.lengthOf(1, 'only one hydration script needed'); + assert.equal($('style').length, 1, 'hydration style added once'); + assert.equal($('script').length, 1, 'only one hydration script needed'); }); });