From 3ee52bdd273c59e6440f02166efb7173dd3091da Mon Sep 17 00:00:00 2001 From: addyosmani Date: Sat, 24 Nov 2018 22:50:00 -0800 Subject: [PATCH] feat(tests): improve test coverage --- demo/test-basic-usage.html | 24 ++++++++++++++++++ demo/test-custom-dom-source.html | 27 ++++++++++++++++++++ demo/test-es-modules.html | 24 ++++++++++++++++++ demo/test-static-url-list.html | 26 ++++++++++++++++++++ test/sample.spec.js | 42 ++++++++++++++++++++++++++++---- 5 files changed, 138 insertions(+), 5 deletions(-) create mode 100644 demo/test-basic-usage.html create mode 100644 demo/test-custom-dom-source.html create mode 100644 demo/test-es-modules.html create mode 100644 demo/test-static-url-list.html diff --git a/demo/test-basic-usage.html b/demo/test-basic-usage.html new file mode 100644 index 00000000..b1bf7ba5 --- /dev/null +++ b/demo/test-basic-usage.html @@ -0,0 +1,24 @@ + + + + + + Prefetch: Basic Usage + + + + + + Link 1 + Link 2 + Link 3 +
+ CSS +
+ Link 4 + + + + \ No newline at end of file diff --git a/demo/test-custom-dom-source.html b/demo/test-custom-dom-source.html new file mode 100644 index 00000000..70f6ddac --- /dev/null +++ b/demo/test-custom-dom-source.html @@ -0,0 +1,27 @@ + + + + + + Prefetch: Custom DOM source + + + + + + Link 1 + Link 2 + Link 3 +
+ CSS +
+ Link 4 + + + + \ No newline at end of file diff --git a/demo/test-es-modules.html b/demo/test-es-modules.html new file mode 100644 index 00000000..c75dc222 --- /dev/null +++ b/demo/test-es-modules.html @@ -0,0 +1,24 @@ + + + + + + Prefetch: ES Modules + + + + + + Link 1 + Link 2 + Link 3 +
+ CSS +
+ Link 4 + + + \ No newline at end of file diff --git a/demo/test-static-url-list.html b/demo/test-static-url-list.html new file mode 100644 index 00000000..35b20ab9 --- /dev/null +++ b/demo/test-static-url-list.html @@ -0,0 +1,26 @@ + + + + + + Prefetch: Static URL list + + + + + + Link 1 + Link 2 + Link 3 +
+ CSS +
+ Link 4 + + + + \ No newline at end of file diff --git a/test/sample.spec.js b/test/sample.spec.js index 8ef92677..45374c22 100644 --- a/test/sample.spec.js +++ b/test/sample.spec.js @@ -3,27 +3,59 @@ describe('quicklink tests', function () { before(async function () { page = await browser.newPage(); - await page.goto('http://127.0.0.1:8080/demo/index.html'); + // await page.goto('http://127.0.0.1:8080/demo/index.html'); }); after(async function () { await page.close(); }); - it('should have the correct page title', async function () { - expect(await page.title()).to.eql('Prefetch experiments'); + it('should prefetch in-viewport links correctly (UMD)', async function () { + const responseURLs = []; + page.on('response', resp => { + responseURLs.push(resp.url()); + }); + await page.goto('http://127.0.0.1:8080/demo/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/2.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'); }); - it('should prefetch pages correctly', async function () { + 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/index.html'); + await page.goto('http://127.0.0.1:8080/demo/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/2.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'); }); + + 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.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'); + }); + + 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.waitFor(1000); + expect(responseURLs).to.be.an('array'); + expect(responseURLs).to.include('http://127.0.0.1:8080/demo/main.css'); + }); });