|
1 | 1 | // Dependencies |
2 | 2 | const { expect } = require('chai'); |
3 | | -const express = require('express'); |
4 | | -const puppeteer = require('puppeteer'); |
5 | | - |
6 | | -// Globals |
7 | | -let APP = null; |
8 | | -let PAGE = null; |
9 | | -let SERVER = null; |
10 | | -let BROWSER = null; |
11 | 3 |
|
12 | 4 | // Helpers |
13 | 5 | const Helpers = require('../src/helpers.js'); |
14 | 6 |
|
15 | 7 | // Helpers assertions |
16 | 8 | describe('Helpers', () => { |
17 | | - before((done) => { |
18 | | - // Start Express server |
19 | | - APP = express(); |
20 | | - |
21 | | - // Serve static files |
22 | | - APP.use(express.static(__dirname)); |
23 | | - |
24 | | - // Listen port |
25 | | - SERVER = APP.listen(3000, () => { |
26 | | - // Start Puppeteer |
27 | | - puppeteer.launch({ headless: false }).then(browser => { |
28 | | - // Save browser |
29 | | - BROWSER = browser; |
30 | | - |
31 | | - // Create page |
32 | | - BROWSER.newPage().then(page => { |
33 | | - // Save page |
34 | | - PAGE = page; |
35 | | - |
36 | | - // Go to Express server |
37 | | - PAGE.goto('http://localhost:3000').then(() => done()); |
38 | | - }); |
39 | | - }); |
40 | | - }); |
41 | | - }); |
42 | | - |
43 | 9 | describe('Helpers.getOrigin', () => { |
44 | 10 | it('Should return `http://bar.com` from `http://bar.com/foo/bar` URL.', () => { |
45 | 11 | // Fake URL |
@@ -147,14 +113,11 @@ describe('Helpers', () => { |
147 | 113 |
|
148 | 114 | describe('Helpers.getTitle', () => { |
149 | 115 | it('Should return the `title` value from a given HTML', () => { |
150 | | - // Get HTML |
151 | | - // PAGE.evaluate(() => { |
152 | | - // // Get HTML |
153 | | - // const html = document.documentElement.outerHTML; |
154 | | - |
155 | | - // // Assertion |
156 | | - // expect(Helpers.getTitle(html)).to.be.equal('Puppeteer'); |
157 | | - // }); |
| 116 | + // Fake HTML |
| 117 | + const html = '<title>Hello</title>'; |
| 118 | + |
| 119 | + // Assertion |
| 120 | + expect(Helpers.getTitle(html)).to.be.equal('Hello'); |
158 | 121 | }); |
159 | 122 |
|
160 | 123 | it('Should return the nothing if no title a given HTML', () => { |
@@ -184,12 +147,4 @@ describe('Helpers', () => { |
184 | 147 | expect(Helpers.camelize(string)).to.be.equal('both'); |
185 | 148 | }); |
186 | 149 | }); |
187 | | - |
188 | | - after((done) => { |
189 | | - // Close Express server |
190 | | - SERVER.close(); |
191 | | - |
192 | | - // Close Puppeteer server |
193 | | - BROWSER.close().then(() => done()); |
194 | | - }); |
195 | 150 | }); |
0 commit comments