From 9c939fd06c0f79c37000f8aa711f0fd18a1bec7b Mon Sep 17 00:00:00 2001
From: viktorstrate <viktorstrate@gmail.com>
Date: Tue, 13 Apr 2021 14:16:40 +0200
Subject: [PATCH] Fix UI tests

---
 ui/babel.config.js                            |  4 +-
 ui/package-lock.json                          | 68 ++++++++++---------
 ui/package.json                               |  8 +--
 ui/src/Layout.test.js                         |  2 +-
 .../components/routes/AuthorizedRoute.test.js |  2 +-
 ui/tsconfig.json                              |  4 +-
 6 files changed, 45 insertions(+), 43 deletions(-)

diff --git a/ui/babel.config.js b/ui/babel.config.js
index 5cdd249..0f6c8a3 100644
--- a/ui/babel.config.js
+++ b/ui/babel.config.js
@@ -2,14 +2,12 @@ module.exports = function (api) {
   const isTest = api.env('test')
   const isProduction = api.env('NODE_ENV') == 'production'
 
-  let presets = ['@babel/preset-typescript', '@babel/preset-react']
+  let presets = ['@babel/preset-react', '@babel/preset-typescript']
   let plugins = []
 
   if (isTest) {
     presets.push('@babel/preset-env')
-
     plugins.push('@babel/plugin-transform-runtime')
-    plugins.push('@babel/plugin-transform-modules-commonjs')
   } else {
     plugins.push(['styled-components', { pure: true }])
     plugins.push('graphql-tag')
diff --git a/ui/package-lock.json b/ui/package-lock.json
index d15438c..c0733f6 100644
--- a/ui/package-lock.json
+++ b/ui/package-lock.json
@@ -11,9 +11,6 @@
       "dependencies": {
         "@apollo/client": "^3.3.14",
         "@babel/core": "^7.13.15",
-        "@babel/plugin-transform-modules-commonjs": "^7.13.8",
-        "@babel/plugin-transform-runtime": "^7.13.15",
-        "@babel/preset-env": "^7.13.15",
         "@babel/preset-react": "^7.13.13",
         "@babel/preset-typescript": "^7.13.0",
         "babel-eslint": "^10.1.0",
@@ -54,8 +51,11 @@
         "workbox-build": "^6.1.2"
       },
       "devDependencies": {
+        "@babel/plugin-transform-runtime": "^7.13.15",
+        "@babel/preset-env": "^7.13.15",
         "@testing-library/jest-dom": "^5.11.10",
         "@testing-library/react": "^11.2.6",
+        "@types/jest": "^26.0.22",
         "@types/react": "^17.0.3",
         "@types/react-dom": "^17.0.3",
         "@types/react-helmet": "^6.1.1",
@@ -163,20 +163,6 @@
         "@babel/highlight": "^7.12.13"
       }
     },
-    "node_modules/@babel/core/node_modules/json5": {
-      "version": "2.1.3",
-      "resolved": "https://registry.npmjs.org/json5/-/json5-2.1.3.tgz",
-      "integrity": "sha512-KXPvOm8K9IJKFM0bmdn8QXh7udDh1g/giieX0NLCaMnb4hEiVFqnop2ImTXCc5e0/oHz3LTqmHGtExn5hfMkOA==",
-      "dependencies": {
-        "minimist": "^1.2.5"
-      },
-      "bin": {
-        "json5": "lib/cli.js"
-      },
-      "engines": {
-        "node": ">=6"
-      }
-    },
     "node_modules/@babel/core/node_modules/semver": {
       "version": "6.3.0",
       "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
@@ -1133,6 +1119,7 @@
       "version": "7.13.15",
       "resolved": "https://registry.npmjs.org/@babel/plugin-transform-runtime/-/plugin-transform-runtime-7.13.15.tgz",
       "integrity": "sha512-d+ezl76gx6Jal08XngJUkXM4lFXK/5Ikl9Mh4HKDxSfGJXmZ9xG64XT2oivBzfxb/eQ62VfvoMkaCZUKJMVrBA==",
+      "dev": true,
       "dependencies": {
         "@babel/helper-module-imports": "^7.13.12",
         "@babel/helper-plugin-utils": "^7.13.0",
@@ -1149,6 +1136,7 @@
       "version": "6.3.0",
       "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
       "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==",
+      "dev": true,
       "bin": {
         "semver": "bin/semver.js"
       }
@@ -2793,9 +2781,9 @@
       }
     },
     "node_modules/@types/jest": {
-      "version": "26.0.15",
-      "resolved": "https://registry.npmjs.org/@types/jest/-/jest-26.0.15.tgz",
-      "integrity": "sha512-s2VMReFXRg9XXxV+CW9e5Nz8fH2K1aEhwgjUqPPbQd7g95T0laAcvLv032EhFHIa5GHsZ8W7iJEQVaJq6k3Gog==",
+      "version": "26.0.22",
+      "resolved": "https://registry.npmjs.org/@types/jest/-/jest-26.0.22.tgz",
+      "integrity": "sha512-eeWwWjlqxvBxc4oQdkueW5OF/gtfSceKk4OnOAGlUSwS/liBRtZppbJuz1YkgbrbfGOoeBHun9fOvXnjNwrSOw==",
       "dev": true,
       "dependencies": {
         "jest-diff": "^26.0.0",
@@ -9445,6 +9433,20 @@
       "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=",
       "dev": true
     },
+    "node_modules/json5": {
+      "version": "2.2.0",
+      "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.0.tgz",
+      "integrity": "sha512-f+8cldu7X/y7RAJurMEJmdoKXGB/X550w2Nr3tTbezL6RwEE/iMcm+tZnXeoZtKuOq6ft8+CqzEkrIgx1fPoQA==",
+      "dependencies": {
+        "minimist": "^1.2.5"
+      },
+      "bin": {
+        "json5": "lib/cli.js"
+      },
+      "engines": {
+        "node": ">=6"
+      }
+    },
     "node_modules/jsonfile": {
       "version": "6.1.0",
       "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz",
@@ -14245,14 +14247,6 @@
             "@babel/highlight": "^7.12.13"
           }
         },
-        "json5": {
-          "version": "2.1.3",
-          "resolved": "https://registry.npmjs.org/json5/-/json5-2.1.3.tgz",
-          "integrity": "sha512-KXPvOm8K9IJKFM0bmdn8QXh7udDh1g/giieX0NLCaMnb4hEiVFqnop2ImTXCc5e0/oHz3LTqmHGtExn5hfMkOA==",
-          "requires": {
-            "minimist": "^1.2.5"
-          }
-        },
         "semver": {
           "version": "6.3.0",
           "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
@@ -15041,6 +15035,7 @@
       "version": "7.13.15",
       "resolved": "https://registry.npmjs.org/@babel/plugin-transform-runtime/-/plugin-transform-runtime-7.13.15.tgz",
       "integrity": "sha512-d+ezl76gx6Jal08XngJUkXM4lFXK/5Ikl9Mh4HKDxSfGJXmZ9xG64XT2oivBzfxb/eQ62VfvoMkaCZUKJMVrBA==",
+      "dev": true,
       "requires": {
         "@babel/helper-module-imports": "^7.13.12",
         "@babel/helper-plugin-utils": "^7.13.0",
@@ -15053,7 +15048,8 @@
         "semver": {
           "version": "6.3.0",
           "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
-          "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw=="
+          "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==",
+          "dev": true
         }
       }
     },
@@ -16419,9 +16415,9 @@
       }
     },
     "@types/jest": {
-      "version": "26.0.15",
-      "resolved": "https://registry.npmjs.org/@types/jest/-/jest-26.0.15.tgz",
-      "integrity": "sha512-s2VMReFXRg9XXxV+CW9e5Nz8fH2K1aEhwgjUqPPbQd7g95T0laAcvLv032EhFHIa5GHsZ8W7iJEQVaJq6k3Gog==",
+      "version": "26.0.22",
+      "resolved": "https://registry.npmjs.org/@types/jest/-/jest-26.0.22.tgz",
+      "integrity": "sha512-eeWwWjlqxvBxc4oQdkueW5OF/gtfSceKk4OnOAGlUSwS/liBRtZppbJuz1YkgbrbfGOoeBHun9fOvXnjNwrSOw==",
       "dev": true,
       "requires": {
         "jest-diff": "^26.0.0",
@@ -21651,6 +21647,14 @@
       "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=",
       "dev": true
     },
+    "json5": {
+      "version": "2.2.0",
+      "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.0.tgz",
+      "integrity": "sha512-f+8cldu7X/y7RAJurMEJmdoKXGB/X550w2Nr3tTbezL6RwEE/iMcm+tZnXeoZtKuOq6ft8+CqzEkrIgx1fPoQA==",
+      "requires": {
+        "minimist": "^1.2.5"
+      }
+    },
     "jsonfile": {
       "version": "6.1.0",
       "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz",
diff --git a/ui/package.json b/ui/package.json
index f136346..046ec5b 100644
--- a/ui/package.json
+++ b/ui/package.json
@@ -11,9 +11,6 @@
   "dependencies": {
     "@apollo/client": "^3.3.14",
     "@babel/core": "^7.13.15",
-    "@babel/plugin-transform-modules-commonjs": "^7.13.8",
-    "@babel/plugin-transform-runtime": "^7.13.15",
-    "@babel/preset-env": "^7.13.15",
     "@babel/preset-react": "^7.13.13",
     "@babel/preset-typescript": "^7.13.0",
     "babel-eslint": "^10.1.0",
@@ -65,8 +62,11 @@
     "prepare": "(cd .. && npx husky install)"
   },
   "devDependencies": {
+    "@babel/plugin-transform-runtime": "^7.13.15",
+    "@babel/preset-env": "^7.13.15",
     "@testing-library/jest-dom": "^5.11.10",
     "@testing-library/react": "^11.2.6",
+    "@types/jest": "^26.0.22",
     "@types/react": "^17.0.3",
     "@types/react-dom": "^17.0.3",
     "@types/react-helmet": "^6.1.1",
@@ -97,7 +97,7 @@
       "^.+\\.css$"
     ],
     "transform": {
-      "^.+\\.js$": "babel-jest",
+      "^.+\\.(js|ts|tsx)$": "babel-jest",
       "^.+\\.svg$": "<rootDir>/testing/transform-svg.js"
     }
   },
diff --git a/ui/src/Layout.test.js b/ui/src/Layout.test.js
index b40a3aa..916fcd6 100644
--- a/ui/src/Layout.test.js
+++ b/ui/src/Layout.test.js
@@ -11,7 +11,7 @@ import * as authentication from './helpers/authentication'
 
 require('./localization').default()
 
-jest.mock('./helpers/authentication.js')
+jest.mock('./helpers/authentication.ts')
 
 test('Layout component', async () => {
   render(
diff --git a/ui/src/components/routes/AuthorizedRoute.test.js b/ui/src/components/routes/AuthorizedRoute.test.js
index a410a80..50fbf7c 100644
--- a/ui/src/components/routes/AuthorizedRoute.test.js
+++ b/ui/src/components/routes/AuthorizedRoute.test.js
@@ -7,7 +7,7 @@ import { MemoryRouter, Route } from 'react-router-dom'
 
 import * as authentication from '../../helpers/authentication'
 
-jest.mock('../../helpers/authentication.js')
+jest.mock('../../helpers/authentication.ts')
 
 describe('AuthorizedRoute component', () => {
   const AuthorizedComponent = () => <div>authorized content</div>
diff --git a/ui/tsconfig.json b/ui/tsconfig.json
index 78afcc4..547c11a 100644
--- a/ui/tsconfig.json
+++ b/ui/tsconfig.json
@@ -3,7 +3,7 @@
     /* Visit https://aka.ms/tsconfig.json to read more about this file */
 
     /* Basic Options */
-    // "incremental": true,                         /* Enable incremental compilation */
+    "incremental": true /* Enable incremental compilation */,
     "target": "es5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
     "module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
     "lib": [
@@ -23,7 +23,7 @@
     // "composite": true,                           /* Enable project compilation */
     // "tsBuildInfoFile": "./",                     /* Specify file to store incremental compilation information */
     // "removeComments": true,                      /* Do not emit comments to output. */
-    "noEmit": true /* Do not emit outputs. */,
+    // "noEmit": true /* Do not emit outputs. */,
     // "importHelpers": true,                       /* Import emit helpers from 'tslib'. */
     // "downlevelIteration": true,                  /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
     // "isolatedModules": true,                     /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
