From 62e0939ce28e5bd03239a637a40fc8a2581aca45 Mon Sep 17 00:00:00 2001
From: Jonas Jenwald <jonas.jenwald@gmail.com>
Date: Sun, 6 Mar 2022 13:57:42 +0100
Subject: [PATCH] Replace XMLHttpRequest usage with the Fetch API in
 `loadStyles` (in `test/driver.js`)

This is another small step in what'll hopefully become a series of patches to implement PR 14287 in smaller steps.
---
 test/driver.js | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/test/driver.js b/test/driver.js
index 13db74f9e..31e4b192f 100644
--- a/test/driver.js
+++ b/test/driver.js
@@ -44,24 +44,23 @@ function loadStyles(styles) {
 
   for (const file of styles) {
     promises.push(
-      new Promise(function (resolve, reject) {
-        const xhr = new XMLHttpRequest();
-        xhr.open("GET", file);
-        xhr.onload = function () {
-          resolve(xhr.responseText);
-        };
-        xhr.onerror = function (e) {
-          reject(new Error(`Error fetching style (${file}): ${e}`));
-        };
-        xhr.send(null);
-      })
+      fetch(file)
+        .then(response => {
+          if (!response.ok) {
+            throw new Error(response.statusText);
+          }
+          return response.text();
+        })
+        .catch(reason => {
+          throw new Error(`Error fetching style (${file}): ${reason}`);
+        })
     );
   }
 
   return Promise.all(promises);
 }
 
-function writeSVG(svgElement, ctx, outputScale) {
+function writeSVG(svgElement, ctx) {
   // We need to have UTF-8 encoded XML.
   const svg_xml = unescape(
     encodeURIComponent(new XMLSerializer().serializeToString(svgElement))