Pārlūkot izejas kodu

generateImages: check that OSMD server is running, log error and exit script otherwise.

sschmid 5 gadi atpakaļ
vecāks
revīzija
9451e96c99
1 mainītis faili ar 11 papildinājumiem un 1 dzēšanām
  1. 11 1
      test/Util/generateDiffImagesPuppeteerLocalhost.js

+ 11 - 1
test/Util/generateDiffImagesPuppeteerLocalhost.js

@@ -14,6 +14,8 @@
 //     });
 // }
 
+const osmdPort = 8000 // OSMD webpack server port. OSMD has to be running (npm start) when this script runs.
+
 // main function
 async function init () {
     console.log('init')
@@ -41,7 +43,15 @@ async function init () {
     const sampleFileName = sampleKeys[0] // TODO for loop over samples / take filenames from script arguments
     const sampleParameter = `&url=${sampleFileName}&endUrl`
     console.log('puppeteer: going to url')
-    await page.goto('http://localhost:8000/?showHeader=0&debugControls=0&backendType=canvas&pageBackgroundColor=FFFFFF' + sampleParameter, { waitUntil: 'networkidle2' })
+    try {
+        await page.goto(`http://localhost:${osmdPort}/?showHeader=0&debugControls=0&backendType=canvas&pageBackgroundColor=FFFFFF${sampleParameter}` +
+            sampleParameter, { waitUntil: 'networkidle2' })
+    } catch (error) {
+        console.log(error)
+        console.log('[OSMD.generateImages] Error generating images: could not reach local OSMD server.' +
+            'Make sure to start OSMD (npm start) local webpack server before running this script.')
+        process.exit(-1) // exit script with error. otherwise process will continue running
+    }
     console.log('goto done')
 
     // fix navigation error