From a1c31665cbc48bfdf4885112b427db48ecc48276 Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Fri, 5 Jan 2024 13:30:53 -0600 Subject: Ensure `appEntrypoint` is referenced in Vue components (#9490) * fix(#6827): ensure `appEntrypoint` is referenced in Vue components * chore: add test * chore: add changeset * fix: windows handling * Update packages/integrations/vue/src/index.ts Co-authored-by: Bjorn Lu * chore: address review feedback * chore: update lockfile --------- Co-authored-by: Bjorn Lu --- .../vue/test/app-entrypoint-css.test.js | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 packages/integrations/vue/test/app-entrypoint-css.test.js (limited to 'packages/integrations/vue/test/app-entrypoint-css.test.js') diff --git a/packages/integrations/vue/test/app-entrypoint-css.test.js b/packages/integrations/vue/test/app-entrypoint-css.test.js new file mode 100644 index 000000000..b629f1d25 --- /dev/null +++ b/packages/integrations/vue/test/app-entrypoint-css.test.js @@ -0,0 +1,67 @@ +import { loadFixture } from './test-utils.js'; +import { expect } from 'chai'; +import { load as cheerioLoad } from 'cheerio'; + +describe('App Entrypoint CSS', () => { + /** @type {import('./test-utils').Fixture} */ + let fixture; + + before(async () => { + fixture = await loadFixture({ + root: './fixtures/app-entrypoint-css/', + }); + }) + + describe('build', () => { + before(async () => { + await fixture.build(); + }) + + it('injects styles referenced in appEntrypoint', async () => { + const html = await fixture.readFile('/index.html'); + const $ = cheerioLoad(html); + + // test 1: basic component renders + expect($('#foo > #bar').text()).to.eq('works'); + + // test 2: injects the global style on the page + expect($('style').first().text().trim()).to.eq(':root{background-color:red}'); + }); + + it('does not inject styles to pages without a Vue component', async () => { + const html = await fixture.readFile('/unrelated/index.html'); + const $ = cheerioLoad(html); + + expect($('style').length).to.eq(0); + expect($('link[rel="stylesheet"]').length).to.eq(0); + }); + }) + + describe('dev', () => { + let devServer; + before(async () => { + devServer = await fixture.startDevServer(); + }) + after(async () => { + await devServer.stop(); + }) + + it('loads during SSR', async () => { + const html = await fixture.fetch('/').then((res) => res.text()); + const $ = cheerioLoad(html); + + // test 1: basic component renders + expect($('#foo > #bar').text()).to.eq('works'); + // test 2: injects the global style on the page + expect($('style').first().text().replace(/\s+/g, '')).to.eq(':root{background-color:red;}'); + }); + + 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); + + expect($('style').length).to.eq(0); + expect($('link[rel="stylesheet"]').length).to.eq(0); + }); + }) +}); -- cgit v1.2.3