Skip to content

Commit

Permalink
Support HEADLESS env variable for unit tests
Browse files Browse the repository at this point in the history
This patch makes it possible to run unit tests in non-headless
mode with the following command:

```
HEADLESS=false npm run unit
```
  • Loading branch information
aslushnikov committed Jul 20, 2017
1 parent a63a019 commit e33a8f8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
13 changes: 9 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,19 @@ To run puppeteer tests, use:
npm run unit
```

To run phantom-shim against phantomjs tests, use:
To run all tests, including lints:
```
npm run test-phantom
npm test
```

To run both puppeteer and phantom_shim tests, use:
To debug unit tests:
```
npm test
npm run debug-unit
```

To run unit tests in non-headless mode:
```
HEADLESS=false npm run unit
```

## DEBUG module
Expand Down
1 change: 1 addition & 0 deletions lib/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down

0 comments on commit e33a8f8

Please sign in to comment.