Skip to content

Commit

Permalink
chore(tests): redirect debugError to the output category of tests (#2969
Browse files Browse the repository at this point in the history
)

I have seen some flaky test failures where it would be nice to have run the tests with `DEBUG=puppeteer:error`. Instead of always running tests like that, I am redirecting `debugError` to the output category of the test. This is the same thing that we do for Chromium's stderr.

As a drive-by, I added an additional `debugError` where we were usually a try..finally pattern.
  • Loading branch information
JoelEinbinder authored and aslushnikov committed Jul 30, 2018
1 parent 12e3510 commit c5fe1db
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/Tracing.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const {helper, assert} = require('./helper');
const {helper, assert, debugError} = require('./helper');
const fs = require('fs');

const openAsync = helper.promisify(fs.open);
Expand Down Expand Up @@ -89,6 +89,8 @@ class Tracing {
let resultBuffer = null;
try {
resultBuffer = Buffer.concat(bufs);
} catch (error) {
debugError(error);
} finally {
return resultBuffer;
}
Expand Down
9 changes: 8 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const GOLDEN_DIR = path.join(__dirname, 'golden');
const OUTPUT_DIR = path.join(__dirname, 'output');
const {TestRunner, Reporter, Matchers} = require('../utils/testrunner/');

const {helper, assert} = require('../lib/helper');
const {helper, assert, debugError} = require('../lib/helper');
if (process.env.COVERAGE)
helper.recordPublicAPICoverage();

Expand Down Expand Up @@ -116,9 +116,16 @@ describe('Page', function() {
const rl = require('readline').createInterface({input: state.browser.process().stderr});
test.output = '';
rl.on('line', onLine);
const enableDebugError = !debugError.enabled;
if (enableDebugError) {
require('debug').enable(debugError.namespace);
debugError.log = onLine;
}
state.tearDown = () => {
rl.removeListener('line', onLine);
rl.close();
if (enableDebugError)
debugError.log = () => undefined;
};
function onLine(line) {
test.output += line + '\n';
Expand Down

0 comments on commit c5fe1db

Please sign in to comment.