-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstart-web-server.spec.js
52 lines (42 loc) · 2.17 KB
/
start-web-server.spec.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
// Mocha Specification Suite
// Imports
import puppeteer from 'puppeteer';
import { assertDeepStrictEqual } from 'assert-deep-strict-equal';
import { browserReady } from '../dist/puppeteer-browser-ready.js'; //replace with: ...from 'puppeteer-browser-ready';
// Setup
const options = { folder: 'spec/fixtures', verbose: false };
const webPath = 'sample.html';
describe('Start Web Server specification suite', () => {
let http; //fields: server, terminator, folder, url, port, verbose
before(async () => http = await browserReady.startWebServer(options));
after(async () => await browserReady.shutdownWebServer(http));
/////////////////////////////////////////////////////////////////////////////////////
describe('The sample web page', () => {
let web; //fields: browser, page, response, status, location, title, html, root
before(async () => web = await puppeteer.launch().then(browserReady.goto(http.url + webPath)));
after(async () => await browserReady.close(web));
it('has the correct URL', () => {
const actual = { status: web.status, url: web.location.href };
const expected = { status: 200, url: http.url + webPath };
assertDeepStrictEqual(actual, expected);
});
it('title is "Sample Web Page"', () => {
const actual = { title: web.title };
const expected = { title: 'Sample Web Page' };
assertDeepStrictEqual(actual, expected);
});
it('body has exactly one header, main, and footer -- node-html-parsed', () => {
const getTags = (elems) => [...elems].map(elem => elem.tagName.toLowerCase());
const actual = getTags(web.root.querySelectorAll('body >*'));
const expected = ['header', 'main', 'footer'];
assertDeepStrictEqual(actual, expected);
});
it('body has exactly one header, main, and footer -- page.$$eval()', async () => {
const getTags = (elems) => elems.map(elem => elem.nodeName.toLowerCase());
const actual = await web.page.$$eval('body >*', getTags);
const expected = ['header', 'main', 'footer'];
assertDeepStrictEqual(actual, expected);
});
});
////////////////////////////////////////////////////////////////////////////////
});