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

chore: migrate vue related tests to node:test (#10061)

* chore: migarte slots-vue.testjs to node

* chore: migrate vue-**.test.js to node:test

* fix: add missing imports, remove expect script
This commit is contained in:
Atharva 2024-02-12 17:51:47 +05:30 committed by GitHub
parent 2a70113f7e
commit 116cfb63e3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 29 additions and 24 deletions

View file

@ -1,4 +1,5 @@
import { expect } from 'chai'; import assert from 'node:assert/strict';
import { before, describe, 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,43 +15,43 @@ describe('Slots: Vue', () => {
const html = await fixture.readFile('/index.html'); const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html); const $ = cheerio.load(html);
expect($('#default-self-closing').text().trim()).to.equal('Fallback'); assert.equal($('#default-self-closing').text().trim(), 'Fallback');
expect($('#default-empty').text().trim()).to.equal('Fallback'); assert.equal($('#default-empty').text().trim(), 'Fallback');
expect($('#zero').text().trim()).to.equal('0'); assert.equal($('#zero').text().trim(), '0');
expect($('#false').text().trim()).to.equal(''); assert.equal($('#false').text().trim(), '');
expect($('#string').text().trim()).to.equal(''); assert.equal($('#string').text().trim(), '');
expect($('#content').text().trim()).to.equal('Hello world!'); assert.equal($('#content').text().trim(), 'Hello world!');
}); });
it('Renders named slot', async () => { it('Renders named slot', async () => {
const html = await fixture.readFile('/index.html'); const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html); const $ = cheerio.load(html);
expect($('#named').text().trim()).to.equal('Fallback / Named'); assert.equal($('#named').text().trim(), 'Fallback / Named');
}); });
it('Preserves dash-case slot', async () => { it('Preserves dash-case slot', async () => {
const html = await fixture.readFile('/index.html'); const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html); const $ = cheerio.load(html);
expect($('#dash-case').text().trim()).to.equal('Fallback / Dash Case'); assert.equal($('#dash-case').text().trim(), 'Fallback / Dash Case');
}); });
describe('For MDX Pages', () => { describe('For MDX Pages', () => {
it('Renders default slot', async () => { it('Renders default slot', async () => {
const html = await fixture.readFile('/mdx/index.html'); const html = await fixture.readFile('/mdx/index.html');
const $ = cheerio.load(html); const $ = cheerio.load(html);
expect($('#content').text().trim()).to.equal('Hello world!'); assert.equal($('#content').text().trim(), 'Hello world!');
}); });
it('Renders named slot', async () => { it('Renders named slot', async () => {
const html = await fixture.readFile('/mdx/index.html'); const html = await fixture.readFile('/mdx/index.html');
const $ = cheerio.load(html); const $ = cheerio.load(html);
expect($('#named').text().trim()).to.equal('Fallback / Named'); assert.equal($('#named').text().trim(), 'Fallback / Named');
}); });
it('Converts dash-case slot to camelCase', async () => { it('Converts dash-case slot to camelCase', async () => {
const html = await fixture.readFile('/mdx/index.html'); const html = await fixture.readFile('/mdx/index.html');
const $ = cheerio.load(html); const $ = cheerio.load(html);
expect($('#dash-case').text().trim()).to.equal('Fallback / Dash Case'); assert.equal($('#dash-case').text().trim(), 'Fallback / Dash Case');
}); });
}); });
}); });

View file

@ -1,4 +1,5 @@
import { expect } from 'chai'; import assert from 'node:assert/strict';
import { before, describe, it, after } from 'node:test';
import * as cheerio from 'cheerio'; import * as cheerio from 'cheerio';
import { isWindows, loadFixture } from './test-utils.js'; import { isWindows, loadFixture } from './test-utils.js';
@ -25,23 +26,23 @@ describe('Vue component', () => {
.map((el) => $(el).text()); .map((el) => $(el).text());
// test 1: renders all components correctly // test 1: renders all components correctly
expect(allPreValues).to.deep.equal(['0', '1', '1', '1', '10', '100', '1000']); assert.deepEqual(allPreValues, ['0', '1', '1', '1', '10', '100', '1000']);
// test 2: renders 3 <astro-island>s // test 2: renders 3 <astro-island>s
expect($('astro-island')).to.have.lengthOf(6); assert.equal($('astro-island').length, 6);
// test 3: all <astro-island>s have uid attributes // test 3: all <astro-island>s have uid attributes
expect($('astro-island[uid]')).to.have.lengthOf(6); assert.equal($('astro-island[uid]').length, 6);
// test 4: treats <my-button> as a custom element // test 4: treats <my-button> as a custom element
expect($('my-button')).to.have.lengthOf(7); assert.equal($('my-button').length, 7);
// test 5: components with identical render output and props have been deduplicated // test 5: components with identical render output and props have been deduplicated
const uniqueRootUIDs = $('astro-island').map((i, el) => $(el).attr('uid')); const uniqueRootUIDs = $('astro-island').map((i, el) => $(el).attr('uid'));
expect(new Set(uniqueRootUIDs).size).to.equal(5); assert.equal(new Set(uniqueRootUIDs).size, 5);
// test 6: import public files work // test 6: import public files work
expect($('#vue-img')).to.be.ok; assert.ok($('#vue-img'));
}); });
}); });
@ -65,7 +66,8 @@ describe('Vue component', () => {
for (const script of $('script').toArray()) { for (const script of $('script').toArray()) {
const { src } = script.attribs; const { src } = script.attribs;
if (!src) continue; if (!src) continue;
expect((await fixture.fetch(src)).status, `404: ${src}`).to.equal(200); const response = await fixture.fetch(src);
assert.equal(response.status, 200, `404: ${src}`);
} }
}); });
}); });

View file

@ -1,4 +1,5 @@
import { expect } from 'chai'; import assert from 'node:assert/strict';
import { before, describe, 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';
@ -24,7 +25,7 @@ describe('Vue JSX', () => {
.toArray() .toArray()
.map((el) => $(el).text()); .map((el) => $(el).text());
expect(allPreValues).to.deep.equal(['2345', '0', '1', '1', '1', '10', '100', '1000']); assert.deepEqual(allPreValues, ['2345', '0', '1', '1', '1', '10', '100', '1000']);
}); });
}); });
}); });

View file

@ -1,4 +1,5 @@
import { expect } from 'chai'; import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import { loadFixture } from './test-utils.js'; import { loadFixture } from './test-utils.js';
describe('Vue with multi-renderer', () => { describe('Vue with multi-renderer', () => {
@ -14,7 +15,7 @@ describe('Vue with multi-renderer', () => {
try { try {
await fixture.build(); await fixture.build();
} catch (e) { } catch (e) {
expect(e).to.equal(undefined, `Should not throw`); assert.equal(e, undefined, `Should not throw`)
} }
}); });
}); });