Add minimal test framework

This patch adds some minimal tests for puppeteer's Page using
Jasmine.
This commit is contained in:
Andrey Lushnikov 2017-05-12 16:36:37 -07:00
parent 62e68159f4
commit 6fc54665e4
3 changed files with 55 additions and 2 deletions

View File

@ -30,7 +30,17 @@ node examples/screenshot.js
### Tests ### Tests
Run all tests:
```
npm test
```
Run phantom.js tests using puppeteer: Run phantom.js tests using puppeteer:
``` ```
./third_party/phantomjs/test/run-tests.py npm run test-phantom
```
Run puppeteer tests:
```
npm run test-puppeteer
``` ```

View File

@ -4,7 +4,9 @@
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"scripts": { "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" "install": "node install.js"
}, },
"author": "The Chromium Authors", "author": "The Chromium Authors",
@ -24,5 +26,8 @@
}, },
"puppeteer": { "puppeteer": {
"chromium_revision": "468266" "chromium_revision": "468266"
},
"devDependencies": {
"jasmine": "^2.6.0"
} }
} }

38
test/test.js Normal file
View 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);
}