astro/packages/astro/test/0-css.test.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

318 lines
10 KiB
JavaScript
Raw Normal View History

2021-11-22 14:24:42 -07:00
/**
* CSS test
* Run this test first! This uses quite a bit of memory, so prefixing with `0-` helps it start and finish early,
* rather than trying to start up when all other threads are busy and having to fight for resources
*/
import { expect } from 'chai';
import cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';
let fixture;
2021-11-22 14:24:42 -07:00
describe('CSS', function () {
2021-11-22 14:24:42 -07:00
before(async () => {
fixture = await loadFixture({ projectRoot: './fixtures/0-css/' });
2021-11-22 14:24:42 -07:00
});
2021-12-22 16:11:05 -05:00
// test HTML and CSS contents for accuracy
describe('build', () => {
merge `next` into `main` (#2705) * Unflag the static build (#2652) * Unflag the static build * Only set legacyBuild to false if experimentalSSR is true * Use legacy build when we have to * Put a few more tests into legacy mode * Last two * Make astro-basic use the legacy build * Adds a changeset * Mark the lit test as legacy * Update yarn lock * Update based on feedback * Add --legacy-build flag * Move astro-basic test to use static build (#2682) * Move some tests over to the static build (#2677) * Move some tests over to the static build * Fix assets tests * Fix the assets tests * Fix for the client:only components * Moves asset tests to the static build * Move postcss test over to static build * Bring back legacy build for astro-basic test * Move astro-basic test to use static build * Migrate more tests to the static build (#2693) * fix: disable HMR during build (#2684) * Migrate more tests to the static build * Only prepend links in non-legacy mode * Add the 0-css tests * Convert all CSS tests to the static build * Migrate Astro global tests * Remove .only * Fix static build tests * Migrate a few more * More tests * Move the lit test back to legacy * Increase the test timeout Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com> * Improve `head` injection behavior (#2436) * feat: add renderHead util to server * feat: remove `layouts` from config, Vite plugin * fix: improve head injection during rendering * chore: update compiler * fix: do not escape links * chore: enter `pre` mode * Replace `send` with `sirv` (#2713) * remove send * Create thick-ravens-chew.md * I feel like I'm going to screw something up * working finally! * rewrite req.url * Add tiny bit of doc * Update .gitignore Co-authored-by: Evan Boehs <evan@boehs.org> * Move remaining tests to the static build (#2712) * Move lit test to the static build * Migrate astro-env plugin to work in the static build * Do not remove vite:define * Adds a changeset * Add a warning when passing the --experimental-static-build flag (#2718) * Add a warning when passing the --experimental-static-build flag * Disable the lint warning * [ci] release (next) (#2721) * [ci] release (next) * chore: update changeset Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Nate Moore <nate@skypack.dev> * 404 page (#2719) * Fix: build to 404.html in the static build * Adds a changeset * fix pnpm install missing peer deps * fix svelte version in workspace * fix lockfile * fix(webapi): add dev script * improve preview reliability (#2739) * improve preview reliability - fix broken tests * shamefully hoist to unblock * remove lit from test running * chore: update lockfile Co-authored-by: Matthew Phillips <matthew@skypack.dev> Co-authored-by: Evan Boehs <evan@boehs.org> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Fred K. Schott <fkschott@gmail.com>
2022-03-09 15:44:26 -06:00
this.timeout(45000); // test needs a little more time in CI
2021-12-22 16:11:05 -05:00
let $;
let bundledCSS;
2021-12-22 16:11:05 -05:00
before(async () => {
await fixture.build();
2021-12-22 16:11:05 -05:00
// get bundled CSS (will be hashed, hence DOM query)
const html = await fixture.readFile('/index.html');
$ = cheerio.load(html);
merge `next` into `main` (#2705) * Unflag the static build (#2652) * Unflag the static build * Only set legacyBuild to false if experimentalSSR is true * Use legacy build when we have to * Put a few more tests into legacy mode * Last two * Make astro-basic use the legacy build * Adds a changeset * Mark the lit test as legacy * Update yarn lock * Update based on feedback * Add --legacy-build flag * Move astro-basic test to use static build (#2682) * Move some tests over to the static build (#2677) * Move some tests over to the static build * Fix assets tests * Fix the assets tests * Fix for the client:only components * Moves asset tests to the static build * Move postcss test over to static build * Bring back legacy build for astro-basic test * Move astro-basic test to use static build * Migrate more tests to the static build (#2693) * fix: disable HMR during build (#2684) * Migrate more tests to the static build * Only prepend links in non-legacy mode * Add the 0-css tests * Convert all CSS tests to the static build * Migrate Astro global tests * Remove .only * Fix static build tests * Migrate a few more * More tests * Move the lit test back to legacy * Increase the test timeout Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com> * Improve `head` injection behavior (#2436) * feat: add renderHead util to server * feat: remove `layouts` from config, Vite plugin * fix: improve head injection during rendering * chore: update compiler * fix: do not escape links * chore: enter `pre` mode * Replace `send` with `sirv` (#2713) * remove send * Create thick-ravens-chew.md * I feel like I'm going to screw something up * working finally! * rewrite req.url * Add tiny bit of doc * Update .gitignore Co-authored-by: Evan Boehs <evan@boehs.org> * Move remaining tests to the static build (#2712) * Move lit test to the static build * Migrate astro-env plugin to work in the static build * Do not remove vite:define * Adds a changeset * Add a warning when passing the --experimental-static-build flag (#2718) * Add a warning when passing the --experimental-static-build flag * Disable the lint warning * [ci] release (next) (#2721) * [ci] release (next) * chore: update changeset Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Nate Moore <nate@skypack.dev> * 404 page (#2719) * Fix: build to 404.html in the static build * Adds a changeset * fix pnpm install missing peer deps * fix svelte version in workspace * fix lockfile * fix(webapi): add dev script * improve preview reliability (#2739) * improve preview reliability - fix broken tests * shamefully hoist to unblock * remove lit from test running * chore: update lockfile Co-authored-by: Matthew Phillips <matthew@skypack.dev> Co-authored-by: Evan Boehs <evan@boehs.org> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Fred K. Schott <fkschott@gmail.com>
2022-03-09 15:44:26 -06:00
const bundledCSSHREF = $('link[rel=stylesheet][href^=/assets/]').attr('href');
bundledCSS = await fixture.readFile(bundledCSSHREF.replace(/^\/?/, '/'));
2021-11-22 14:24:42 -07:00
});
2021-12-22 16:11:05 -05:00
describe('Astro Styles', () => {
it('HTML and CSS scoped correctly', async () => {
const el1 = $('#dynamic-class');
const el2 = $('#dynamic-vis');
const classes = $('#class').attr('class').split(' ');
const scopedClass = classes.find((name) => /^astro-[A-Za-z0-9-]+/.test(name));
2021-12-22 16:11:05 -05:00
// 1. check HTML
expect(el1.attr('class')).to.equal(`blue ${scopedClass}`);
expect(el2.attr('class')).to.equal(`visible ${scopedClass}`);
2021-12-22 16:11:05 -05:00
// 2. check CSS
merge `next` into `main` (#2705) * Unflag the static build (#2652) * Unflag the static build * Only set legacyBuild to false if experimentalSSR is true * Use legacy build when we have to * Put a few more tests into legacy mode * Last two * Make astro-basic use the legacy build * Adds a changeset * Mark the lit test as legacy * Update yarn lock * Update based on feedback * Add --legacy-build flag * Move astro-basic test to use static build (#2682) * Move some tests over to the static build (#2677) * Move some tests over to the static build * Fix assets tests * Fix the assets tests * Fix for the client:only components * Moves asset tests to the static build * Move postcss test over to static build * Bring back legacy build for astro-basic test * Move astro-basic test to use static build * Migrate more tests to the static build (#2693) * fix: disable HMR during build (#2684) * Migrate more tests to the static build * Only prepend links in non-legacy mode * Add the 0-css tests * Convert all CSS tests to the static build * Migrate Astro global tests * Remove .only * Fix static build tests * Migrate a few more * More tests * Move the lit test back to legacy * Increase the test timeout Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com> * Improve `head` injection behavior (#2436) * feat: add renderHead util to server * feat: remove `layouts` from config, Vite plugin * fix: improve head injection during rendering * chore: update compiler * fix: do not escape links * chore: enter `pre` mode * Replace `send` with `sirv` (#2713) * remove send * Create thick-ravens-chew.md * I feel like I'm going to screw something up * working finally! * rewrite req.url * Add tiny bit of doc * Update .gitignore Co-authored-by: Evan Boehs <evan@boehs.org> * Move remaining tests to the static build (#2712) * Move lit test to the static build * Migrate astro-env plugin to work in the static build * Do not remove vite:define * Adds a changeset * Add a warning when passing the --experimental-static-build flag (#2718) * Add a warning when passing the --experimental-static-build flag * Disable the lint warning * [ci] release (next) (#2721) * [ci] release (next) * chore: update changeset Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Nate Moore <nate@skypack.dev> * 404 page (#2719) * Fix: build to 404.html in the static build * Adds a changeset * fix pnpm install missing peer deps * fix svelte version in workspace * fix lockfile * fix(webapi): add dev script * improve preview reliability (#2739) * improve preview reliability - fix broken tests * shamefully hoist to unblock * remove lit from test running * chore: update lockfile Co-authored-by: Matthew Phillips <matthew@skypack.dev> Co-authored-by: Evan Boehs <evan@boehs.org> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Fred K. Schott <fkschott@gmail.com>
2022-03-09 15:44:26 -06:00
const expected = `.blue.${scopedClass}{color:#b0e0e6}.color\\\\:blue.${scopedClass}{color:#b0e0e6}.visible.${scopedClass}{display:block}`;
expect(bundledCSS).to.include(expected);
});
2021-12-22 16:11:05 -05:00
it('No <style> skips scoping', async () => {
// Astro component without <style> should not include scoped class
expect($('#no-scope').attr('class')).to.equal(undefined);
});
2021-12-22 16:11:05 -05:00
it('Child inheritance', async () => {
expect($('#passed-in').attr('class')).to.match(/outer astro-[A-Z0-9]+ astro-[A-Z0-9]+/);
});
2021-12-22 16:11:05 -05:00
it('Using hydrated components adds astro-root styles', async () => {
merge `next` into `main` (#2705) * Unflag the static build (#2652) * Unflag the static build * Only set legacyBuild to false if experimentalSSR is true * Use legacy build when we have to * Put a few more tests into legacy mode * Last two * Make astro-basic use the legacy build * Adds a changeset * Mark the lit test as legacy * Update yarn lock * Update based on feedback * Add --legacy-build flag * Move astro-basic test to use static build (#2682) * Move some tests over to the static build (#2677) * Move some tests over to the static build * Fix assets tests * Fix the assets tests * Fix for the client:only components * Moves asset tests to the static build * Move postcss test over to static build * Bring back legacy build for astro-basic test * Move astro-basic test to use static build * Migrate more tests to the static build (#2693) * fix: disable HMR during build (#2684) * Migrate more tests to the static build * Only prepend links in non-legacy mode * Add the 0-css tests * Convert all CSS tests to the static build * Migrate Astro global tests * Remove .only * Fix static build tests * Migrate a few more * More tests * Move the lit test back to legacy * Increase the test timeout Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com> * Improve `head` injection behavior (#2436) * feat: add renderHead util to server * feat: remove `layouts` from config, Vite plugin * fix: improve head injection during rendering * chore: update compiler * fix: do not escape links * chore: enter `pre` mode * Replace `send` with `sirv` (#2713) * remove send * Create thick-ravens-chew.md * I feel like I'm going to screw something up * working finally! * rewrite req.url * Add tiny bit of doc * Update .gitignore Co-authored-by: Evan Boehs <evan@boehs.org> * Move remaining tests to the static build (#2712) * Move lit test to the static build * Migrate astro-env plugin to work in the static build * Do not remove vite:define * Adds a changeset * Add a warning when passing the --experimental-static-build flag (#2718) * Add a warning when passing the --experimental-static-build flag * Disable the lint warning * [ci] release (next) (#2721) * [ci] release (next) * chore: update changeset Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Nate Moore <nate@skypack.dev> * 404 page (#2719) * Fix: build to 404.html in the static build * Adds a changeset * fix pnpm install missing peer deps * fix svelte version in workspace * fix lockfile * fix(webapi): add dev script * improve preview reliability (#2739) * improve preview reliability - fix broken tests * shamefully hoist to unblock * remove lit from test running * chore: update lockfile Co-authored-by: Matthew Phillips <matthew@skypack.dev> Co-authored-by: Evan Boehs <evan@boehs.org> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Fred K. Schott <fkschott@gmail.com>
2022-03-09 15:44:26 -06:00
const inline = $('style').html();
expect(inline).to.include('display: contents');
});
2021-12-22 16:11:05 -05:00
it('<style lang="sass">', async () => {
expect(bundledCSS).to.match(new RegExp('h1.astro-[^{]*{color:#90ee90}'));
});
2021-12-22 16:11:05 -05:00
it('<style lang="scss">', async () => {
expect(bundledCSS).to.match(new RegExp('h1.astro-[^{]*{color:#ff69b4}'));
});
2021-11-22 14:24:42 -07:00
});
2021-12-22 16:11:05 -05:00
describe('Styles in src/', () => {
it('.css', async () => {
expect(bundledCSS).to.match(new RegExp('.linked-css[^{]*{color:gold'));
});
2021-12-22 16:11:05 -05:00
it('.sass', async () => {
expect(bundledCSS).to.match(new RegExp('.linked-sass[^{]*{color:#789'));
});
2021-12-22 16:11:05 -05:00
it('.scss', async () => {
expect(bundledCSS).to.match(new RegExp('.linked-scss[^{]*{color:#6b8e23'));
});
2021-11-22 14:24:42 -07:00
});
2021-12-22 16:11:05 -05:00
describe('JSX', () => {
it('.css', async () => {
const el = $('#react-css');
// 1. check HTML
expect(el.attr('class')).to.include('react-title');
// 2. check CSS
expect(bundledCSS).to.include('.react-title');
});
2021-12-22 16:11:05 -05:00
it('.module.css', async () => {
const el = $('#react-module-css');
const classes = el.attr('class').split(' ');
const moduleClass = classes.find((name) => /^_title_[A-Za-z0-9-_]+/.test(name));
2021-11-22 14:24:42 -07:00
// 1. check HTML
expect(el.attr('class')).to.include(moduleClass);
2021-11-22 14:24:42 -07:00
// 2. check CSS
expect(bundledCSS).to.match(new RegExp(`.${moduleClass}[^{]*{font-family:fantasy}`));
});
2021-11-22 14:24:42 -07:00
it('.sass', async () => {
const el = $('#react-sass');
2021-12-22 16:11:05 -05:00
// 1. check HTML
expect(el.attr('class')).to.include('react-sass-title');
2021-11-22 14:24:42 -07:00
// 2. check CSS
expect(bundledCSS).to.match(new RegExp(`.react-sass-title[^{]*{font-family:fantasy}`));
});
2021-11-22 14:24:42 -07:00
it('.scss', async () => {
const el = $('#react-scss');
2021-11-22 14:24:42 -07:00
// 1. check HTML
expect(el.attr('class')).to.include('react-scss-title');
2021-11-22 14:24:42 -07:00
// 2. check CSS
expect(bundledCSS).to.match(new RegExp(`.react-scss-title[^{]*{font-family:fantasy}`));
});
2021-12-22 16:11:05 -05:00
it('.module.sass', async () => {
const el = $('#react-module-sass');
const classes = el.attr('class').split(' ');
const moduleClass = classes.find((name) => /^_title_[A-Za-z0-9-_]+/.test(name));
2021-11-22 14:24:42 -07:00
// 1. check HTML
expect(el.attr('class')).to.include(moduleClass);
// 2. check CSS
expect(bundledCSS).to.match(new RegExp(`.${moduleClass}[^{]*{font-family:fantasy}`));
});
2021-11-22 14:24:42 -07:00
it('.module.scss', async () => {
const el = $('#react-module-scss');
const classes = el.attr('class').split(' ');
const moduleClass = classes.find((name) => /^_title_[A-Za-z0-9-_]+/.test(name));
2021-11-22 14:24:42 -07:00
// 1. check HTML
expect(el.attr('class')).to.include(moduleClass);
2021-11-22 14:24:42 -07:00
// 2. check CSS
expect(bundledCSS).to.match(new RegExp(`.${moduleClass}[^{]*{font-family:fantasy}`));
});
2021-11-22 14:24:42 -07:00
});
describe('Vue', () => {
it('<style>', async () => {
const el = $('#vue-css');
2021-11-22 14:24:42 -07:00
// 1. check HTML
expect(el.attr('class')).to.include('vue-css');
2021-11-22 14:24:42 -07:00
// 2. check CSS
expect(bundledCSS).to.match(new RegExp(`.vue-css[^{]*{font-family:cursive`));
});
2021-11-22 14:24:42 -07:00
it('<style scoped>', async () => {
const el = $('#vue-scoped');
2021-11-22 14:24:42 -07:00
// find data-v-* attribute (how Vue CSS scoping works)
const { attribs } = el.get(0);
const scopeId = Object.keys(attribs).find((k) => k.startsWith('data-v-'));
expect(scopeId).to.be.ok;
2021-11-22 14:24:42 -07:00
// 1. check HTML
expect(el.attr('class')).to.include('vue-scoped');
2021-11-22 14:24:42 -07:00
// 2. check CSS
expect(bundledCSS).to.include(`.vue-scoped[${scopeId}]`);
});
2021-11-22 14:24:42 -07:00
it('<style module>', async () => {
const el = $('#vue-modules');
const classes = el.attr('class').split(' ');
const moduleClass = classes.find((name) => /^_title_[A-Za-z0-9-_]+/.test(name));
2021-11-22 14:24:42 -07:00
// 1. check HTML
expect(el.attr('class')).to.include(moduleClass);
2021-11-22 14:24:42 -07:00
// 2. check CSS
expect(bundledCSS).to.match(new RegExp(`.${moduleClass}[^{]*{font-family:cursive}`));
});
2021-12-22 16:11:05 -05:00
it('<style lang="sass">', async () => {
const el = $('#vue-sass');
2021-12-22 16:11:05 -05:00
// 1. check HTML
expect(el.attr('class')).to.include('vue-sass');
2021-12-22 16:11:05 -05:00
// 2. check CSS
expect(bundledCSS).to.match(new RegExp(`.vue-sass[^{]*{font-family:cursive`));
});
2021-12-22 16:11:05 -05:00
it('<style lang="scss">', async () => {
const el = $('#vue-scss');
2021-12-22 16:11:05 -05:00
// 1. check HTML
expect(el.attr('class')).to.include('vue-scss');
2021-12-22 16:11:05 -05:00
// 2. check CSS
expect(bundledCSS).to.match(new RegExp(`.vue-scss[^{]*{font-family:cursive`));
});
2021-11-22 14:24:42 -07:00
});
2021-12-22 16:11:05 -05:00
describe('Svelte', () => {
it('<style>', async () => {
const el = $('#svelte-css');
const classes = el.attr('class').split(' ');
merge `next` into `main` (#2705) * Unflag the static build (#2652) * Unflag the static build * Only set legacyBuild to false if experimentalSSR is true * Use legacy build when we have to * Put a few more tests into legacy mode * Last two * Make astro-basic use the legacy build * Adds a changeset * Mark the lit test as legacy * Update yarn lock * Update based on feedback * Add --legacy-build flag * Move astro-basic test to use static build (#2682) * Move some tests over to the static build (#2677) * Move some tests over to the static build * Fix assets tests * Fix the assets tests * Fix for the client:only components * Moves asset tests to the static build * Move postcss test over to static build * Bring back legacy build for astro-basic test * Move astro-basic test to use static build * Migrate more tests to the static build (#2693) * fix: disable HMR during build (#2684) * Migrate more tests to the static build * Only prepend links in non-legacy mode * Add the 0-css tests * Convert all CSS tests to the static build * Migrate Astro global tests * Remove .only * Fix static build tests * Migrate a few more * More tests * Move the lit test back to legacy * Increase the test timeout Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com> * Improve `head` injection behavior (#2436) * feat: add renderHead util to server * feat: remove `layouts` from config, Vite plugin * fix: improve head injection during rendering * chore: update compiler * fix: do not escape links * chore: enter `pre` mode * Replace `send` with `sirv` (#2713) * remove send * Create thick-ravens-chew.md * I feel like I'm going to screw something up * working finally! * rewrite req.url * Add tiny bit of doc * Update .gitignore Co-authored-by: Evan Boehs <evan@boehs.org> * Move remaining tests to the static build (#2712) * Move lit test to the static build * Migrate astro-env plugin to work in the static build * Do not remove vite:define * Adds a changeset * Add a warning when passing the --experimental-static-build flag (#2718) * Add a warning when passing the --experimental-static-build flag * Disable the lint warning * [ci] release (next) (#2721) * [ci] release (next) * chore: update changeset Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Nate Moore <nate@skypack.dev> * 404 page (#2719) * Fix: build to 404.html in the static build * Adds a changeset * fix pnpm install missing peer deps * fix svelte version in workspace * fix lockfile * fix(webapi): add dev script * improve preview reliability (#2739) * improve preview reliability - fix broken tests * shamefully hoist to unblock * remove lit from test running * chore: update lockfile Co-authored-by: Matthew Phillips <matthew@skypack.dev> Co-authored-by: Evan Boehs <evan@boehs.org> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Fred K. Schott <fkschott@gmail.com>
2022-03-09 15:44:26 -06:00
const scopedClass = classes.find((name) => name !== 'svelte-css' && /^svelte-[A-Za-z0-9-]+/.test(name));
2021-12-22 16:11:05 -05:00
// 1. check HTML
expect(el.attr('class')).to.include('svelte-css');
2021-12-22 16:11:05 -05:00
// 2. check CSS
expect(bundledCSS).to.match(new RegExp(`.svelte-css.${scopedClass}[^{]*{font-family:Comic Sans MS`));
});
2021-12-22 16:11:05 -05:00
it('<style lang="sass">', async () => {
const el = $('#svelte-sass');
const classes = el.attr('class').split(' ');
merge `next` into `main` (#2705) * Unflag the static build (#2652) * Unflag the static build * Only set legacyBuild to false if experimentalSSR is true * Use legacy build when we have to * Put a few more tests into legacy mode * Last two * Make astro-basic use the legacy build * Adds a changeset * Mark the lit test as legacy * Update yarn lock * Update based on feedback * Add --legacy-build flag * Move astro-basic test to use static build (#2682) * Move some tests over to the static build (#2677) * Move some tests over to the static build * Fix assets tests * Fix the assets tests * Fix for the client:only components * Moves asset tests to the static build * Move postcss test over to static build * Bring back legacy build for astro-basic test * Move astro-basic test to use static build * Migrate more tests to the static build (#2693) * fix: disable HMR during build (#2684) * Migrate more tests to the static build * Only prepend links in non-legacy mode * Add the 0-css tests * Convert all CSS tests to the static build * Migrate Astro global tests * Remove .only * Fix static build tests * Migrate a few more * More tests * Move the lit test back to legacy * Increase the test timeout Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com> * Improve `head` injection behavior (#2436) * feat: add renderHead util to server * feat: remove `layouts` from config, Vite plugin * fix: improve head injection during rendering * chore: update compiler * fix: do not escape links * chore: enter `pre` mode * Replace `send` with `sirv` (#2713) * remove send * Create thick-ravens-chew.md * I feel like I'm going to screw something up * working finally! * rewrite req.url * Add tiny bit of doc * Update .gitignore Co-authored-by: Evan Boehs <evan@boehs.org> * Move remaining tests to the static build (#2712) * Move lit test to the static build * Migrate astro-env plugin to work in the static build * Do not remove vite:define * Adds a changeset * Add a warning when passing the --experimental-static-build flag (#2718) * Add a warning when passing the --experimental-static-build flag * Disable the lint warning * [ci] release (next) (#2721) * [ci] release (next) * chore: update changeset Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Nate Moore <nate@skypack.dev> * 404 page (#2719) * Fix: build to 404.html in the static build * Adds a changeset * fix pnpm install missing peer deps * fix svelte version in workspace * fix lockfile * fix(webapi): add dev script * improve preview reliability (#2739) * improve preview reliability - fix broken tests * shamefully hoist to unblock * remove lit from test running * chore: update lockfile Co-authored-by: Matthew Phillips <matthew@skypack.dev> Co-authored-by: Evan Boehs <evan@boehs.org> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Fred K. Schott <fkschott@gmail.com>
2022-03-09 15:44:26 -06:00
const scopedClass = classes.find((name) => name !== 'svelte-sass' && /^svelte-[A-Za-z0-9-]+/.test(name));
2021-12-22 16:11:05 -05:00
// 1. check HTML
expect(el.attr('class')).to.include('svelte-sass');
2021-12-22 16:11:05 -05:00
// 2. check CSS
expect(bundledCSS).to.match(new RegExp(`.svelte-sass.${scopedClass}[^{]*{font-family:Comic Sans MS`));
});
2021-12-22 16:11:05 -05:00
it('<style lang="scss">', async () => {
const el = $('#svelte-scss');
const classes = el.attr('class').split(' ');
merge `next` into `main` (#2705) * Unflag the static build (#2652) * Unflag the static build * Only set legacyBuild to false if experimentalSSR is true * Use legacy build when we have to * Put a few more tests into legacy mode * Last two * Make astro-basic use the legacy build * Adds a changeset * Mark the lit test as legacy * Update yarn lock * Update based on feedback * Add --legacy-build flag * Move astro-basic test to use static build (#2682) * Move some tests over to the static build (#2677) * Move some tests over to the static build * Fix assets tests * Fix the assets tests * Fix for the client:only components * Moves asset tests to the static build * Move postcss test over to static build * Bring back legacy build for astro-basic test * Move astro-basic test to use static build * Migrate more tests to the static build (#2693) * fix: disable HMR during build (#2684) * Migrate more tests to the static build * Only prepend links in non-legacy mode * Add the 0-css tests * Convert all CSS tests to the static build * Migrate Astro global tests * Remove .only * Fix static build tests * Migrate a few more * More tests * Move the lit test back to legacy * Increase the test timeout Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com> * Improve `head` injection behavior (#2436) * feat: add renderHead util to server * feat: remove `layouts` from config, Vite plugin * fix: improve head injection during rendering * chore: update compiler * fix: do not escape links * chore: enter `pre` mode * Replace `send` with `sirv` (#2713) * remove send * Create thick-ravens-chew.md * I feel like I'm going to screw something up * working finally! * rewrite req.url * Add tiny bit of doc * Update .gitignore Co-authored-by: Evan Boehs <evan@boehs.org> * Move remaining tests to the static build (#2712) * Move lit test to the static build * Migrate astro-env plugin to work in the static build * Do not remove vite:define * Adds a changeset * Add a warning when passing the --experimental-static-build flag (#2718) * Add a warning when passing the --experimental-static-build flag * Disable the lint warning * [ci] release (next) (#2721) * [ci] release (next) * chore: update changeset Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Nate Moore <nate@skypack.dev> * 404 page (#2719) * Fix: build to 404.html in the static build * Adds a changeset * fix pnpm install missing peer deps * fix svelte version in workspace * fix lockfile * fix(webapi): add dev script * improve preview reliability (#2739) * improve preview reliability - fix broken tests * shamefully hoist to unblock * remove lit from test running * chore: update lockfile Co-authored-by: Matthew Phillips <matthew@skypack.dev> Co-authored-by: Evan Boehs <evan@boehs.org> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Fred K. Schott <fkschott@gmail.com>
2022-03-09 15:44:26 -06:00
const scopedClass = classes.find((name) => name !== 'svelte-scss' && /^svelte-[A-Za-z0-9-]+/.test(name));
2021-12-22 16:11:05 -05:00
// 1. check HTML
expect(el.attr('class')).to.include('svelte-scss');
2021-12-22 16:11:05 -05:00
// 2. check CSS
expect(bundledCSS).to.match(new RegExp(`.svelte-scss.${scopedClass}[^{]*{font-family:Comic Sans MS`));
});
2021-11-22 14:24:42 -07:00
});
});
2021-12-22 16:11:05 -05:00
// with "build" handling CSS checking, the dev tests are mostly testing the paths resolve in dev
describe('dev', () => {
let devServer;
let $;
2021-12-22 16:11:05 -05:00
before(async () => {
devServer = await fixture.startDevServer();
const html = await fixture.fetch('/').then((res) => res.text());
$ = cheerio.load(html);
});
2021-12-22 16:11:05 -05:00
after(async () => {
2022-03-15 12:38:13 +00:00
await devServer.stop();
2021-11-22 14:24:42 -07:00
});
2021-12-22 16:11:05 -05:00
it('resolves CSS in public/', async () => {
const href = $('link[href="/global.css"]').attr('href');
expect((await fixture.fetch(href)).status).to.equal(200);
});
2021-12-22 16:11:05 -05:00
// Skipped until upstream fix lands
// Our fix: https://github.com/withastro/astro/pull/2106
// OG Vite PR: https://github.com/vitejs/vite/pull/5940
// Next Vite PR: https://github.com/vitejs/vite/pull/5796
it.skip('resolved imported CSS with ?url', async () => {
const href = $('link[href$="imported-url.css"]').attr('href');
expect(href).to.be.ok;
expect((await fixture.fetch(href)).status).to.equal(200);
});
2021-12-22 16:11:05 -05:00
it('resolves Astro styles', async () => {
const style = $('style[astro-style]');
expect(style.length).to.not.equal(0);
2021-11-22 14:24:42 -07:00
});
2021-12-22 16:11:05 -05:00
it('resolves Styles from React', async () => {
const styles = ['ReactCSS.css', 'ReactModules.module.css', 'ReactModules.module.scss', 'ReactModules.module.sass', 'ReactSass.sass', 'ReactScss.scss'];
for (const style of styles) {
const href = $(`link[href$="${style}"]`).attr('href');
expect((await fixture.fetch(href)).status, style).to.equal(200);
}
});
2021-12-22 16:11:05 -05:00
it('resolves CSS from Svelte', async () => {
const scripts = ['SvelteCSS.svelte?svelte&type=style&lang.css', 'SvelteSass.svelte?svelte&type=style&lang.css', 'SvelteScss.svelte?svelte&type=style&lang.css'];
for (const script of scripts) {
const src = $(`script[src$="${script}"]`).attr('src');
expect((await fixture.fetch(src)).status, script).to.equal(200);
}
});
2021-12-22 16:11:05 -05:00
it('resolves CSS from Vue', async () => {
const styles = [
'VueCSS.vue?vue&type=style&index=0&lang.css',
'VueModules.vue?vue&type=style&index=0&lang.module.scss',
'VueSass.vue?vue&type=style&index=0&lang.sass',
'VueScoped.vue?vue&type=style&index=0&scoped=true&lang.css',
'VueScss.vue?vue&type=style&index=0&lang.scss',
];
for (const style of styles) {
const href = $(`link[href$="${style}"]`).attr('href');
expect((await fixture.fetch(href)).status, style).to.equal(200);
}
2021-11-22 14:24:42 -07:00
});
});
});