From d42fd385c2a465f82caf01be16462f5a6d53ed61 Mon Sep 17 00:00:00 2001 From: Daniel Lawrence Date: Thu, 21 May 2020 10:38:37 -0700 Subject: [PATCH] fix `InvalidStateError` exception This commit fixes #244. The xhr.responseText property cannot be accessed unless xhr.responseType is either 'text' or '', otherwise it throws an error: Uncaught InvalidStateError: Failed to read the 'responseText' property from 'XMLHttpRequest': The value is only accessible if the object's 'responseType' is '' or 'text' (was 'json') This will therefore happen in handleCoverageResponse whenever a request returns falsy. This should never happen, but is occasionally flaking and producing the above error. This commit fixes a few likely culprits: - responseType = `json` was being set after `xhr.send`, which may cause a race condition https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/response - the middleware called res.send with a CoverageMap may receive a non-serializable object, since istanbul CoverageMap provides a toJSON method, implying that the default method may not be serializable - removing now-unused PhantomJS code. - finally, introduces a check to only read from the 'responseText' property in a valid circumstance, and gives a more meaningful error otherwise. --- lib/attach-middleware.js | 2 +- lib/templates/test-body-footer.html | 30 +++++++++++------------------ 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/lib/attach-middleware.js b/lib/attach-middleware.js index 7438391c..8db957d5 100644 --- a/lib/attach-middleware.js +++ b/lib/attach-middleware.js @@ -54,7 +54,7 @@ function reportCoverage(map, root, configPath) { function coverageHandler(map, options, req, res) { writeCoverage(req.body, options.fileLookup, options.root, map); reportCoverage(map, options.root, options.configPath); - res.send(map.getCoverageSummary()); + res.send(map.getCoverageSummary().toJSON()); } // Used when app is in dev mode (`ember serve`). diff --git a/lib/templates/test-body-footer.html b/lib/templates/test-body-footer.html index aff8040e..39b8c7f3 100644 --- a/lib/templates/test-body-footer.html +++ b/lib/templates/test-body-footer.html @@ -1,7 +1,4 @@