summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWinnie Hellmann <winnie@gitlab.com>2018-04-23 13:25:22 +0200
committerWinnie Hellmann <winnie@gitlab.com>2018-04-23 13:29:38 +0200
commita22e7bb91122d5373acc691184bc26b977bd3ec8 (patch)
treed129ea06c36614c30266d4e76da90be694e2ee60
parent508ad87ed70bb74da01f8da4ffc5fbe7cb137db9 (diff)
downloadgitlab-ce-winh-fail-unmocked-requests.tar.gz
Fail tests for non-mocked Ajax requestswinh-fail-unmocked-requests
-rw-r--r--spec/javascripts/test_bundle.js14
1 files changed, 14 insertions, 0 deletions
diff --git a/spec/javascripts/test_bundle.js b/spec/javascripts/test_bundle.js
index 14bff05e537..5fd094976a9 100644
--- a/spec/javascripts/test_bundle.js
+++ b/spec/javascripts/test_bundle.js
@@ -80,6 +80,20 @@ if (testFiles.length > 0) {
console.log('Running all tests');
}
+beforeAll(() => {
+ const allowedAjaxUrls = [FIXTURES_PATH, window.location.origin, '/_karma_webpack_/'];
+
+ const openRequest = XMLHttpRequest.prototype.open;
+ XMLHttpRequest.prototype.open = function requestFallback(method, url, ...args) {
+ if (allowedAjaxUrls.find(allowedUrl => url.indexOf(allowedUrl) === 0)) {
+ openRequest.apply(this, method, url, args);
+ return;
+ }
+
+ fail(`Ajax request was not mocked: ${method} ${url}`);
+ };
+});
+
// render all of our tests
const testsContext = require.context('.', true, /_spec$/);
testsContext.keys().forEach(function(path) {