2024-01-31 09:58:44 -05:00
|
|
|
import * as assert from 'node:assert/strict';
|
|
|
|
import { after, before, describe, it } from 'node:test';
|
2024-01-05 14:30:53 -05:00
|
|
|
import { load as cheerioLoad } from 'cheerio';
|
|
|
|
import { loadFixture } from './test-utils.js';
|
|
|
|
|
|
|
|
describe('App Entrypoint CSS', () => {
|
|
|
|
/** @type {import('./test-utils').Fixture} */
|
|
|
|
let fixture;
|
|
|
|
|
|
|
|
before(async () => {
|
|
|
|
fixture = await loadFixture({
|
|
|
|
root: './fixtures/app-entrypoint-css/',
|
|
|
|
});
|
2024-01-05 14:31:59 -05:00
|
|
|
});
|
2024-01-05 14:30:53 -05:00
|
|
|
|
|
|
|
describe('build', () => {
|
|
|
|
before(async () => {
|
|
|
|
await fixture.build();
|
2024-01-05 14:31:59 -05:00
|
|
|
});
|
2024-01-05 14:30:53 -05:00
|
|
|
|
|
|
|
it('injects styles referenced in appEntrypoint', async () => {
|
|
|
|
const html = await fixture.readFile('/index.html');
|
|
|
|
const $ = cheerioLoad(html);
|
|
|
|
|
|
|
|
// test 1: basic component renders
|
2024-01-31 09:58:44 -05:00
|
|
|
assert.equal($('#foo > #bar').text(), 'works');
|
2024-01-05 14:30:53 -05:00
|
|
|
// test 2: injects the global style on the page
|
2024-01-31 09:58:44 -05:00
|
|
|
assert.equal($('style').first().text().trim(), ':root{background-color:red}');
|
2024-01-05 14:30:53 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('does not inject styles to pages without a Vue component', async () => {
|
|
|
|
const html = await fixture.readFile('/unrelated/index.html');
|
|
|
|
const $ = cheerioLoad(html);
|
|
|
|
|
2024-01-31 09:58:44 -05:00
|
|
|
assert.equal($('style').length, 0);
|
|
|
|
assert.equal($('link[rel="stylesheet"]').length, 0);
|
2024-01-05 14:30:53 -05:00
|
|
|
});
|
2024-01-05 14:31:59 -05:00
|
|
|
});
|
2024-01-05 14:30:53 -05:00
|
|
|
|
|
|
|
describe('dev', () => {
|
|
|
|
let devServer;
|
|
|
|
before(async () => {
|
|
|
|
devServer = await fixture.startDevServer();
|
2024-01-05 14:31:59 -05:00
|
|
|
});
|
2024-01-05 14:30:53 -05:00
|
|
|
after(async () => {
|
|
|
|
await devServer.stop();
|
2024-01-05 14:31:59 -05:00
|
|
|
});
|
2024-01-05 14:30:53 -05:00
|
|
|
|
|
|
|
it('loads during SSR', async () => {
|
|
|
|
const html = await fixture.fetch('/').then((res) => res.text());
|
|
|
|
const $ = cheerioLoad(html);
|
2024-01-05 14:31:59 -05:00
|
|
|
|
2024-01-05 14:30:53 -05:00
|
|
|
// test 1: basic component renders
|
2024-01-31 09:58:44 -05:00
|
|
|
assert.equal($('#foo > #bar').text(), 'works');
|
2024-01-05 14:30:53 -05:00
|
|
|
// test 2: injects the global style on the page
|
2024-01-31 09:58:44 -05:00
|
|
|
assert.equal($('style').first().text().replace(/\s+/g, ''), ':root{background-color:red;}');
|
2024-01-05 14:30:53 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('does not inject styles to pages without a Vue component', async () => {
|
|
|
|
const html = await fixture.fetch('/unrelated').then((res) => res.text());
|
|
|
|
const $ = cheerioLoad(html);
|
|
|
|
|
2024-01-31 09:58:44 -05:00
|
|
|
assert.equal($('style').length, 0);
|
|
|
|
assert.equal($('link[rel="stylesheet"]').length, 0);
|
2024-01-05 14:30:53 -05:00
|
|
|
});
|
2024-01-05 14:31:59 -05:00
|
|
|
});
|
2024-01-05 14:30:53 -05:00
|
|
|
});
|