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

chore: migrate alias tests to node:test (#10108)

This commit is contained in:
Atharva 2024-02-14 16:21:03 +05:30 committed by GitHub
parent 748b2e87cd
commit f7f20069c3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 48 additions and 45 deletions

View file

@ -1,4 +1,5 @@
import { expect } from 'chai';
import assert from 'node:assert/strict';
import { describe, before, it, after } from 'node:test';
import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';
@ -51,33 +52,33 @@ describe('Aliases with tsconfig.json - baseUrl only', () => {
const $ = cheerio.load(html);
// Should render aliased element
expect($('#client').text()).to.equal('test');
assert.equal($('#client').text(), 'test')
const scripts = $('script').toArray();
expect(scripts.length).to.be.greaterThan(0);
assert.ok(scripts.length > 0)
});
it('can load via baseUrl', async () => {
const html = await fixture.fetch('/').then((res) => res.text());
const $ = cheerio.load(html);
expect($('#foo').text()).to.equal('foo');
expect($('#constants-foo').text()).to.equal('foo');
expect($('#constants-index').text()).to.equal('index');
assert.equal($('#foo').text(), 'foo');
assert.equal($('#constants-foo').text(), 'foo');
assert.equal($('#constants-index').text(), 'index');
});
it('works in css @import', async () => {
const html = await fixture.fetch('/').then((res) => res.text());
// imported css should be bundled
expect(html).to.include('#style-red');
expect(html).to.include('#style-blue');
assert.ok(html.includes('#style-red'));
assert.ok(html.includes('#style-blue'));
});
it('works in components', async () => {
const html = await fixture.fetch('/').then((res) => res.text());
const $ = cheerio.load(html);
expect($('#alias').text()).to.equal('foo');
assert.equal($('#alias').text(), 'foo')
});
});
@ -91,19 +92,19 @@ describe('Aliases with tsconfig.json - baseUrl only', () => {
const $ = cheerio.load(html);
// Should render aliased element
expect($('#client').text()).to.equal('test');
assert.equal($('#client').text(), 'test')
const scripts = $('script').toArray();
expect(scripts.length).to.be.greaterThan(0);
assert.ok(scripts.length > 0)
});
it('can load via baseUrl', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
expect($('#foo').text()).to.equal('foo');
expect($('#constants-foo').text()).to.equal('foo');
expect($('#constants-index').text()).to.equal('index');
assert.equal($('#foo').text(), 'foo');
assert.equal($('#constants-foo').text(), 'foo');
assert.equal($('#constants-index').text(), 'index');
});
it('works in css @import', async () => {
@ -111,15 +112,15 @@ describe('Aliases with tsconfig.json - baseUrl only', () => {
const content = await Promise.all(getLinks(html).map((href) => getLinkContent(href)));
const [{ css }] = content;
// imported css should be bundled
expect(css).to.include('#style-red');
expect(css).to.include('#style-blue');
assert.ok(css.includes('#style-red'));
assert.ok(css.includes('#style-blue'));
});
it('works in components', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
expect($('#alias').text()).to.equal('foo');
assert.equal($('#alias').text(), 'foo')
});
});
});

View file

@ -1,4 +1,5 @@
import { expect } from 'chai';
import assert from 'node:assert/strict';
import { describe, before, it, after } from 'node:test';
import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';
@ -51,47 +52,47 @@ describe('Aliases with tsconfig.json', () => {
const $ = cheerio.load(html);
// Should render aliased element
expect($('#client').text()).to.equal('test');
assert.equal($('#client').text(), 'test');
const scripts = $('script').toArray();
expect(scripts.length).to.be.greaterThan(0);
assert.ok(scripts.length > 0);
});
it('can load via baseUrl', async () => {
const html = await fixture.fetch('/').then((res) => res.text());
const $ = cheerio.load(html);
expect($('#foo').text()).to.equal('foo');
expect($('#constants-foo').text()).to.equal('foo');
expect($('#constants-index').text()).to.equal('index');
assert.equal($('#foo').text(), 'foo');
assert.equal($('#constants-foo').text(), 'foo');
assert.equal($('#constants-index').text(), 'index');
});
it('can load namespace packages with @* paths', async () => {
const html = await fixture.fetch('/').then((res) => res.text());
const $ = cheerio.load(html);
expect($('#namespace').text()).to.equal('namespace');
assert.equal($('#namespace').text(), 'namespace');
});
it('works in css @import', async () => {
const html = await fixture.fetch('/').then((res) => res.text());
// imported css should be bundled
expect(html).to.include('#style-red');
expect(html).to.include('#style-blue');
assert.ok(html.includes('#style-red'));
assert.ok(html.includes('#style-blue'));
});
it('works in components', async () => {
const html = await fixture.fetch('/').then((res) => res.text());
const $ = cheerio.load(html);
expect($('#alias').text()).to.equal('foo');
assert.equal($('#alias').text(), 'foo');
});
it('works for import.meta.glob', async () => {
const html = await fixture.fetch('/').then((res) => res.text());
const $ = cheerio.load(html);
expect($('#glob').text()).to.equal('/src/components/glob/a.js');
assert.equal($('#glob').text(), '/src/components/glob/a.js');
});
});
@ -105,26 +106,26 @@ describe('Aliases with tsconfig.json', () => {
const $ = cheerio.load(html);
// Should render aliased element
expect($('#client').text()).to.equal('test');
assert.equal($('#client').text(), 'test');
const scripts = $('script').toArray();
expect(scripts.length).to.be.greaterThan(0);
assert.ok(scripts.length > 0);
});
it('can load via baseUrl', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
expect($('#foo').text()).to.equal('foo');
expect($('#constants-foo').text()).to.equal('foo');
expect($('#constants-index').text()).to.equal('index');
assert.equal($('#foo').text(), 'foo');
assert.equal($('#constants-foo').text(), 'foo');
assert.equal($('#constants-index').text(), 'index');
});
it('can load namespace packages with @* paths', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
expect($('#namespace').text()).to.equal('namespace');
assert.equal($('#namespace').text(), 'namespace');
});
it('works in css @import', async () => {
@ -132,22 +133,22 @@ describe('Aliases with tsconfig.json', () => {
const content = await Promise.all(getLinks(html).map((href) => getLinkContent(href)));
const [{ css }] = content;
// imported css should be bundled
expect(css).to.include('#style-red');
expect(css).to.include('#style-blue');
assert.ok(css.includes('#style-red'));
assert.ok(css.includes('#style-blue'));
});
it('works in components', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
expect($('#alias').text()).to.equal('foo');
assert.equal($('#alias').text(), 'foo');
});
it('works for import.meta.glob', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
expect($('#glob').text()).to.equal('/src/components/glob/a.js');
assert.equal($('#glob').text(), '/src/components/glob/a.js');
});
});
});

View file

@ -1,4 +1,5 @@
import { expect } from 'chai';
import assert from 'node:assert/strict';
import { describe, before, it, after } from 'node:test';
import * as cheerio from 'cheerio';
import { isWindows, loadFixture } from './test-utils.js';
@ -29,10 +30,10 @@ describe('Aliases', () => {
const $ = cheerio.load(html);
// Should render aliased element
expect($('#client').text()).to.equal('test');
assert.equal($('#client').text(), 'test');
const scripts = $('script').toArray();
expect(scripts.length).to.be.greaterThan(0);
assert.ok(scripts.length > 0);
});
});
@ -46,10 +47,10 @@ describe('Aliases', () => {
const $ = cheerio.load(html);
// Should render aliased element
expect($('#client').text()).to.equal('test');
assert.equal($('#client').text(), 'test');
const scripts = $('script').toArray();
expect(scripts.length).to.be.greaterThan(0);
assert.ok(scripts.length > 0);
});
it('can use aliases and relative in same project', async () => {
@ -57,10 +58,10 @@ describe('Aliases', () => {
const $ = cheerio.load(html);
// Should render aliased element
expect($('#client').text()).to.equal('test');
assert.equal($('#client').text(), 'test');
const scripts = $('script').toArray();
expect(scripts.length).to.be.greaterThan(0);
assert.ok(scripts.length > 0);
});
});
});