DEV: Update pretender and fake-xml-http-request (#13937)

DEV: Update pretender and fake-xml-http-request (#13937)

We are still on a version of pretender since 2017 Release v1.6.1 · pretenderjs/pretender · GitHub

Since then many changes have been made, including adding support for xhr.upload. Upgrading will let us write proper acceptance tests for uppy, which uses XmlHTTPRequest internally including xhr.upload.

Updates pretender to 3.4.7 and fake-xml-http-request to 2.1.2.

Note: There have been no breaking changes in the releases that would affect us, mainly dropping support for old node versions.

diff --git a/app/assets/javascripts/discourse/package.json b/app/assets/javascripts/discourse/package.json
index 99aaf01..1f66aa4 100644
--- a/app/assets/javascripts/discourse/package.json
+++ b/app/assets/javascripts/discourse/package.json
@@ -54,7 +54,7 @@
     "message-bus-client": "^3.3.0",
     "mousetrap": "^1.6.5",
     "mousetrap-global-bind": "^1.1.0",
-    "pretender": "^3.4.3",
+    "pretender": "^3.4.7",
     "pretty-text": "^1.0.0",
     "qunit": "^2.14.0",
     "qunit-dom": "^1.6.0",
diff --git a/app/assets/javascripts/yarn.lock b/app/assets/javascripts/yarn.lock
index 76e24fe..236a56c 100644
--- a/app/assets/javascripts/yarn.lock
+++ b/app/assets/javascripts/yarn.lock
@@ -5935,7 +5935,7 @@ extsprintf@^1.2.0:
   resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.4.0.tgz#e2689f8f356fad62cca65a3a91c5df5f9551692f"
   integrity sha1-4mifjzVvrWLMplo6kcXfX5VRaS8=
 
-fake-xml-http-request@^2.1.1:
+fake-xml-http-request@^2.1.2:
   version "2.1.2"
   resolved "https://registry.yarnpkg.com/fake-xml-http-request/-/fake-xml-http-request-2.1.2.tgz#f1786720cae50bbb46273035a0173414f3e85e74"
   integrity sha512-HaFMBi7r+oEC9iJNpc3bvcW7Z7iLmM26hPDmlb0mFwyANSsOQAtJxbdWsXITKOzZUyMYK0zYCv3h5yDj9TsiXg==
@@ -9347,12 +9347,12 @@ prepend-http@^2.0.0:
   resolved "https://registry.yarnpkg.com/prepend-http/-/prepend-http-2.0.0.tgz#e92434bfa5ea8c19f41cdfd401d741a3c819d897"
   integrity sha1-6SQ0v6XqjBn0HN/UAddBo8gZ2Jc=
 
-pretender@^3.4.3:
-  version "3.4.3"
-  resolved "https://registry.yarnpkg.com/pretender/-/pretender-3.4.3.tgz#a3b4160516007075d29127262f3a0063d19896e9"
-  integrity sha512-AlbkBly9R8KR+R0sTCJ/ToOeEoUMtt52QVCetui5zoSmeLOU3S8oobFsyPLm1O2txR6t58qDNysqPnA1vVi8Hg==
+pretender@^3.4.7:
+  version "3.4.7"
+  resolved "https://registry.yarnpkg.com/pretender/-/pretender-3.4.7.tgz#34a2ae2d1fc9db440a990d50e6c0f5481d8755fc"
+  integrity sha512-jkPAvt1BfRi0RKamweJdEcnjkeu7Es8yix3bJ+KgBC5VpG/Ln4JE3hYN6vJym4qprm8Xo5adhWpm3HCoft1dOw==
   dependencies:
-    fake-xml-http-request "^2.1.1"
+    fake-xml-http-request "^2.1.2"
     route-recognizer "^0.3.3"
 
 printf@^0.6.1:
diff --git a/lib/tasks/javascript.rake b/lib/tasks/javascript.rake
index 510a1ff..2914940 100644
--- a/lib/tasks/javascript.rake
+++ b/lib/tasks/javascript.rake
@@ -188,7 +188,10 @@ def dependencies
       source: 'qunit/qunit/qunit.js'
     },
     {
-      source: 'pretender/pretender.js'
+      source: 'pretender/dist/pretender.js'
+    },
+    {
+      source: 'fake-xml-http-request/fake_xml_http_request.js'
     },
     {
       source: 'sinon/pkg/sinon.js'
diff --git a/package.json b/package.json
index 39a7c9e..abcdfe6 100644
--- a/package.json
+++ b/package.json
@@ -51,7 +51,7 @@
     "chrome-launcher": "^0.12.0",
     "chrome-remote-interface": "^0.25",
     "lodash-cli": "https://github.com/lodash-archive/lodash-cli.git",
-    "pretender": "^1.6",
+    "pretender": "^3.4.7",
     "puppeteer": "1.20",
     "qunit": "2.8.0",
     "route-recognizer": "^0.3.3",
diff --git a/vendor/assets/javascripts/fake_xml_http_request.js b/vendor/assets/javascripts/fake_xml_http_request.js
index 0284c65..3537cc2 100644
--- a/vendor/assets/javascripts/fake_xml_http_request.js
+++ b/vendor/assets/javascripts/fake_xml_http_request.js
@@ -1,480 +1,530 @@
-(function(undefined){
-/**
- * Minimal Event interface implementation
- *
- * Original implementation by Sven Fuchs: https://gist.github.com/995028
- * Modifications and tests by Christian Johansen.
- *
- * @author Sven Fuchs (svenfuchs@artweb-design.de)
- * @author Christian Johansen (christian@cjohansen.no)
- * @license BSD
- *
- * Copyright (c) 2011 Sven Fuchs, Christian Johansen
- */
-
-var _Event = function Event(type, bubbles, cancelable, target) {
-  this.type = type;
-  this.bubbles = bubbles;
-  this.cancelable = cancelable;
-  this.target = target;
-};
-
-_Event.prototype = {
-  stopPropagation: function () {},
-  preventDefault: function () {
-    this.defaultPrevented = true;
-  }
-};
-
-/*
-  Used to set the statusText property of an xhr object
-*/
-var httpStatusCodes = {
-  100: "Continue",
-  101: "Switching Protocols",
-  200: "OK",
-  201: "Created",
-  202: "Accepted",
-  203: "Non-Authoritative Information",
-  204: "No Content",
-  205: "Reset Content",
-  206: "Partial Content",
-  300: "Multiple Choice",
-  301: "Moved Permanently",
-  302: "Found",
-  303: "See Other",
-  304: "Not Modified",
-  305: "Use Proxy",
-  307: "Temporary Redirect",
-  400: "Bad Request",
-  401: "Unauthorized",
-  402: "Payment Required",
-  403: "Forbidden",
-  404: "Not Found",
-  405: "Method Not Allowed",
-  406: "Not Acceptable",
-  407: "Proxy Authentication Required",
-  408: "Request Timeout",
-  409: "Conflict",
-  410: "Gone",
-  411: "Length Required",
-  412: "Precondition Failed",
-  413: "Request Entity Too Large",
-  414: "Request-URI Too Long",
-  415: "Unsupported Media Type",
-  416: "Requested Range Not Satisfiable",
-  417: "Expectation Failed",
-  422: "Unprocessable Entity",
-  500: "Internal Server Error",
-  501: "Not Implemented",
-  502: "Bad Gateway",
-  503: "Service Unavailable",
-  504: "Gateway Timeout",
-  505: "HTTP Version Not Supported"
-};
-
-
-/*
-  Cross-browser XML parsing. Used to turn
-  XML responses into Document objects
-  Borrowed from JSpec
-*/
-function parseXML(text) {
-  var xmlDoc;
-
-  if (typeof DOMParser != "undefined") {
-    var parser = new DOMParser();
-    xmlDoc = parser.parseFromString(text, "text/xml");
-  } else {
-    xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
-    xmlDoc.async = "false";
-    xmlDoc.loadXML(text);
-  }
-
-  return xmlDoc;
-}
-
-/*
-  Without mocking, the native XMLHttpRequest object will throw
-  an error when attempting to set these headers. We match this behavior.
-*/
-var unsafeHeaders = {
-  "Accept-Charset": true,
-  "Accept-Encoding": true,
-  "Connection": true,
-  "Content-Length": true,
-  "Cookie": true,
-  "Cookie2": true,
-  "Content-Transfer-Encoding": true,
-  "Date": true,
-  "Expect": true,
-  "Host": true,
-  "Keep-Alive": true,
-  "Referer": true,
-  "TE": true,
-  "Trailer": true,
-  "Transfer-Encoding": true,
-  "Upgrade": true,
-  "User-Agent": true,
-  "Via": true
-};
-
-/*
-  Adds an "event" onto the fake xhr object
-  that just calls the same-named method. This is
-  in case a library adds callbacks for these events.
-*/
-function _addEventListener(eventName, xhr){
-  xhr.addEventListener(eventName, function (event) {
-    var listener = xhr["on" + eventName];
-
-    if (listener && typeof listener == "function") {
-      listener(event);
+(function (global, factory) {
+  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
+  typeof define === 'function' && define.amd ? define(factory) :
+  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.FakeXMLHttpRequest = factory());
+}(this, (function () { 'use strict';
+
+  /**
+   * Minimal Event interface implementation
+   *
+   * Original implementation by Sven Fuchs: https://gist.github.com/995028
+   * Modifications and tests by Christian Johansen.
+   *
+   * @author Sven Fuchs (svenfuchs@artweb-design.de)
+   * @author Christian Johansen (christian@cjohansen.no)
+   * @license BSD
+   *
+   * Copyright (c) 2011 Sven Fuchs, Christian Johansen
+   */
+
+  var _Event = function Event(type, bubbles, cancelable, target) {
+    this.type = type;
+    this.bubbles = bubbles;
+    this.cancelable = cancelable;
+    this.target = target;
+  };
+
+  _Event.prototype = {
+    stopPropagation: function () {},
+    preventDefault: function () {
+      this.defaultPrevented = true;
     }
-  });
-}
-
-/*
-  Constructor for a fake window.XMLHttpRequest
-*/
-function FakeXMLHttpRequest() {
-  this.readyState = FakeXMLHttpRequest.UNSENT;
-  this.requestHeaders = {};
-  this.requestBody = null;
-  this.status = 0;
-  this.statusText = "";
-
-  this._eventListeners = {};
-  var events = ["loadstart", "load", "abort", "loadend"];

[... diff too long, it was truncated ...]

GitHub sha: d8a0d2262c3fc8ef4313a1f05c5755aa94a3d4b6

This commit appears in #13937 which was approved by ZogStriP and CvX. It was merged by martin.