Skip to content

Commit 3ee52bd

Browse files
committed
feat(tests): improve test coverage
1 parent d0b8911 commit 3ee52bd

5 files changed

Lines changed: 138 additions & 5 deletions

File tree

demo/test-basic-usage.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<title>Prefetch: Basic Usage</title>
7+
<meta name="viewport" content="width=device-width, initial-scale=1">
8+
<link rel="stylesheet" type="text/css" media="screen" href="main.css" />
9+
<script src="https://polyfill.io/v2/polyfill.min.js?features=IntersectionObserver"></script>
10+
</head>
11+
<body>
12+
<a href="1.html">Link 1</a>
13+
<a href="2.html">Link 2</a>
14+
<a href="3.html">Link 3</a>
15+
<section id="stuff">
16+
<a href="main.css">CSS</a>
17+
</section>
18+
<a href="4.html" style="position:absolute;margin-top:900px;">Link 4</a>
19+
<script src="../dist/quicklink.umd.js"></script>
20+
<script>
21+
quicklink();
22+
</script>
23+
</body>
24+
</html>

demo/test-custom-dom-source.html

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<title>Prefetch: Custom DOM source</title>
7+
<meta name="viewport" content="width=device-width, initial-scale=1">
8+
<link rel="stylesheet" type="text/css" media="screen" href="main.css" />
9+
<script src="https://polyfill.io/v2/polyfill.min.js?features=IntersectionObserver"></script>
10+
</head>
11+
<body>
12+
<a href="1.html">Link 1</a>
13+
<a href="2.html">Link 2</a>
14+
<a href="3.html">Link 3</a>
15+
<section id="stuff">
16+
<a href="main.css">CSS</a>
17+
</section>
18+
<a href="4.html" style="position:absolute;margin-top:900px;">Link 4</a>
19+
<script src="../dist/quicklink.umd.js"></script>
20+
<script>
21+
let elem = document.getElementById('stuff');
22+
quicklink({
23+
el: elem
24+
});
25+
</script>
26+
</body>
27+
</html>

demo/test-es-modules.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<title>Prefetch: ES Modules</title>
7+
<meta name="viewport" content="width=device-width, initial-scale=1">
8+
<link rel="stylesheet" type="text/css" media="screen" href="main.css" />
9+
<script src="https://polyfill.io/v2/polyfill.min.js?features=IntersectionObserver"></script>
10+
</head>
11+
<body>
12+
<a href="1.html">Link 1</a>
13+
<a href="2.html">Link 2</a>
14+
<a href="3.html">Link 3</a>
15+
<section id="stuff">
16+
<a href="main.css">CSS</a>
17+
</section>
18+
<a href="4.html" style="position:absolute;margin-top:900px;">Link 4</a>
19+
<script type="module">
20+
import quicklink from "../dist/quicklink.mjs";
21+
quicklink();
22+
</script>
23+
</body>
24+
</html>

demo/test-static-url-list.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<title>Prefetch: Static URL list</title>
7+
<meta name="viewport" content="width=device-width, initial-scale=1">
8+
<link rel="stylesheet" type="text/css" media="screen" href="main.css" />
9+
<script src="https://polyfill.io/v2/polyfill.min.js?features=IntersectionObserver"></script>
10+
</head>
11+
<body>
12+
<a href="1.html">Link 1</a>
13+
<a href="2.html">Link 2</a>
14+
<a href="3.html">Link 3</a>
15+
<section id="stuff">
16+
<a href="main.css">CSS</a>
17+
</section>
18+
<a href="4.html" style="position:absolute;margin-top:900px;">Link 4</a>
19+
<script src="../dist/quicklink.umd.js"></script>
20+
<script>
21+
quicklink({
22+
urls: ['2.html','4.html']
23+
});
24+
</script>
25+
</body>
26+
</html>

test/sample.spec.js

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,59 @@ describe('quicklink tests', function () {
33

44
before(async function () {
55
page = await browser.newPage();
6-
await page.goto('http://127.0.0.1:8080/demo/index.html');
6+
// await page.goto('http://127.0.0.1:8080/demo/index.html');
77
});
88

99
after(async function () {
1010
await page.close();
1111
});
1212

13-
it('should have the correct page title', async function () {
14-
expect(await page.title()).to.eql('Prefetch experiments');
13+
it('should prefetch in-viewport links correctly (UMD)', async function () {
14+
const responseURLs = [];
15+
page.on('response', resp => {
16+
responseURLs.push(resp.url());
17+
});
18+
await page.goto('http://127.0.0.1:8080/demo/test-basic-usage.html');
19+
await page.waitFor(1000);
20+
expect(responseURLs).to.be.an('array');
21+
expect(responseURLs).to.include('http://127.0.0.1:8080/demo/2.html');
22+
expect(responseURLs).to.include('http://127.0.0.1:8080/demo/2.html');
23+
expect(responseURLs).to.include('http://127.0.0.1:8080/demo/3.html');
1524
});
1625

17-
it('should prefetch pages correctly', async function () {
26+
it('should prefetch in-viewport links correctly (ES Modules)', async function () {
1827
const responseURLs = [];
1928
page.on('response', resp => {
2029
responseURLs.push(resp.url());
2130
});
22-
await page.goto('http://127.0.0.1:8080/demo/index.html');
31+
await page.goto('http://127.0.0.1:8080/demo/test-es-modules.html');
2332
await page.waitFor(1000);
2433
expect(responseURLs).to.be.an('array');
2534
expect(responseURLs).to.include('http://127.0.0.1:8080/demo/2.html');
2635
expect(responseURLs).to.include('http://127.0.0.1:8080/demo/2.html');
2736
expect(responseURLs).to.include('http://127.0.0.1:8080/demo/3.html');
2837
});
38+
39+
it('should prefetch a static list of URLs correctly', async function () {
40+
const responseURLs = [];
41+
page.on('response', resp => {
42+
responseURLs.push(resp.url());
43+
});
44+
await page.goto('http://127.0.0.1:8080/demo/test-static-url-list.html');
45+
await page.waitFor(1000);
46+
expect(responseURLs).to.be.an('array');
47+
expect(responseURLs).to.include('http://127.0.0.1:8080/demo/2.html');
48+
expect(responseURLs).to.include('http://127.0.0.1:8080/demo/4.html');
49+
});
50+
51+
it('should prefetch in-viewport links from a custom DOM source', async function () {
52+
const responseURLs = [];
53+
page.on('response', resp => {
54+
responseURLs.push(resp.url());
55+
});
56+
await page.goto('http://127.0.0.1:8080/demo/test-custom-dom-source.html');
57+
await page.waitFor(1000);
58+
expect(responseURLs).to.be.an('array');
59+
expect(responseURLs).to.include('http://127.0.0.1:8080/demo/main.css');
60+
});
2961
});

0 commit comments

Comments
 (0)