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:
parent
a63a0198de
commit
e33a8f818c
@ -43,16 +43,21 @@ To run puppeteer tests, use:
|
|||||||
npm run unit
|
npm run unit
|
||||||
```
|
```
|
||||||
|
|
||||||
To run phantom-shim against phantomjs tests, use:
|
To run all tests, including lints:
|
||||||
```
|
|
||||||
npm run test-phantom
|
|
||||||
```
|
|
||||||
|
|
||||||
To run both puppeteer and phantom_shim tests, use:
|
|
||||||
```
|
```
|
||||||
npm test
|
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
|
## DEBUG module
|
||||||
Puppeteer uses [debug](https://github.com/visionmedia/debug) module to expose some of it's inner guts under the `puppeteer` namespace.
|
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`:
|
Try putting the following script in the `script.js` and running it via `DEBUG=* node script.js`:
|
||||||
|
@ -555,6 +555,7 @@ class Page extends EventEmitter {
|
|||||||
let node = document.querySelector(selector);
|
let node = document.querySelector(selector);
|
||||||
if (!node)
|
if (!node)
|
||||||
return null;
|
return null;
|
||||||
|
node.scrollIntoView();
|
||||||
let rect = node.getBoundingClientRect();
|
let rect = node.getBoundingClientRect();
|
||||||
return {
|
return {
|
||||||
x: (rect.left + rect.right) / 2,
|
x: (rect.left + rect.right) / 2,
|
||||||
|
@ -30,6 +30,7 @@ let EMPTY_PAGE = PREFIX + '/empty.html';
|
|||||||
let HTTPS_PORT = 8908;
|
let HTTPS_PORT = 8908;
|
||||||
let HTTPS_PREFIX = 'https://localhost:' + HTTPS_PORT;
|
let HTTPS_PREFIX = 'https://localhost:' + HTTPS_PORT;
|
||||||
|
|
||||||
|
const headless = (process.env.HEADLESS || 'true').trim().toLowerCase() === 'true';
|
||||||
if (process.env.DEBUG_TEST)
|
if (process.env.DEBUG_TEST)
|
||||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 1000 * 1000;
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 1000 * 1000;
|
||||||
else
|
else
|
||||||
@ -50,7 +51,7 @@ describe('Puppeteer', function() {
|
|||||||
let page;
|
let page;
|
||||||
|
|
||||||
beforeAll(SX(async function() {
|
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');
|
const assetsPath = path.join(__dirname, 'assets');
|
||||||
server = await SimpleServer.create(assetsPath, PORT);
|
server = await SimpleServer.create(assetsPath, PORT);
|
||||||
httpsServer = await SimpleServer.createHTTPS(assetsPath, HTTPS_PORT);
|
httpsServer = await SimpleServer.createHTTPS(assetsPath, HTTPS_PORT);
|
||||||
|
Loading…
Reference in New Issue
Block a user