mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
Add minimal test framework
This patch adds some minimal tests for puppeteer's Page using Jasmine.
This commit is contained in:
parent
62e68159f4
commit
6fc54665e4
12
README.md
12
README.md
@ -30,7 +30,17 @@ node examples/screenshot.js
|
||||
|
||||
### Tests
|
||||
|
||||
Run all tests:
|
||||
```
|
||||
npm test
|
||||
```
|
||||
|
||||
Run phantom.js tests using puppeteer:
|
||||
```
|
||||
./third_party/phantomjs/test/run-tests.py
|
||||
npm run test-phantom
|
||||
```
|
||||
|
||||
Run puppeteer tests:
|
||||
```
|
||||
npm run test-puppeteer
|
||||
```
|
||||
|
@ -4,7 +4,9 @@
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "python third_party/phantomjs/test/run-tests.py",
|
||||
"test-puppeteer": "jasmine test/test.js",
|
||||
"test-phantom": "python third_party/phantomjs/test/run-tests.py",
|
||||
"test": "npm run test-puppeteer && npm run test-phantom",
|
||||
"install": "node install.js"
|
||||
},
|
||||
"author": "The Chromium Authors",
|
||||
@ -24,5 +26,8 @@
|
||||
},
|
||||
"puppeteer": {
|
||||
"chromium_revision": "468266"
|
||||
},
|
||||
"devDependencies": {
|
||||
"jasmine": "^2.6.0"
|
||||
}
|
||||
}
|
||||
|
38
test/test.js
Normal file
38
test/test.js
Normal file
@ -0,0 +1,38 @@
|
||||
var Browser = require('../lib/Browser');
|
||||
|
||||
describe('Page', function() {
|
||||
var browser;
|
||||
var page;
|
||||
|
||||
beforeAll(function() {
|
||||
browser = new Browser();
|
||||
});
|
||||
|
||||
afterAll(function() {
|
||||
browser.close();
|
||||
});
|
||||
|
||||
beforeEach(SX(async function() {
|
||||
page = await browser.newPage();
|
||||
}));
|
||||
|
||||
afterEach(function() {
|
||||
page.close();
|
||||
});
|
||||
|
||||
it('Page.evaluate', SX(async function() {
|
||||
var result = await page.evaluate(() => 7 * 3);
|
||||
expect(result).toBe(21);
|
||||
}));
|
||||
|
||||
it('Page.evaluateAsync', SX(async function() {
|
||||
var result = await page.evaluateAsync(() => Promise.resolve(8 * 7));
|
||||
expect(result).toBe(56);
|
||||
}));
|
||||
});
|
||||
|
||||
// Since Jasmine doesn't like async functions, they should be wrapped
|
||||
// in a SX function.
|
||||
function SX(fun) {
|
||||
return done => Promise.resolve(fun()).then(done).catch(done.fail);
|
||||
}
|
Loading…
Reference in New Issue
Block a user