0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-02-17 22:44:24 -05:00

chore: Migrate some astro-*.test.js to node:test (#10085)

Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
This commit is contained in:
Mohamed 2024-02-12 16:09:45 +02:00 committed by GitHub
parent a006d44993
commit 1b528d2e50
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 136 additions and 126 deletions

View file

@ -1,4 +1,5 @@
import { expect, assert } from 'chai'; import assert from 'node:assert/strict';
import { after, describe, before, it } from 'node:test';
import { loadFixture } from './test-utils.js'; import { loadFixture } from './test-utils.js';
// Asset bundling // Asset bundling
@ -23,8 +24,9 @@ describe('Not returning responses', () => {
try { try {
await fixture.build(); await fixture.build();
} catch (e) { } catch (e) {
expect(e).to.be.instanceOf( assert.equal(
Error, e instanceof Error,
true,
'Only instance of Response can be returned from an Astro file' 'Only instance of Response can be returned from an Astro file'
); );
return null; return null;

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 { loadFixture } from './test-utils.js';
describe('build format', () => { describe('build format', () => {
@ -17,9 +18,9 @@ describe('build format', () => {
}); });
it('outputs', async () => { it('outputs', async () => {
expect(await fixture.readFile('/client.html')).to.be.ok; assert.ok(await fixture.readFile('/client.html'));
expect(await fixture.readFile('/nested-md.html')).to.be.ok; assert.ok(await fixture.readFile('/nested-md.html'));
expect(await fixture.readFile('/nested-astro.html')).to.be.ok; assert.ok(await fixture.readFile('/nested-astro.html'));
}); });
}); });
@ -38,9 +39,9 @@ describe('build format', () => {
}); });
it('outputs', async () => { it('outputs', async () => {
expect(await fixture.readFile('/client.html')).to.be.ok; assert.ok(await fixture.readFile('/client.html'));
expect(await fixture.readFile('/nested-md/index.html')).to.be.ok; assert.ok(await fixture.readFile('/nested-md/index.html'));
expect(await fixture.readFile('/nested-astro/index.html')).to.be.ok; assert.ok(await fixture.readFile('/nested-astro/index.html'));
}); });
}); });
}); });

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 * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js'; import { loadFixture } from './test-utils.js';
@ -26,7 +27,7 @@ describe('Pagination root', () => {
Object.entries(prevMap).map(async ([curr, prev]) => { Object.entries(prevMap).map(async ([curr, prev]) => {
const html = await fixture.readFile(curr + 'index.html'); const html = await fixture.readFile(curr + 'index.html');
const $ = cheerio.load(html); const $ = cheerio.load(html);
expect($('#prev').attr('href')).to.equal(prev); assert.equal($('#prev').attr('href'), prev);
}) })
); );
}); });

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 * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js'; import { loadFixture } from './test-utils.js';
@ -20,7 +21,7 @@ describe('Pagination', () => {
'/posts/optional-root-page/2/index.html', '/posts/optional-root-page/2/index.html',
'/posts/optional-root-page/3/index.html', '/posts/optional-root-page/3/index.html',
]) { ]) {
expect(await fixture.readFile(file)).to.be.ok; assert.ok(await fixture.readFile(file));
} }
}); });
@ -30,7 +31,7 @@ describe('Pagination', () => {
'/posts/named-root-page/2/index.html', '/posts/named-root-page/2/index.html',
'/posts/named-root-page/3/index.html', '/posts/named-root-page/3/index.html',
]) { ]) {
expect(await fixture.readFile(file)).to.be.ok; assert.ok(await fixture.readFile(file));
} }
}); });
@ -44,24 +45,24 @@ describe('Pagination', () => {
params.map(async ({ color, p }) => { params.map(async ({ color, p }) => {
const html = await fixture.readFile(`/posts/${color}/${p}/index.html`); const html = await fixture.readFile(`/posts/${color}/${p}/index.html`);
const $ = cheerio.load(html); const $ = cheerio.load(html);
expect($('#page-param').text()).to.equal(p); assert.equal($('#page-param').text(), p);
expect($('#currentPage').text()).to.equal(p); assert.equal($('#currentPage').text(), p);
expect($('#filter').text()).to.equal(color); assert.equal($('#filter').text(), color);
const prevHref = $('#prev').attr('href'); const prevHref = $('#prev').attr('href');
const nextHref = $('#next').attr('href'); const nextHref = $('#next').attr('href');
if (color === 'red') { if (color === 'red') {
expect(prevHref).to.be.undefined; assert.equal(prevHref, undefined);
expect(nextHref).to.be.undefined; assert.equal(nextHref, undefined);
} }
if (color === 'blue' && p === '1') { if (color === 'blue' && p === '1') {
expect(prevHref).to.be.undefined; assert.equal(prevHref, undefined);
expect(nextHref).to.equal('/posts/blue/2'); assert.equal(nextHref, '/posts/blue/2');
} }
if (color === 'blue' && p === '2') { if (color === 'blue' && p === '2') {
expect(prevHref).to.equal('/posts/blue/1'); assert.equal(prevHref, '/posts/blue/1');
expect(nextHref).to.be.undefined; assert.equal(nextHref, undefined);
} }
}) })
); );

View file

@ -0,0 +1,19 @@
import assert from 'node:assert/strict';
import { describe, before, it } from 'node:test';
import { loadFixture } from './test-utils.js';
describe('Public', () => {
let fixture;
before(async () => {
fixture = await loadFixture({ root: './fixtures/astro-public/' });
await fixture.build();
});
it('css and js files do not get bundled', async () => {
let indexHtml = await fixture.readFile('/index.html');
assert.equal(indexHtml.includes('<script src="/example.js"></script>'), true);
assert.equal(indexHtml.includes('<link href="/example.css" rel="stylesheet">'), true);
assert.equal(indexHtml.includes('<img src="/images/twitter.png">'), true);
});
});

View file

@ -1,18 +0,0 @@
import { expect } from 'chai';
import { loadFixture } from './test-utils.js';
describe('Public', () => {
let fixture;
before(async () => {
fixture = await loadFixture({ root: './fixtures/astro-public/' });
await fixture.build();
});
it('css and js files do not get bundled', async () => {
let indexHtml = await fixture.readFile('/index.html');
expect(indexHtml).to.include('<script src="/example.js"></script>');
expect(indexHtml).to.include('<link href="/example.css" rel="stylesheet">');
expect(indexHtml).to.include('<img src="/images/twitter.png">');
});
});

View file

@ -1,4 +1,5 @@
import { expect } from 'chai'; import assert from 'node:assert/strict';
import { after, describe, before, it } from 'node:test';
import { loadFixture } from './test-utils.js'; import { loadFixture } from './test-utils.js';
// Asset bundling // Asset bundling
@ -21,6 +22,6 @@ describe('Returning responses', () => {
it('Works from a page', async () => { it('Works from a page', async () => {
let response = await fixture.fetch('/not-found'); let response = await fixture.fetch('/not-found');
expect(response.status).to.equal(404); assert.equal(response.status, 404);
}); });
}); });

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 * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js'; import { loadFixture } from './test-utils.js';
@ -14,12 +15,12 @@ describe('Slots with client: directives', () => {
it('Tags of dynamic tags works', async () => { it('Tags of dynamic tags works', async () => {
const html = await fixture.readFile('/index.html'); const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html); const $ = cheerio.load(html);
expect($('script')).to.have.a.lengthOf(1); assert.equal($('script').length, 1);
}); });
it('Astro slot tags are cleaned', async () => { it('Astro slot tags are cleaned', async () => {
const html = await fixture.readFile('/index.html'); const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html); const $ = cheerio.load(html);
expect($('astro-slot')).to.have.a.lengthOf(0); assert.equal($('astro-slot').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 * as cheerio from 'cheerio'; import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js'; import { loadFixture } from './test-utils.js';
@ -14,59 +15,59 @@ describe('Slots', () => {
const html = await fixture.readFile('/index.html'); const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html); const $ = cheerio.load(html);
expect($('#a').text().trim()).to.equal('A'); assert.equal($('#a').text().trim(), 'A');
expect($('#b').text().trim()).to.equal('B'); assert.equal($('#b').text().trim(), 'B');
expect($('#c').text().trim()).to.equal('C'); assert.equal($('#c').text().trim(), 'C');
expect($('#default').text().trim()).to.equal('Default'); assert.equal($('#default').text().trim(), 'Default');
}); });
it('Dynamic named slots work', async () => { it('Dynamic named slots work', async () => {
const html = await fixture.readFile('/dynamic/index.html'); const html = await fixture.readFile('/dynamic/index.html');
const $ = cheerio.load(html); const $ = cheerio.load(html);
expect($('#a').text().trim()).to.equal('A'); assert.equal($('#a').text().trim(), 'A');
expect($('#b').text().trim()).to.equal('B'); assert.equal($('#b').text().trim(), 'B');
expect($('#c').text().trim()).to.equal('C'); assert.equal($('#c').text().trim(), 'C');
expect($('#default').text().trim()).to.equal('Default'); assert.equal($('#default').text().trim(), 'Default');
}); });
it('Conditional named slots work', async () => { it('Conditional named slots work', async () => {
const html = await fixture.readFile('/conditional/index.html'); const html = await fixture.readFile('/conditional/index.html');
const $ = cheerio.load(html); const $ = cheerio.load(html);
expect($('#a').text().trim()).to.equal('A'); assert.equal($('#a').text().trim(), 'A');
expect($('#b').text().trim()).to.equal('B'); assert.equal($('#b').text().trim(), 'B');
expect($('#c').text().trim()).to.equal('C'); assert.equal($('#c').text().trim(), 'C');
expect($('#default').text().trim()).to.equal('Default'); assert.equal($('#default').text().trim(), 'Default');
}); });
it('Slots of a component render fallback content by default', async () => { it('Slots of a component render fallback content by default', async () => {
const html = await fixture.readFile('/fallback/index.html'); const html = await fixture.readFile('/fallback/index.html');
const $ = cheerio.load(html); const $ = cheerio.load(html);
expect($('#default')).to.have.lengthOf(1); assert.equal($('#default').length, 1);
}); });
it('Slots of a page render fallback content', async () => { it('Slots of a page render fallback content', async () => {
const html = await fixture.readFile('/fallback-own/index.html'); const html = await fixture.readFile('/fallback-own/index.html');
const $ = cheerio.load(html); const $ = cheerio.load(html);
expect($('#default')).to.have.lengthOf(1); assert.equal($('#default').length, 1);
}); });
it('Slots override fallback content', async () => { it('Slots override fallback content', async () => {
const html = await fixture.readFile('/fallback-override/index.html'); const html = await fixture.readFile('/fallback-override/index.html');
const $ = cheerio.load(html); const $ = cheerio.load(html);
expect($('#override')).to.have.lengthOf(1); assert.equal($('#override').length, 1);
expect($('#fallback-2').text()).to.equal('Slotty slot.'); assert.equal($('#fallback-2').text(), 'Slotty slot.');
}); });
it('Slots work with multiple elements', async () => { it('Slots work with multiple elements', async () => {
const html = await fixture.readFile('/multiple/index.html'); const html = await fixture.readFile('/multiple/index.html');
const $ = cheerio.load(html); const $ = cheerio.load(html);
expect($('#a').text().trim()).to.equal('ABC'); assert.equal($('#a').text().trim(), 'ABC');
}); });
it('Slots work on Components', async () => { it('Slots work on Components', async () => {
@ -74,13 +75,12 @@ describe('Slots', () => {
const $ = cheerio.load(html); const $ = cheerio.load(html);
// test 1: #a renders // test 1: #a renders
expect($('#a')).to.have.lengthOf(1); assert.equal($('#a').length, 1);
// test 2: Slotted component into #a // test 2: Slotted component into #a
expect($('#a').children('astro-component')).to.have.lengthOf(1); assert.equal($('#a').children('astro-component').length, 1);
// test 3: Slotted component into default slot // test 3: Slotted component into default slot
expect($('#default').children('astro-component')).to.have.lengthOf(1); assert.equal($('#default').children('astro-component').length, 1);
}); });
describe('Slots API work on Components', () => { describe('Slots API work on Components', () => {
@ -88,42 +88,42 @@ describe('Slots', () => {
const html = await fixture.readFile('/slottedapi-default/index.html'); const html = await fixture.readFile('/slottedapi-default/index.html');
const $ = cheerio.load(html); const $ = cheerio.load(html);
expect($('#a')).to.have.lengthOf(1); assert.equal($('#a').length, 1);
expect($('#b')).to.have.lengthOf(1); assert.equal($('#b').length, 1);
expect($('#c')).to.have.lengthOf(1); assert.equal($('#c').length, 1);
expect($('#default')).to.have.lengthOf(1); assert.equal($('#default').length, 1);
}); });
it('IDs will not exist because the slots are not filled', async () => { it('IDs will not exist because the slots are not filled', async () => {
const html = await fixture.readFile('/slottedapi-empty/index.html'); const html = await fixture.readFile('/slottedapi-empty/index.html');
const $ = cheerio.load(html); const $ = cheerio.load(html);
expect($('#a')).to.have.lengthOf(0); assert.equal($('#a').length, 0);
expect($('#b')).to.have.lengthOf(0); assert.equal($('#b').length, 0);
expect($('#c')).to.have.lengthOf(0); assert.equal($('#c').length, 0);
expect($('#default')).to.have.lengthOf(0); assert.equal($('#default').length, 0);
}); });
it('IDs will exist because the slots are filled', async () => { it('IDs will exist because the slots are filled', async () => {
const html = await fixture.readFile('/slottedapi-filled/index.html'); const html = await fixture.readFile('/slottedapi-filled/index.html');
const $ = cheerio.load(html); const $ = cheerio.load(html);
expect($('#a')).to.have.lengthOf(1); assert.equal($('#a').length, 1);
expect($('#b')).to.have.lengthOf(1); assert.equal($('#b').length, 1);
expect($('#c')).to.have.lengthOf(1); assert.equal($('#c').length, 1);
expect($('#default')).to.have.lengthOf(0); // the default slot is not filled assert.equal($('#default').length, 0); // the default slot is not filled
}); });
it('Default ID will exist because the default slot is filled', async () => { it('Default ID will exist because the default slot is filled', async () => {
const html = await fixture.readFile('/slottedapi-default-filled/index.html'); const html = await fixture.readFile('/slottedapi-default-filled/index.html');
const $ = cheerio.load(html); const $ = cheerio.load(html);
expect($('#a')).to.have.lengthOf(0); assert.equal($('#a').length, 0);
expect($('#b')).to.have.lengthOf(0); assert.equal($('#b').length, 0);
expect($('#c')).to.have.lengthOf(0); assert.equal($('#c').length, 0);
expect($('#default')).to.have.lengthOf(1); // the default slot is filled assert.equal($('#default').length, 1); // the default slot is not filled
}); });
}); });
@ -133,8 +133,8 @@ describe('Slots', () => {
const html = await fixture.readFile('/slottedapi-render/index.html'); const html = await fixture.readFile('/slottedapi-render/index.html');
const $ = cheerio.load(html); const $ = cheerio.load(html);
expect($('#render')).to.have.lengthOf(1); assert.equal($('#render').length, 1);
expect($('#render').text()).to.equal('render'); assert.equal($('#render').text(), 'render');
} }
// Child function render without args // Child function render without args
@ -142,8 +142,8 @@ describe('Slots', () => {
const html = await fixture.readFile('/slottedapi-render/index.html'); const html = await fixture.readFile('/slottedapi-render/index.html');
const $ = cheerio.load(html); const $ = cheerio.load(html);
expect($('#render-fn')).to.have.lengthOf(1); assert.equal($('#render-fn').length, 1);
expect($('#render-fn').text()).to.equal('render-fn'); assert.equal($('#render-fn').text(), 'render-fn');
} }
// Child function render with args // Child function render with args
@ -151,9 +151,9 @@ describe('Slots', () => {
const html = await fixture.readFile('/slottedapi-render/index.html'); const html = await fixture.readFile('/slottedapi-render/index.html');
const $ = cheerio.load(html); const $ = cheerio.load(html);
expect($('#render-args')).to.have.lengthOf(1); assert.equal($('#render-args').length, 1);
expect($('#render-args span')).to.have.lengthOf(1); assert.equal($('#render-args span').length, 1);
expect($('#render-args').text()).to.equal('render-args'); assert.equal($('#render-args').text(), 'render-args');
} }
{ {
@ -161,13 +161,13 @@ describe('Slots', () => {
const $ = cheerio.load(html); const $ = cheerio.load(html);
const elements = $('div'); const elements = $('div');
expect(elements).to.have.lengthOf(10); assert.equal(elements.length, 10);
const [first, second, third] = elements; const [first, second, third] = elements;
expect(first.children[0].data).to.not.equal(second.children[0].data); assert.notEqual(first.children[0].data, second.children[0].data);
expect(second.children[0].data).to.not.equal(third.children[0].data); assert.notEqual(second.children[0].data, third.children[0].data);
expect(third.children[0].data).to.not.equal(first.children[0].data); assert.notEqual(third.children[0].data, first.children[0].data);
} }
}); });
}); });

View file

@ -1,4 +1,5 @@
import { expect } from 'chai'; import assert from 'node:assert/strict';
import { after, describe, before, it } from 'node:test';
import * as cheerio from 'cheerio'; import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js'; import { loadFixture } from './test-utils.js';
import { preact } from './fixtures/before-hydration/deps.mjs'; import { preact } from './fixtures/before-hydration/deps.mjs';
@ -43,7 +44,7 @@ describe('Astro Scripts before-hydration', () => {
let res = await fixture.fetch('/'); let res = await fixture.fetch('/');
let html = await res.text(); let html = await res.text();
let $ = cheerio.load(html); let $ = cheerio.load(html);
expect($('astro-island[before-hydration-url]')).has.a.lengthOf(1); assert.equal($('astro-island[before-hydration-url]').length, 1);
}); });
}); });
@ -55,7 +56,7 @@ describe('Astro Scripts before-hydration', () => {
it('Is included in the astro-island', async () => { it('Is included in the astro-island', async () => {
let html = await fixture.readFile('/index.html'); let html = await fixture.readFile('/index.html');
let $ = cheerio.load(html); let $ = cheerio.load(html);
expect($('astro-island[before-hydration-url]')).has.a.lengthOf(1); assert.equal($('astro-island[before-hydration-url]').length, 1);
}); });
}); });
}); });
@ -86,7 +87,7 @@ describe('Astro Scripts before-hydration', () => {
let res = await fixture.fetch('/'); let res = await fixture.fetch('/');
let html = await res.text(); let html = await res.text();
let $ = cheerio.load(html); let $ = cheerio.load(html);
expect($('astro-island[before-hydration-url]')).has.a.lengthOf(1); assert.equal($('astro-island[before-hydration-url]').length, 1);
}); });
}); });
@ -98,7 +99,7 @@ describe('Astro Scripts before-hydration', () => {
it('Does not include before-hydration-url on the astro-island', async () => { it('Does not include before-hydration-url on the astro-island', async () => {
let html = await fixture.readFile('/index.html'); let html = await fixture.readFile('/index.html');
let $ = cheerio.load(html); let $ = cheerio.load(html);
expect($('astro-island[before-hydration-url]')).has.a.lengthOf(0); assert.equal($('astro-island[before-hydration-url]').length, 0);
}); });
}); });
}); });
@ -139,7 +140,7 @@ describe('Astro Scripts before-hydration', () => {
let response = await app.render(request); let response = await app.render(request);
let html = await response.text(); let html = await response.text();
let $ = cheerio.load(html); let $ = cheerio.load(html);
expect($('astro-island[before-hydration-url]')).has.a.lengthOf(1); assert.equal($('astro-island[before-hydration-url]').length, 1);
}); });
}); });
}); });
@ -167,7 +168,7 @@ describe('Astro Scripts before-hydration', () => {
let response = await app.render(request); let response = await app.render(request);
let html = await response.text(); let html = await response.text();
let $ = cheerio.load(html); let $ = cheerio.load(html);
expect($('astro-island[before-hydration-url]')).has.a.lengthOf(0); assert.equal($('astro-island[before-hydration-url]').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 * as cheerio from 'cheerio'; import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js'; import { loadFixture } from './test-utils.js';
import { preact } from './fixtures/before-hydration/deps.mjs'; import { preact } from './fixtures/before-hydration/deps.mjs';
@ -21,13 +22,13 @@ describe('build assets (static)', () => {
it('Populates /_astro directory', async () => { it('Populates /_astro directory', async () => {
let files = await fixture.readdir('/_astro'); let files = await fixture.readdir('/_astro');
expect(files.length).to.be.greaterThan(0); assert.equal(files.length > 0, true);
}); });
it('Defaults to flat /_astro output', async () => { it('Defaults to flat /_astro output', async () => {
let files = await fixture.readdir('/_astro'); let files = await fixture.readdir('/_astro');
for (const file of files) { for (const file of files) {
expect(file.slice(1)).to.not.contain('/'); assert.equal(file.slice(1).includes('/'), false);
} }
}); });
@ -35,7 +36,7 @@ describe('build assets (static)', () => {
let html = await fixture.readFile('/index.html'); let html = await fixture.readFile('/index.html');
let $ = cheerio.load(html); let $ = cheerio.load(html);
expect($('link[href$=".css"]').attr('href')).to.match(/^\/_astro\//); assert.match($('link[href$=".css"]').attr('href'), /^\/_astro\//);
}); });
it('emits JS assets to /_astro', async () => { it('emits JS assets to /_astro', async () => {
@ -43,9 +44,9 @@ describe('build assets (static)', () => {
let $ = cheerio.load(html); let $ = cheerio.load(html);
const island = $('astro-island'); const island = $('astro-island');
expect(island.length).to.eq(1); assert.equal(island.length, 1);
expect(island.attr('component-url')).to.match(/^\/_astro\//); assert.match(island.attr('component-url'), /^\/_astro\//);
expect(island.attr('renderer-url')).to.match(/^\/_astro\//); assert.match(island.attr('renderer-url'), /^\/_astro\//);
}); });
}); });
@ -67,14 +68,14 @@ describe('build assets (static)', () => {
it('Populates /custom-assets directory', async () => { it('Populates /custom-assets directory', async () => {
let files = await fixture.readdir('/custom-assets'); let files = await fixture.readdir('/custom-assets');
expect(files.length).to.be.greaterThan(0); assert.equal(files.length > 0, true);
}); });
it('emits CSS assets to /custom-assets', async () => { it('emits CSS assets to /custom-assets', async () => {
let html = await fixture.readFile('/index.html'); let html = await fixture.readFile('/index.html');
let $ = cheerio.load(html); let $ = cheerio.load(html);
expect($('link[href$=".css"]').attr('href')).to.match(/^\/custom-assets\//); assert.match($('link[href$=".css"]').attr('href'), /^\/custom-assets\//);
}); });
it('emits JS assets to /custom-assets', async () => { it('emits JS assets to /custom-assets', async () => {
@ -82,9 +83,9 @@ describe('build assets (static)', () => {
let $ = cheerio.load(html); let $ = cheerio.load(html);
const island = $('astro-island'); const island = $('astro-island');
expect(island.length).to.eq(1); assert.equal(island.length, 1);
expect(island.attr('component-url')).to.match(/^\/custom-assets\//); assert.match(island.attr('component-url'), /^\/custom-assets\//);
expect(island.attr('renderer-url')).to.match(/^\/custom-assets\//); assert.match(island.attr('renderer-url'), /^\/custom-assets\//);
}); });
}); });
}); });
@ -107,13 +108,13 @@ describe('build assets (server)', () => {
it('Populates /_astro directory', async () => { it('Populates /_astro directory', async () => {
let files = await fixture.readdir('/_astro'); let files = await fixture.readdir('/_astro');
expect(files.length).to.be.greaterThan(0); assert.equal(files.length > 0, true);
}); });
it('Defaults to flat /_astro output', async () => { it('Defaults to flat /_astro output', async () => {
let files = await fixture.readdir('/_astro'); let files = await fixture.readdir('/_astro');
for (const file of files) { for (const file of files) {
expect(file.slice(1)).to.not.contain('/'); assert.equal(file.slice(1).includes('/'), false);
} }
}); });
@ -121,7 +122,7 @@ describe('build assets (server)', () => {
let html = await fixture.readFile('/index.html'); let html = await fixture.readFile('/index.html');
let $ = cheerio.load(html); let $ = cheerio.load(html);
expect($('link[href$=".css"]').attr('href')).to.match(/^\/_astro\//); assert.match($('link[href$=".css"]').attr('href'), /^\/_astro\//);
}); });
it('emits JS assets to /_astro', async () => { it('emits JS assets to /_astro', async () => {
@ -129,9 +130,9 @@ describe('build assets (server)', () => {
let $ = cheerio.load(html); let $ = cheerio.load(html);
const island = $('astro-island'); const island = $('astro-island');
expect(island.length).to.eq(1); assert.equal(island.length, 1);
expect(island.attr('component-url')).to.match(/^\/_astro\//); assert.match(island.attr('component-url'), /^\/_astro\//);
expect(island.attr('renderer-url')).to.match(/^\/_astro\//); assert.match(island.attr('renderer-url'), /^\/_astro\//);
}); });
}); });
@ -154,14 +155,14 @@ describe('build assets (server)', () => {
it('Populates /custom-assets directory', async () => { it('Populates /custom-assets directory', async () => {
let files = await fixture.readdir('/custom-assets'); let files = await fixture.readdir('/custom-assets');
expect(files.length).to.be.greaterThan(0); assert.equal(files.length > 0, true);
}); });
it('emits CSS assets to /custom-assets', async () => { it('emits CSS assets to /custom-assets', async () => {
let html = await fixture.readFile('/index.html'); let html = await fixture.readFile('/index.html');
let $ = cheerio.load(html); let $ = cheerio.load(html);
expect($('link[href$=".css"]').attr('href')).to.match(/^\/custom-assets\//); assert.match($('link[href$=".css"]').attr('href'), /^\/custom-assets\//);
}); });
it('emits JS assets to /custom-assets', async () => { it('emits JS assets to /custom-assets', async () => {
@ -169,9 +170,9 @@ describe('build assets (server)', () => {
let $ = cheerio.load(html); let $ = cheerio.load(html);
const island = $('astro-island'); const island = $('astro-island');
expect(island.length).to.eq(1); assert.equal(island.length, 1);
expect(island.attr('component-url')).to.match(/^\/custom-assets\//); assert.match(island.attr('component-url'), /^\/custom-assets\//);
expect(island.attr('renderer-url')).to.match(/^\/custom-assets\//); assert.match(island.attr('renderer-url'), /^\/custom-assets\//);
}); });
}); });
}); });