/
set-html.test.js
92 lines (78 loc) · 2.58 KB
/
set-html.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { expect } from 'chai';
import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';
describe('set:html', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
before(async () => {
fixture = await loadFixture({
root: './fixtures/set-html/',
});
});
describe('Development', () => {
/** @type {import('./test-utils').DevServer} */
let devServer;
before(async () => {
devServer = await fixture.startDevServer();
globalThis.TEST_FETCH = (fetch, url, init) => {
return fetch(fixture.resolveUrl(url), init);
};
});
after(async () => {
await devServer.stop();
});
it('can take a fetch()', async () => {
let res = await fixture.fetch('/fetch');
expect(res.status).to.equal(200);
let html = await res.text();
const $ = cheerio.load(html);
expect($('#fetched-html')).to.have.a.lengthOf(1);
expect($('#fetched-html').text()).to.equal('works');
});
it('test Fragment when Fragment is as a slot', async () => {
let res = await fixture.fetch('/children');
expect(res.status).to.equal(200);
let html = await res.text();
expect(html).include('Test');
})
});
describe('Build', () => {
before(async () => {
await fixture.build();
});
it('can take a string of HTML', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
expect($('#html-inner')).to.have.a.lengthOf(1);
});
it('can take a Promise to a string of HTML', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
expect($('#promise-html-inner')).to.have.a.lengthOf(1);
});
it('can take a Response to a string of HTML', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
expect($('#response-html-inner')).to.have.a.lengthOf(1);
});
it('can take an Iterator', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
expect($('#iterator-num')).to.have.a.lengthOf(5);
});
it('Can take an AsyncIterator', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
expect($('#asynciterator-num')).to.have.a.lengthOf(5);
});
it('Can take a ReadableStream', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
expect($('#readable-inner')).to.have.a.lengthOf(1);
});
it('test Fragment when Fragment is as a slot', async () => {
let res = await fixture.readFile('/children/index.html');
expect(res).include('Test');
})
});
});