0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

chore: move test to node (#10125)

* chore: move test to node

* `strictEqual` to `strict`
This commit is contained in:
ktym4a 2024-02-15 19:49:28 +07:00 committed by GitHub
parent 9eb37a31a7
commit f134358bcf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 30 additions and 25 deletions

View file

@ -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');
});
});

View file

@ -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);
});
});

View file

@ -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);
});
});
});

View file

@ -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 () => {

View file

@ -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');
});
});