diff --git a/clicktests/environment.js b/clicktests/environment.js
index <HASH>..<HASH> 100644
--- a/clicktests/environment.js
+++ b/clicktests/environment.js
@@ -32,6 +32,8 @@ Environment.prototype.init = function(callback) {
 }
 Environment.prototype.shutdown = function(callback) {
   var self = this;
+  this.page.onConsoleMessage = undefined;
+  this.page.onError = undefined;
   this.backgroundAction('POST', this.url + '/api/testing/cleanup', undefined, function() {
     self.shutdownServer(function() {
       callback();
@@ -157,8 +159,6 @@ Environment.prototype.changeTestFile = function(filename, callback) {
   this.backgroundAction('POST', this.url + '/api/testing/changefile', { file: filename }, callback);
 }
 Environment.prototype.shutdownServer = function(callback) {
-  this.page.onConsoleMessage = undefined;
-  this.page.onError = undefined;
   this.backgroundAction('POST', this.url + '/api/testing/shutdown', undefined, callback);
 }
 Environment.prototype.createTempFolder = function(callback) {
Expand scope of removing message listeners during shutdown