Skip login/logout tests if KORAP_LOGIN empty

Change-Id: I67e1e30f2b96724b68c99521d72187045ddb2329
diff --git a/Readme.md b/Readme.md
index 7b750e1..471c66c 100644
--- a/Readme.md
+++ b/Readme.md
@@ -21,4 +21,6 @@
  npm test
 ```
 
+### Comments on Environment Variables
 
+Use `KORAP_LOGIN="" npm test` to skip login and logout tests, e.g. to run tests against Kustvakt-lite.
diff --git a/test/korap-ui.js b/test/korap-ui.js
index 467bb04..bb5e293 100644
--- a/test/korap-ui.js
+++ b/test/korap-ui.js
@@ -1,14 +1,17 @@
-const { doesNotMatch } = require('assert');
 const { beforeEach } = require('mocha');
 const puppeteer = require('puppeteer')
 var chai = require('chai');
+const { expect, assert } = require('chai');
 var should = chai.should();
-var assert = chai.assert;
 const KORAP_URL = process.env.KORAP_URL || "http://localhost:64543";
-const KORAP_LOGIN = process.env.KORAP_LOGIN || "user2";
+const KORAP_LOGIN = (process.env.KORAP_LOGIN || process.env.KORAP_LOGIN == "" ? process.env.KORAP_LOGIN : "user2")
 const KORAP_PWD = process.env.KORAP_PWD || "password2";
 const KORAP_QUERIES = 'geht, [orth=geht & cmc/pos=VVFIN]'
-const korap_rc = require('../lib/korap_rc.js').new(KORAP_URL);
+const korap_rc = require('../lib/korap_rc.js').new(KORAP_URL)
+
+function ifConditionIt(title, condition, test) {
+    return condition ? it(title, test) : it.skip(title, test)
+}
 
 describe('Running KorAP UI end-to-end tests on ' + KORAP_URL, () => {
     const screenshot = 'screenshot.png'
@@ -22,13 +25,23 @@
         await browser.close()
     })
 
-    it('Login into KorAP with incorrect credentials fails',
+    it('KorAP UI is up and running',
+        (async () => {
+            await await page.goto(KORAP_URL);
+            const query_field = await page.$("#q-field")
+            assert.isNotNull(query_field, "#q-field not found. Kalamar not running?");
+        })).timeout(10000)
+
+
+    ifConditionIt('Login into KorAP with incorrect credentials fails',
+        KORAP_LOGIN != "",
         (async () => {
             const login_result = await korap_rc.login(page, KORAP_LOGIN, KORAP_PWD + "*")
             login_result.should.be.false
         })).timeout(10000)
 
-    it('Login into KorAP with correct credentials succeeds',
+    ifConditionIt('Login into KorAP with correct credentials succeeds',
+        KORAP_LOGIN != "",
         (async () => {
             const login_result = await korap_rc.login(page, KORAP_LOGIN, KORAP_PWD)
             login_result.should.be.true
@@ -39,7 +52,6 @@
             await korap_rc.assure_glimpse_off(page)
         })).timeout(10000)
 
-    const expected_hits = 724
     describe('Running searches that should have hits', () => {
         KORAP_QUERIES.split(/[;,] */).forEach((query, i) => {
             it('Search for "' + query + '" has hits',
@@ -50,7 +62,9 @@
                 })).timeout(20000)
         })
     })
-    it('Logout works',
+
+    ifConditionIt('Logout works',
+        KORAP_LOGIN != "",
         (async () => {
             const logout_result = await korap_rc.logout(page)
             logout_result.should.be.true