import * as assert from 'node:assert/strict'; import { after, before, describe, it } from 'node:test'; import { parseHTML } from 'linkedom'; import { type DevServer, type Fixture, loadFixture } from './test-utils.ts'; describe('Basics', () => { let fixture: Fixture; before(async () => { fixture = await loadFixture({ root: './fixtures/basics/', }); await fixture.build(); }); it('Slots are added without the slot attribute', async () => { const data = await fixture.readFile('/index.html'); const { document } = parseHTML(data); const bar = document.querySelector('#foo')!; assert.notEqual(bar, undefined); assert.equal(bar.getAttribute('slot'), null); }); it('Can show images from public', async () => { const data = await fixture.readFile('/public/index.html'); const { document } = parseHTML(data); const img = document.querySelector('img')!; assert.notEqual(img, undefined); assert.equal(img.getAttribute('src'), '/light_walrus.avif'); }); it('Should generate unique ids when using useId()', async () => { const data = await fixture.readFile('/index.html'); const { document } = parseHTML(data); const els = document.querySelectorAll('.vue-use-id'); assert.equal(els.length, 2); assert.notEqual(els[0].getAttribute('id'), els[1].getAttribute('id')); }); it('Can load Vue JSX', async () => { const data = await fixture.readFile('/jsx/index.html'); const { document } = parseHTML(data); const allPreValues = [...document.querySelectorAll('pre')].map((e) => e.textContent); assert.deepEqual(allPreValues, ['2345', '0', '1', '1', '1', '10', '100', '1000']); }); describe('dev', () => { let devServer: DevServer; before(async () => { devServer = await fixture.startDevServer(); }); after(async () => { await devServer.stop(); }); it('starts with Vue devtools enabled', async () => { const response = await fixture.fetch('/'); assert.equal(response.status, 200); }); it('inlines Vue scoped styles transformed by the Vue plugin', async () => { const html = await fixture.fetch('/scoped-style').then((res) => res.text()); const { document } = parseHTML(html); const css = [...document.querySelectorAll('style[data-vite-dev-id]')] .filter((style) => style.getAttribute('data-vite-dev-id')!.includes('ScopedStyle.vue')) .map((style) => style.textContent) .join(''); assert.match(css, /\.box\[data-v-[a-z0-9]+\]/); assert.doesNotMatch(css, /v-bind/); }); }); });