-
Notifications
You must be signed in to change notification settings - Fork 412
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tests refactoring): add mocha, chai tests with puppeteer
- Loading branch information
1 parent
fd81b71
commit d0b8911
Showing
7 changed files
with
372 additions
and
1,995 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const puppeteer = require('puppeteer'); | ||
const {expect} = require('chai'); | ||
const _ = require('lodash'); | ||
const globalVariables = _.pick(global, ['browser', 'expect']); | ||
|
||
// puppeteer options | ||
const opts = { | ||
headless: false, | ||
slowMo: 100, | ||
timeout: 10000, | ||
}; | ||
|
||
// expose variables | ||
before(async function () { | ||
global.expect = expect; | ||
global.browser = await puppeteer.launch(opts); | ||
}); | ||
|
||
// close browser and reset global variables | ||
after(function () { | ||
browser.close(); | ||
|
||
global.browser = globalVariables.browser; | ||
global.expect = globalVariables.expect; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Puppeteer Mocha</title> | ||
</head> | ||
<body> | ||
<h1>Page Title</h1> | ||
<p class='main-content'>Some paragraph text</p> | ||
</body> | ||
</html> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
describe('quicklink tests', function () { | ||
let page; | ||
|
||
before(async function () { | ||
page = await browser.newPage(); | ||
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 pages correctly', 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.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'); | ||
}); | ||
}); |
Oops, something went wrong.