forked from withastro/astro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathastro-doctype.test.js
76 lines (57 loc) · 2.25 KB
/
astro-doctype.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';
describe('Doctype', () => {
let fixture;
before(async () => {
fixture = await loadFixture({ root: './fixtures/astro-doctype/' });
await fixture.build();
});
it('Automatically prepends the standards mode doctype', async () => {
const html = await fixture.readFile('/prepend/index.html');
// test that Doctype always included
assert.match(html, /^<!DOCTYPE html>/i);
});
it('No attributes added when doctype is provided by user', async () => {
const html = await fixture.readFile('/provided/index.html');
// test that Doctype always included
assert.match(html, /^<!DOCTYPE html>/i);
});
it.skip('Preserves user provided doctype', async () => {
const html = await fixture.readFile('/preserve/index.html');
// test that Doctype included was preserved
assert.match(
html,
/^<!DOCTYPE html PUBLIC "-\/\/W3C\/\/DTD HTML 4.01 Transitional\/\/EN" "http:\/\/www.w3.org\/TR\/html4\/loose.dtd">/i,
);
});
it('User provided doctype is case insensitive', async () => {
const html = await fixture.readFile('/capital/index.html');
// test 1: Doctype left alone
assert.match(html, /^<!DOCTYPE html>/i);
// test 2: no closing tag
assert.doesNotMatch(html, /<\/!DOCTYPE>/i);
});
it.skip('Doctype can be provided in a layout', async () => {
const html = await fixture.readFile('/in-layout/index.html');
// test 1: doctype is at the front
assert.match(html, /^<!DOCTYPE html>/i);
// test 2: A link inside of the head
const $ = cheerio.load(html);
assert.equal($('head link').length, 1);
});
it('Doctype is added in a layout without one', async () => {
const html = await fixture.readFile('/in-layout-no-doctype/index.html');
// test that doctype is at the front
assert.match(html, /^<!DOCTYPE html>/i);
});
it('Doctype is added in a layout used with markdown pages', async () => {
const html = await fixture.readFile('/in-layout-article/index.html');
// test 1: doctype is at the front
assert.match(html, /^<!DOCTYPE html>/i);
// test 2: A link inside of the head
const $ = cheerio.load(html);
assert.equal($('head link').length, 1);
});
});