Skip to content

Commit

Permalink
Add minimal test framework
Browse files Browse the repository at this point in the history
This patch adds some minimal tests for puppeteer's Page using
Jasmine.
  • Loading branch information
aslushnikov committed May 12, 2017
1 parent 62e6815 commit 6fc5466
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -24,5 +26,8 @@
},
"puppeteer": {
"chromium_revision": "468266"
},
"devDependencies": {
"jasmine": "^2.6.0"
}
}
38 changes: 38 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit 6fc5466

Please sign in to comment.