Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose Puppeteer polling mechanism. #40

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ args.option('file', 'Path to the page which contains tests (required)')
.option('height', 'Viewport height', undefined, parseInt)
.option('executablePath', 'Chrome executable path', undefined, String)
.option('visible', 'Show Chrome window', undefined, Boolean)
.option('polling', 'Puppeteer polling mechanism', undefined, String)
.example('mocha-headless-chrome -f test.html', 'Run tests on the "test.html" page')
.example('mocha-headless-chrome -f http://localhost:8080', 'Run tests on the remote page')
.example('mocha-headless-chrome -f test.html -a no-sandbox -a disable-setuid-sandbox', 'Pass the Chrome arguments')
Expand Down
5 changes: 5 additions & 0 deletions lib/runner.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ interface Options {
* Whether to show the Chrome window.
*/
visible?: boolean;

/**
* Puppeteer polling mechanism.
*/
polling?: string;
}

/**
Expand Down
5 changes: 3 additions & 2 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function prepareUrl(filePath) {
return `file://${resolvedPath}`;
}

exports.runner = function ({ file, reporter, timeout, width, height, args, executablePath, visible }) {
exports.runner = function ({ file, reporter, timeout, width, height, args, executablePath, visible, polling }) {
return new Promise(resolve => {

// validate options
Expand All @@ -161,6 +161,7 @@ exports.runner = function ({ file, reporter, timeout, width, height, args, execu

args = [].concat(args || []).map(arg => '--' + arg);
!timeout && (timeout = 60000);
/^\d+$/.test(polling) && (polling = parseInt(polling));

const url = prepareUrl(file);

Expand All @@ -183,7 +184,7 @@ exports.runner = function ({ file, reporter, timeout, width, height, args, execu

return page.evaluateOnNewDocument(initMocha, reporter)
.then(() => page.goto(url))
.then(() => page.waitForFunction(() => window.__mochaResult__, { timeout: timeout }))
.then(() => page.waitForFunction(() => window.__mochaResult__, { timeout, polling }))
.then(() => page.evaluate(() => window.__mochaResult__))
.then(obj => {
browser.close();
Expand Down