astro/packages/astro/test/astro-global.test.js
Matthew Phillips fd52bceea4
Build/bundle assets and CSS (#1786)
* Bundling CSS

* Current progress of building assets

* New build progress

* Its finally working

* Force css to go through the build

* Prettier filenames

* Split into separate CSS and HTML plugins

* Always have at least one input

* Bring back in sitemaps + output

* Bring back srcset support

* Bundle CSS

* Bring back minify

* Update dynamic tests

* Update remaining tests

* Linting

* Fix remaining broken test

* Use fs directly

* Adding a changeset

* Use path.posix

* Debugging windows

* More debugging

* Pass URLs into readFile

* Remove some debugging stuff

* Remove force flag from transformWithVite

* Update packages/astro/src/vite-plugin-build-css/index.ts

Co-authored-by: Drew Powers <1369770+drwpow@users.noreply.github.com>

Co-authored-by: Drew Powers <1369770+drwpow@users.noreply.github.com>
2021-11-11 08:44:11 -05:00

57 lines
1.8 KiB
JavaScript

import { expect } from 'chai';
import cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';
describe('Astro.*', () => {
let fixture;
before(async () => {
fixture = await loadFixture({
projectRoot: './fixtures/astro-global/',
buildOptions: {
site: 'https://mysite.dev/blog/',
sitemap: false,
},
});
await fixture.build();
});
it('Astro.request.url', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
expect($('#pathname').text()).to.equal('/');
expect($('#child-pathname').text()).to.equal('/');
expect($('#nested-child-pathname').text()).to.equal('/');
});
it('Astro.request.canonicalURL', async () => {
// given a URL, expect the following canonical URL
const canonicalURLs = {
'/index.html': 'https://mysite.dev/blog/',
'/post/post/index.html': 'https://mysite.dev/blog/post/post/',
'/posts/1/index.html': 'https://mysite.dev/blog/posts/',
'/posts/2/index.html': 'https://mysite.dev/blog/posts/2/',
};
for (const [url, canonicalURL] of Object.entries(canonicalURLs)) {
const html = await fixture.readFile(url);
const $ = cheerio.load(html);
expect($('link[rel="canonical"]').attr('href')).to.equal(canonicalURL);
}
});
it('Astro.site', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
expect($('#site').attr('href')).to.equal('https://mysite.dev/blog/');
});
it('Astro.resolve built', async () => {
const html = await fixture.readFile('/resolve/index.html');
const $ = cheerio.load(html);
expect($('img').attr('src')).to.include('assets/penguin.ccd44411.png'); // Main src/images
expect($('#inner-child img').attr('src')).to.include('assets/penguin.b9ab122a.png');
});
});