Skip to content

Commit 6819f50

Browse files
committed
server: Allow --debug mode to reload the browser window
To ease debugging, allow the landing page to be loaded multiple times. Normally, to catch mistakes and bugs, we do not permit this since we would have anywhere to report on a second or third run of test results from the same clientId, since we will have closed that stream and finished the report on that client already.
1 parent 6c06adb commit 6819f50

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/server.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -463,21 +463,25 @@ class ControlServer {
463463
if (!filePath.startsWith(this.root)) {
464464
// Disallow outside directory traversal
465465
this.logger.debug('respond_static_deny', url.pathname);
466-
return this.serveError(resp, 403, 'Forbidden');
466+
return this.serveError(resp, 403, 'HTTP 403: QTap respond_static_deny');
467467
}
468468

469469
const clientId = url.searchParams.get('qtap_clientId');
470470
if (clientId !== null) {
471471
// Serve the testfile from any URL path, as chosen by launchBrowser()
472472
const browser = this.browsers.get(clientId);
473-
if (!browser) {
474-
this.logger.debug('browser_connected_unknown', clientId);
475-
return this.serveError(resp, 403, 'Forbidden');
473+
if (browser) {
474+
browser.logger.debug('browser_connected', `${browser.getDisplayName()} connected! Serving test file.`);
475+
this.eventbus.emit('online', { clientId });
476+
} else if (this.debugMode) {
477+
// Allow users to reload the page when in --debug mode.
478+
// Note that do not handle more TAP results after a given test run has finished.
479+
this.logger.debug('browser_reload_debug', clientId);
480+
} else {
481+
this.logger.debug('browser_unknown_clientId', clientId);
482+
return this.serveError(resp, 403, 'HTTP 403: QTap browser_unknown_clientId.\n\nThis clientId was likely already served and cannot be repeated. Run qtap with --debug to bypass this restriction.');
476483
}
477484

478-
browser.logger.debug('browser_connected', `${browser.getDisplayName()} connected! Serving test file.`);
479-
this.eventbus.emit('online', { clientId });
480-
481485
const testFileResp = await this.getTestFile(clientId);
482486
for (const [name, value] of testFileResp.headers) {
483487
resp.setHeader(name, value);
@@ -490,13 +494,15 @@ class ControlServer {
490494
resp.end();
491495

492496
// Count proxying the test file toward connectTimeout, not idleTimeout.
493-
browser.clientIdleActive = performance.now();
497+
if (browser) {
498+
browser.clientIdleActive = performance.now();
499+
}
494500
return;
495501
}
496502

497503
if (!fs.existsSync(filePath)) {
498504
this.logger.debug('respond_static_notfound', filePath);
499-
return this.serveError(resp, 404, 'Not Found');
505+
return this.serveError(resp, 404, 'HTTP 404: QTap respond_static_notfound');
500506
}
501507

502508
this.logger.debug('respond_static_pipe', filePath);

0 commit comments

Comments
 (0)