From b624179b8d7b138c756b98f6c912ae282f7d31c1 Mon Sep 17 00:00:00 2001
From: chris48s <chris48s@users.noreply.github.com>
Date: Mon, 29 Aug 2022 20:58:10 +0100
Subject: [PATCH] get the tests passing on windows (#8350)

* run the core tests on windows

* fix glob with windows path seperator

* always use slash when slicing serviceClass matches

..and add comment explaining why we need to do this

* strip line endings (+ any other whitspace) before base64 encoding

Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
---
 .github/workflows/test-main.yml |  7 ++++++-
 core/base-service/loader.js     | 15 ++++++++++++---
 lib/logos.spec.js               |  4 ++--
 lib/svg-helpers.js              |  4 +++-
 4 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/.github/workflows/test-main.yml b/.github/workflows/test-main.yml
index e07463cd21..e57fdc59a0 100644
--- a/.github/workflows/test-main.yml
+++ b/.github/workflows/test-main.yml
@@ -7,7 +7,12 @@ on:
 
 jobs:
   test-main:
-    runs-on: ubuntu-latest
+    strategy:
+      matrix:
+        os: ['ubuntu-latest', 'windows-latest']
+
+    runs-on: ${{ matrix.os }}
+
     steps:
       - name: Checkout
         uses: actions/checkout@v3
diff --git a/core/base-service/loader.js b/core/base-service/loader.js
index cf499eca15..9bbf0c948d 100644
--- a/core/base-service/loader.js
+++ b/core/base-service/loader.js
@@ -13,6 +13,13 @@ const serviceDir = path.join(
   'services'
 )
 
+function toUnixPath(path) {
+  // glob does not allow \ as a path separator
+  // see https://github.com/isaacs/node-glob/blob/main/changelog.md#80
+  // so we need to convert to use / for use with glob
+  return path.replace(/\\/g, '/')
+}
+
 class InvalidService extends Error {
   constructor(message) {
     super(message)
@@ -22,7 +29,9 @@ class InvalidService extends Error {
 
 async function loadServiceClasses(servicePaths) {
   if (!servicePaths) {
-    servicePaths = glob.sync(path.join(serviceDir, '**', '*.service.js'))
+    servicePaths = glob.sync(
+      toUnixPath(path.join(serviceDir, '**', '*.service.js'))
+    )
   }
 
   const serviceClasses = []
@@ -42,8 +51,8 @@ async function loadServiceClasses(servicePaths) {
       if (serviceClass && serviceClass.prototype instanceof BaseService) {
         // Decorate each service class with the directory that contains it.
         serviceClass.serviceFamily = servicePath
-          .replace(serviceDir, '')
-          .split(path.sep)[1]
+          .replace(toUnixPath(serviceDir), '')
+          .split('/')[1]
         serviceClass.validateDefinition()
         return serviceClasses.push(serviceClass)
       }
diff --git a/lib/logos.spec.js b/lib/logos.spec.js
index 0d6eaae400..cc2e415c72 100644
--- a/lib/logos.spec.js
+++ b/lib/logos.spec.js
@@ -33,7 +33,7 @@ describe('Logo helpers', function () {
   test(prepareNamedLogo, () => {
     // NPM uses multiple colors so the color param should be ignored
     const npmLogo =
-      'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0MCA0MCI+PHBhdGggZD0iTTAgMGg0MHY0MEgwVjB6IiBmaWxsPSIjY2IwMDAwIi8+PHBhdGggZmlsbD0iI2ZmZiIgZD0iTTcgN2gyNnYyNmgtN1YxNGgtNnYxOUg3eiIvPjwvc3ZnPgo='
+      'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0MCA0MCI+PHBhdGggZD0iTTAgMGg0MHY0MEgwVjB6IiBmaWxsPSIjY2IwMDAwIi8+PHBhdGggZmlsbD0iI2ZmZiIgZD0iTTcgN2gyNnYyNmgtN1YxNGgtNnYxOUg3eiIvPjwvc3ZnPg=='
     given({ name: 'npm' }).expect(npmLogo)
     given({ name: 'npm', color: 'blue' }).expect(npmLogo)
 
@@ -115,7 +115,7 @@ describe('Logo helpers', function () {
       undefined
     )
     given('npm', {}).expect(
-      'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0MCA0MCI+PHBhdGggZD0iTTAgMGg0MHY0MEgwVjB6IiBmaWxsPSIjY2IwMDAwIi8+PHBhdGggZmlsbD0iI2ZmZiIgZD0iTTcgN2gyNnYyNmgtN1YxNGgtNnYxOUg3eiIvPjwvc3ZnPgo='
+      'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0MCA0MCI+PHBhdGggZD0iTTAgMGg0MHY0MEgwVjB6IiBmaWxsPSIjY2IwMDAwIi8+PHBhdGggZmlsbD0iI2ZmZiIgZD0iTTcgN2gyNnYyNmgtN1YxNGgtNnYxOUg3eiIvPjwvc3ZnPg=='
     )
   })
 })
diff --git a/lib/svg-helpers.js b/lib/svg-helpers.js
index 040df8a503..c688c34776 100644
--- a/lib/svg-helpers.js
+++ b/lib/svg-helpers.js
@@ -1,5 +1,7 @@
 function svg2base64(svg) {
-  return `data:image/svg+xml;base64,${Buffer.from(svg).toString('base64')}`
+  return `data:image/svg+xml;base64,${Buffer.from(svg.trim()).toString(
+    'base64'
+  )}`
 }
 
 export { svg2base64 }
-- 
GitLab