0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-27 22:19:04 -05:00
astro/packages/astro/test/virtual-astro-file.js
Matthew Phillips 5f4ecbad1b
Allow defining Astro components in Vite plugins (#3889)
* Allow defining Astro components in Vite plugins

* Adds a changeset

* Move non-main compilation into load

* Use the cachedCompilation in the markdown plugin

* Fix HMR test

* Simplify getNormalizedID

* Use a windows-friendly virtual module id for the test
2022-07-11 16:13:21 -04:00

27 lines
831 B
JavaScript

import { expect } from 'chai';
import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';
describe('Loading virtual Astro files', () => {
let fixture;
before(async () => {
fixture = await loadFixture({ root: './fixtures/virtual-astro-file/' });
await fixture.build();
});
it('renders the component', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
expect($('#something')).to.have.a.lengthOf(1);
expect($('#works').text()).to.equal('true');
});
it('builds component CSS', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
const href = $('link').attr('href');
const css = await fixture.readFile(href);
expect(css).to.match(/green/, 'css bundled from virtual astro module');
});
});