test: setup to allow unit tests with stubbing
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 24 Mar 2023 16:02:57 +0000 (17:02 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 24 Mar 2023 16:02:57 +0000 (17:02 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
build-requirements.mjs
package.json
pnpm-lock.yaml
src/charging-station/Bootstrap.ts
test/charging-station/ChargingStationTest.ts [new file with mode: 0644]
tsconfig.json

index d3e7fe873f7ab60462052fa12d60d291424fdd7b..167f36569182ee258e5699c319d2acdddef6fcc9 100644 (file)
@@ -2,12 +2,11 @@ import chalk from 'chalk';
 import semVer from 'semver';
 import packageJson from './package.json' assert { type: 'json' };
 
-const enginesNodeVersion = packageJson.engines.node;
-
 /**
  * Check if the current node version match the required engines version.
  */
 export function checkNodeVersion() {
+  const enginesNodeVersion = packageJson.engines.node;
   if (semVer.satisfies(process.version, enginesNodeVersion) === false) {
     console.error(
       chalk.red(
index 8457499a2e1b7700b1e12027aa1a714420ec6a9d..899dd131b90eb6f5438b96124cc7280817a26817 100644 (file)
     "@types/mochawesome": "^6.2.1",
     "@types/node": "^18.15.7",
     "@types/proper-lockfile": "^4.1.2",
+    "@types/sinon": "^10.0.13",
     "@types/tar": "^6.1.4",
     "@types/ws": "^8.5.4",
     "@typescript-eslint/eslint-plugin": "^5.56.0",
     "rollup-plugin-copy": "^3.4.0",
     "rollup-plugin-delete": "^2.0.0",
     "semver": "^7.3.8",
+    "sinon": "^15.0.2",
     "ts-node": "^10.9.1",
     "typescript": "^5.0.2"
   }
index 523ec42b5652e8c82fe434950f3c3271f7fa0810..8421f85a7c8fb893f9f3267038ba5be0f380fc9b 100644 (file)
@@ -16,6 +16,7 @@ specifiers:
   '@types/mochawesome': ^6.2.1
   '@types/node': ^18.15.7
   '@types/proper-lockfile': ^4.1.2
+  '@types/sinon': ^10.0.13
   '@types/tar': ^6.1.4
   '@types/ws': ^8.5.4
   '@typescript-eslint/eslint-plugin': ^5.56.0
@@ -60,6 +61,7 @@ specifiers:
   rollup-plugin-copy: ^3.4.0
   rollup-plugin-delete: ^2.0.0
   semver: ^7.3.8
+  sinon: ^15.0.2
   source-map-support: ^0.5.21
   tar: ^6.1.13
   ts-node: ^10.9.1
@@ -111,6 +113,7 @@ devDependencies:
   '@types/mochawesome': 6.2.1
   '@types/node': 18.15.7
   '@types/proper-lockfile': 4.1.2
+  '@types/sinon': 10.0.13
   '@types/tar': 6.1.4
   '@types/ws': 8.5.4
   '@typescript-eslint/eslint-plugin': 5.56.0_2hcjazgfnbtq42tcc73br2vup4
@@ -141,6 +144,7 @@ devDependencies:
   rollup-plugin-copy: 3.4.0
   rollup-plugin-delete: 2.0.0
   semver: 7.3.8
+  sinon: 15.0.2
   ts-node: 10.9.1_gkjsv6qbk4dkl5zwoikfngqpvy
   typescript: 5.0.2
 
@@ -1263,6 +1267,36 @@ packages:
     engines: {node: '>=14.16'}
     dev: true
 
+  /@sinonjs/commons/2.0.0:
+    resolution: {integrity: sha512-uLa0j859mMrg2slwQYdO/AkrOfmH+X6LTVmNTS9CqexuE2IvVORIkSpJLqePAbEnKJ77aMmCwr1NUZ57120Xcg==}
+    dependencies:
+      type-detect: 4.0.8
+    dev: true
+
+  /@sinonjs/commons/3.0.0:
+    resolution: {integrity: sha512-jXBtWAF4vmdNmZgD5FoKsVLv3rPgDnLgPbU84LIJ3otV44vJlDRokVng5v8NFJdCf/da9legHcKaRuZs4L7faA==}
+    dependencies:
+      type-detect: 4.0.8
+    dev: true
+
+  /@sinonjs/fake-timers/10.0.2:
+    resolution: {integrity: sha512-SwUDyjWnah1AaNl7kxsa7cfLhlTYoiyhDAIgyh+El30YvXs/o7OLXpYH88Zdhyx9JExKrmHDJ+10bwIcY80Jmw==}
+    dependencies:
+      '@sinonjs/commons': 2.0.0
+    dev: true
+
+  /@sinonjs/samsam/7.0.1:
+    resolution: {integrity: sha512-zsAk2Jkiq89mhZovB2LLOdTCxJF4hqqTToGP0ASWlhp4I1hqOjcfmZGafXntCN7MDC6yySH0mFHrYtHceOeLmw==}
+    dependencies:
+      '@sinonjs/commons': 2.0.0
+      lodash.get: 4.4.2
+      type-detect: 4.0.8
+    dev: true
+
+  /@sinonjs/text-encoding/0.7.2:
+    resolution: {integrity: sha512-sXXKG+uL9IrKqViTtao2Ws6dy0znu9sOaP1di/jKGW1M6VssO8vlpXCQcpZ+jisQ1tTFAC5Jo/EOzFbggBagFQ==}
+    dev: true
+
   /@szmarczak/http-timer/1.1.2:
     resolution: {integrity: sha512-XIB2XbzHTN6ieIjfIMV9hlVcfPU26s2vafYWQcZHWXHOxiaRZYEDKEwdl129Zyg50+foYV2jCgtrqSA6qNuNSA==}
     engines: {node: '>=6'}
@@ -1447,6 +1481,16 @@ packages:
     resolution: {integrity: sha512-21cFJr9z3g5dW8B0CVI9g2O9beqaThGQ6ZFBqHfwhzLDKUxaqTIy3vnfah/UPkfOiF2pLq+tGz+W8RyCskuslw==}
     dev: true
 
+  /@types/sinon/10.0.13:
+    resolution: {integrity: sha512-UVjDqJblVNQYvVNUsj0PuYYw0ELRmgt1Nt5Vk0pT5f16ROGfcKJY8o1HVuMOJOpD727RrGB9EGvoaTQE5tgxZQ==}
+    dependencies:
+      '@types/sinonjs__fake-timers': 8.1.2
+    dev: true
+
+  /@types/sinonjs__fake-timers/8.1.2:
+    resolution: {integrity: sha512-9GcLXF0/v3t80caGs5p2rRfkB+a8VBGLJZVih6CNFkx8IZ994wiKKLSRs9nuFwk1HevWs/1mnUmkApGrSGsShA==}
+    dev: true
+
   /@types/stack-utils/2.0.1:
     resolution: {integrity: sha512-Hl219/BT5fLAaz6NDkSuhzasy49dwQS/DSdu4MdggFB8zcXv7vflBI3xp7FEmkmdDkBUI2bPUNeMttp2knYdxw==}
     dev: true
@@ -5990,6 +6034,10 @@ packages:
     resolution: {integrity: sha512-1IynUYEc/HAwxhi3WDpIpxJbZpMCvvrrmZVqvj9EhpvbH8lls7HhdhiByjL7DkAaWlLIzpC0Xc/VPvy/UxLNjA==}
     dev: false
 
+  /just-extend/4.2.1:
+    resolution: {integrity: sha512-g3UB796vUFIY90VIv/WX3L2c8CS2MdWUww3CNrYmqza1Fg0DURc2K/O4YrnklBdQarSJ/y8JnJYDGc+1iumQjg==}
+    dev: true
+
   /just-merge/3.2.0:
     resolution: {integrity: sha512-cNh5FWt44hx4SpQS1xZU8Tzr/fQA69pqCdjbwxmaYYIOuRfA8EIg+dn1bGmIW03ZUtR2vkMOCjWKc+jIbpauSw==}
     dev: false
@@ -7085,6 +7133,16 @@ packages:
     resolution: {integrity: sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==}
     dev: true
 
+  /nise/5.1.4:
+    resolution: {integrity: sha512-8+Ib8rRJ4L0o3kfmyVCL7gzrohyDe0cMFTBa2d364yIrEGMEoetznKJx899YxjybU6bL9SQkYPSBBs1gyYs8Xg==}
+    dependencies:
+      '@sinonjs/commons': 2.0.0
+      '@sinonjs/fake-timers': 10.0.2
+      '@sinonjs/text-encoding': 0.7.2
+      just-extend: 4.2.1
+      path-to-regexp: 1.8.0
+    dev: true
+
   /no-case/2.3.2:
     resolution: {integrity: sha512-rmTZ9kz+f3rCvK2TD1Ue/oZlns7OGoIWP4fc3llxxRXlOkHKoWPPWJOfFYpITabSow43QJbRIoHQXtt10VldyQ==}
     dependencies:
@@ -7656,6 +7714,12 @@ packages:
       minipass: 4.2.5
     dev: true
 
+  /path-to-regexp/1.8.0:
+    resolution: {integrity: sha512-n43JRhlUKUAlibEJhPeir1ncUID16QnEjNpwzNdO3Lm4ywrBpBZ5oLD0I6br9evr1Y9JTqwRtAh7JLoOzAQdVA==}
+    dependencies:
+      isarray: 0.0.1
+    dev: true
+
   /path-type/4.0.0:
     resolution: {integrity: sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==}
     engines: {node: '>=8'}
@@ -8647,6 +8711,17 @@ packages:
       string-width: 1.0.2
     dev: true
 
+  /sinon/15.0.2:
+    resolution: {integrity: sha512-PCVP63XZkg0/LOqQH5rEU4LILuvTFMb5tNxTHfs6VUMNnZz2XrnGSTZbAGITjzwQWbl/Bl/8hi4G3zZWjyBwHg==}
+    dependencies:
+      '@sinonjs/commons': 3.0.0
+      '@sinonjs/fake-timers': 10.0.2
+      '@sinonjs/samsam': 7.0.1
+      diff: 5.1.0
+      nise: 5.1.4
+      supports-color: 7.2.0
+    dev: true
+
   /sinusoidal-decimal/1.0.0:
     resolution: {integrity: sha512-KPUi1ZqLocV64n0AuV+g4VDjAM+tEEY66nUd+rYaVBHIfeheGGUvIxe9bf7Mpc1PonDTVW2uRr9nigQa9odvuA==}
     dev: true
@@ -9490,6 +9565,11 @@ packages:
     resolution: {integrity: sha512-mDZRBQS2yZkwRQKfjJvQ8UIYJeBNNWCq+HBNstl9N5s9jZ4dkVYXEGkVPsSCEh5Ld4JM1kmrZTzjnrqSAIQ7dw==}
     dev: true
 
+  /type-detect/4.0.8:
+    resolution: {integrity: sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==}
+    engines: {node: '>=4'}
+    dev: true
+
   /type-fest/0.18.1:
     resolution: {integrity: sha512-OIAYXk8+ISY+qTOwkHtKqzAuxchoMiD9Udx+FSGQDuiRR+PJKJHc2NJAXlbhkGwTt/4/nKZxELY1w3ReWOL8mw==}
     engines: {node: '>=10'}
index 6be5d275682b3e5bdf5ead54916334d94825ebee..00a7df7dd45e770b720a63aa848f3f19b8b1f51a 100644 (file)
@@ -7,7 +7,7 @@ import { type Worker, isMainThread } from 'node:worker_threads';
 import chalk from 'chalk';
 
 import { type AbstractUIServer, ChargingStationUtils, UIServerFactory } from './internal';
-import { version } from '../../package.json';
+import packageJson from '../../package.json' assert { type: 'json' };
 import { BaseError } from '../exception';
 import { type Storage, StorageFactory } from '../performance';
 import {
@@ -37,7 +37,7 @@ export class Bootstrap {
   private readonly uiServer!: AbstractUIServer | null;
   private readonly storage!: Storage;
   private numberOfStartedChargingStations!: number;
-  private readonly version: string = version;
+  private readonly version: string = packageJson.version;
   private initializedCounters: boolean;
   private started: boolean;
   private readonly workerScript: string;
diff --git a/test/charging-station/ChargingStationTest.ts b/test/charging-station/ChargingStationTest.ts
new file mode 100644 (file)
index 0000000..e69de29
index f30d942d87bbe1c3876ded107e7906c0a49d1ecb..b8078fc366a8571cd54c3f9adaaf135dc1a3d922 100644 (file)
@@ -5,7 +5,7 @@
     /* Basic Options */
     // "incremental": true,                   /* Enable incremental compilation */
     "target": "es2022",                       /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
-    "module": "es2022",                       /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
+    "module": "esnext",                       /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
     "lib": ["es2022"],                        /* Specify library files to be included in the compilation. */
     // "allowJs": true,                       /* Allow javascript files to be compiled. */
     // "checkJs": true,                       /* Report errors in .js files. */