Skip to content

Commit

Permalink
feat(tests): move /demo to tests directory
Browse files Browse the repository at this point in the history
  • Loading branch information
addyosmani committed Nov 25, 2018
1 parent f3f3f9b commit 9d8ff74
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 54 deletions.
36 changes: 0 additions & 36 deletions demo/index.html

This file was deleted.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"scripts": {
"lint": "eslint src/*.mjs test/*.js",
"lint-fix": "eslint src/*.mjs test/*.js --fix",
"server": "http-server demo",
"test": "mocha test/bootstrap.js --recursive test",
"server": "http-server .",
"test": "npm run build && mocha test/bootstrap.js --recursive test",
"build": "microbundle src/index.mjs --no-sourcemap",
"prepare": "npm run -s build",
"release": "cross-var npm run build -s && cross-var git commit -am $npm_package_version && cross-var git tag $npm_package_version && git push && git push --tags && npm publish --access public"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
32 changes: 29 additions & 3 deletions test/index.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,36 @@
<!DOCTYPE html>
<html>
<head>
<title>Puppeteer Mocha</title>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Prefetch experiments</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" media="screen" href="main.css" />
<script src="https://polyfill.io/v2/polyfill.min.js?features=IntersectionObserver"></script>
</head>
<body>
<h1>Page Title</h1>
<p class='main-content'>Some paragraph text</p>
<a href="1.html">Link 1</a>
<a href="2.html">Link 2</a>
<a href="3.html">Link 3</a>
<section id="stuff">
<a href="main.css">CSS</a>
</section>
<a href="4.html" style="position:absolute;margin-top:900px;">Link 4</a>
<script src="../dist/quicklink.umd.js"></script>
<script>
quicklink();
// quicklink({ priority: 'high' });
</script>
<script type="module">
// import quicklink from "../dist/quicklink.mjs";
// quicklink();
// quicklink({
// urls: ['2.html','4.html']
// });
// let elem = document.getElementById('stuff');
// quicklink({
// el: elem
// });
</script>
</body>
</html>
File renamed without changes.
27 changes: 14 additions & 13 deletions test/sample.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
describe('quicklink tests', function () {
const server = `http://127.0.0.1:8080/test`;
let page;

before(async function () {
Expand All @@ -15,47 +16,47 @@ describe('quicklink tests', function () {
page.on('response', resp => {
responseURLs.push(resp.url());
});
await page.goto('http://127.0.0.1:8080/demo/test-basic-usage.html');
await page.goto(`${server}/test-basic-usage.html`);
await page.waitFor(1000);
expect(responseURLs).to.be.an('array');
expect(responseURLs).to.include('http://127.0.0.1:8080/demo/1.html');
expect(responseURLs).to.include('http://127.0.0.1:8080/demo/2.html');
expect(responseURLs).to.include('http://127.0.0.1:8080/demo/3.html');
expect(responseURLs).to.include(`${server}/1.html`);
expect(responseURLs).to.include(`${server}/2.html`);
expect(responseURLs).to.include(`${server}/3.html`);
});

it('should prefetch in-viewport links correctly (ES Modules)', async function () {
const responseURLs = [];
page.on('response', resp => {
responseURLs.push(resp.url());
});
await page.goto('http://127.0.0.1:8080/demo/test-es-modules.html');
await page.goto(`${server}/test-es-modules.html`);
await page.waitFor(1000);
expect(responseURLs).to.be.an('array');
expect(responseURLs).to.include('http://127.0.0.1:8080/demo/1.html');
expect(responseURLs).to.include('http://127.0.0.1:8080/demo/2.html');
expect(responseURLs).to.include('http://127.0.0.1:8080/demo/3.html');
expect(responseURLs).to.include(`${server}/1.html`);
expect(responseURLs).to.include(`${server}/2.html`);
expect(responseURLs).to.include(`${server}/3.html`);
});

it('should prefetch a static list of URLs correctly', async function () {
const responseURLs = [];
page.on('response', resp => {
responseURLs.push(resp.url());
});
await page.goto('http://127.0.0.1:8080/demo/test-static-url-list.html');
await page.goto(`${server}/test-static-url-list.html`);
await page.waitFor(1000);
expect(responseURLs).to.be.an('array');
expect(responseURLs).to.include('http://127.0.0.1:8080/demo/2.html');
expect(responseURLs).to.include('http://127.0.0.1:8080/demo/4.html');
expect(responseURLs).to.include(`${server}/2.html`);
expect(responseURLs).to.include(`${server}/4.html`);
});

it('should prefetch in-viewport links from a custom DOM source', async function () {
const responseURLs = [];
page.on('response', resp => {
responseURLs.push(resp.url());
});
await page.goto('http://127.0.0.1:8080/demo/test-custom-dom-source.html');
await page.goto(`${server}/test-custom-dom-source.html`);
await page.waitFor(1000);
expect(responseURLs).to.be.an('array');
expect(responseURLs).to.include('http://127.0.0.1:8080/demo/main.css');
expect(responseURLs).to.include(`${server}/main.css`);
});
});
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 9d8ff74

Please sign in to comment.