Support HEADLESS env variable for unit tests

This patch makes it possible to run unit tests in non-headless
mode with the following command:

```
HEADLESS=false npm run unit
```
This commit is contained in:
Andrey Lushnikov 2017-07-19 19:35:09 -07:00
parent a63a0198de
commit e33a8f818c
3 changed files with 14 additions and 7 deletions

View File

@ -43,16 +43,21 @@ To run puppeteer tests, use:
npm run unit
```
To run phantom-shim against phantomjs tests, use:
```
npm run test-phantom
```
To run both puppeteer and phantom_shim tests, use:
To run all tests, including lints:
```
npm test
```
To debug unit tests:
```
npm run debug-unit
```
To run unit tests in non-headless mode:
```
HEADLESS=false npm run unit
```
## DEBUG module
Puppeteer uses [debug](https://github.com/visionmedia/debug) module to expose some of it's inner guts under the `puppeteer` namespace.
Try putting the following script in the `script.js` and running it via `DEBUG=* node script.js`:

View File

@ -555,6 +555,7 @@ class Page extends EventEmitter {
let node = document.querySelector(selector);
if (!node)
return null;
node.scrollIntoView();
let rect = node.getBoundingClientRect();
return {
x: (rect.left + rect.right) / 2,

View File

@ -30,6 +30,7 @@ let EMPTY_PAGE = PREFIX + '/empty.html';
let HTTPS_PORT = 8908;
let HTTPS_PREFIX = 'https://localhost:' + HTTPS_PORT;
const headless = (process.env.HEADLESS || 'true').trim().toLowerCase() === 'true';
if (process.env.DEBUG_TEST)
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 1000 * 1000;
else
@ -50,7 +51,7 @@ describe('Puppeteer', function() {
let page;
beforeAll(SX(async function() {
browser = new Browser({headless: true, args: ['--no-sandbox']});
browser = new Browser({headless, args: ['--no-sandbox']});
const assetsPath = path.join(__dirname, 'assets');
server = await SimpleServer.create(assetsPath, PORT);
httpsServer = await SimpleServer.createHTTPS(assetsPath, HTTPS_PORT);