diff --git a/README.md b/README.md index 699aa6915f8b0..a60328ce08f97 100644 --- a/README.md +++ b/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 ``` diff --git a/package.json b/package.json index 4fa90178da632..280e54908a536 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/test/test.js b/test/test.js new file mode 100644 index 0000000000000..77d0b34144e9f --- /dev/null +++ b/test/test.js @@ -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); +}