forked from withastro/astro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcss-assets.test.js
50 lines (44 loc) · 1.29 KB
/
css-assets.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import * as assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';
describe('Assets in CSS', () => {
let fixture;
before(async () => {
fixture = await loadFixture({
root: './fixtures/css-assets/',
vite: {
build: {
assetsInlineLimit: 0,
},
},
});
await fixture.build();
});
function getAllMatches(re, text) {
let count = 0;
while (re.exec(text) !== null) {
++count;
}
return count;
}
async function getCSSForPage(pathname) {
const html = await fixture.readFile(pathname);
const $ = cheerio.load(html);
const cssPath = $('link').attr('href');
const css = await fixture.readFile(cssPath);
return css;
}
it('Bundled CSS does not have __VITE_ASSET__', async () => {
let css = await getCSSForPage('/one/index.html');
assert.equal(css.includes('__VITE_ASSET__'), false);
css = await getCSSForPage('/two/index.html');
assert.equal(css.includes('__VITE_ASSET__'), false);
});
it('Pages contain only their own CSS', async () => {
let css = await getCSSForPage('/one/index.html');
assert.equal(getAllMatches(/font-face/g, css), 1);
css = await getCSSForPage('/two/index.html');
assert.equal(getAllMatches(/font-face/g, css), 1);
});
});