From 4f3afa33a270a621bc4f666c1897c88eac52bfde Mon Sep 17 00:00:00 2001
From: Juan Picado <juanpicado19@gmail.com>
Date: Fri, 26 Mar 2021 18:04:19 +0100
Subject: [PATCH] build: fix node version issue on ci (#2140)

* build: fix node version issue

* chore: fix test on node 15
---
 .eslintrc                         |   2 +-
 .github/workflows/ci-e2e-ui.yml   |   2 +-
 .github/workflows/ci-e2e.yml      |   2 +-
 .github/workflows/ci.yml          |   2 +-
 .github/workflows/release.yml     |   2 +-
 test/unit/modules/cli/cli.spec.ts | 157 ++++++++++++------------------
 6 files changed, 67 insertions(+), 100 deletions(-)

diff --git a/.eslintrc b/.eslintrc
index 8c1a16585..afbb0e594 100644
--- a/.eslintrc
+++ b/.eslintrc
@@ -59,7 +59,7 @@
     "camelcase": "off",
     "guard-for-in": "error",
     "new-cap": "error",
-    "max-len": ["error", 160],
+    "max-len": ["error", 180],
     "no-console": ["error", { "allow": ["warn"] }],
     "no-constant-condition": "error",
     "no-debugger": "error",
diff --git a/.github/workflows/ci-e2e-ui.yml b/.github/workflows/ci-e2e-ui.yml
index 5e618ae8d..f2fcc8294 100644
--- a/.github/workflows/ci-e2e-ui.yml
+++ b/.github/workflows/ci-e2e-ui.yml
@@ -18,7 +18,7 @@ jobs:
       - name: Use Node ${{ matrix.node_version }}
         uses: actions/setup-node@v2.1.5
         with:
-          node_version: ${{ matrix.node_version }}
+          node-version: ${{ matrix.node_version }}
       - name: Install
         run: yarn install --immutable
       - name: Build
diff --git a/.github/workflows/ci-e2e.yml b/.github/workflows/ci-e2e.yml
index d83e1baae..d4289485c 100644
--- a/.github/workflows/ci-e2e.yml
+++ b/.github/workflows/ci-e2e.yml
@@ -18,7 +18,7 @@ jobs:
       - name: Use Node ${{ matrix.node_version }}
         uses: actions/setup-node@v2.1.5
         with:
-          node_version: ${{ matrix.node_version }}
+          node-version: ${{ matrix.node_version }}
       - name: Install
         run: yarn install --immutable
       - name: Build
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index c95dd4780..ecb54cb4e 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -18,7 +18,7 @@ jobs:
     - name: Use Node ${{ matrix.node_version }}
       uses: actions/setup-node@v2.1.5
       with:
-        node_version: ${{ matrix.node_version }}
+        node-version: ${{ matrix.node_version }}
     - name: Install
       run: yarn install --immutable
     - name: Build
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 71f87764c..f520fe1c6 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -14,7 +14,7 @@ jobs:
     - name: Use Node (latest)
       uses: actions/setup-node@v2.1.5
       with:
-        node_version: 14
+        node-version: 14
     - name: Install
       run: yarn install
     - name: Build
diff --git a/test/unit/modules/cli/cli.spec.ts b/test/unit/modules/cli/cli.spec.ts
index a3a1603fe..eaadc5986 100644
--- a/test/unit/modules/cli/cli.spec.ts
+++ b/test/unit/modules/cli/cli.spec.ts
@@ -19,8 +19,8 @@ jest.mock('../../../../src/lib/logger', () => ({
     trace: jest.fn(),
     warn: jest.fn(),
     error: jest.fn(),
-    fatal: jest.fn()
-  }
+    fatal: jest.fn(),
+  },
 }));
 
 describe('startServer via API', () => {
@@ -35,25 +35,18 @@ describe('startServer via API', () => {
       const version = '1.0.0';
       const port = '6000';
 
-      await startServer(
-        config(),
-        port,
-        store,
-        version,
-        serverName,
-        (webServer, addrs, pkgName, pkgVersion) => {
-          expect(webServer).toBeDefined();
-          expect(addrs).toBeDefined();
-          expect(addrs.proto).toBe(DEFAULT_PROTOCOL);
-          expect(addrs.host).toBe(DEFAULT_DOMAIN);
-          expect(addrs.port).toBe(port);
-          expect(pkgName).toBeDefined();
-          expect(pkgVersion).toBeDefined();
-          expect(pkgVersion).toBe(version);
-          expect(pkgName).toBe(serverName);
-          done();
-        }
-      );
+      await startServer(config(), port, store, version, serverName, (webServer, addrs, pkgName, pkgVersion) => {
+        expect(webServer).toBeDefined();
+        expect(addrs).toBeDefined();
+        expect(addrs.proto).toBe(DEFAULT_PROTOCOL);
+        expect(addrs.host).toBe(DEFAULT_DOMAIN);
+        expect(addrs.port).toBe(port);
+        expect(pkgName).toBeDefined();
+        expect(pkgVersion).toBeDefined();
+        expect(pkgVersion).toBe(version);
+        expect(pkgName).toBe(serverName);
+        done();
+      });
     });
 
     test('should set keepAliveTimeout to 0 seconds', async (done) => {
@@ -62,27 +55,20 @@ describe('startServer via API', () => {
       const version = '1.0.0';
       const port = '6100';
 
-      await startServer(
-        config(parseConfigurationFile('server/keepalivetimeout-0')),
-        port,
-        store,
-        version,
-        serverName,
-        (webServer, addrs, pkgName, pkgVersion) => {
-          expect(webServer).toBeDefined();
-          expect(webServer.keepAliveTimeout).toBeDefined();
-          expect(webServer.keepAliveTimeout).toBe(0);
-          expect(addrs).toBeDefined();
-          expect(addrs.proto).toBe(DEFAULT_PROTOCOL);
-          expect(addrs.host).toBe(DEFAULT_DOMAIN);
-          expect(addrs.port).toBe(port);
-          expect(pkgName).toBeDefined();
-          expect(pkgVersion).toBeDefined();
-          expect(pkgVersion).toBe(version);
-          expect(pkgName).toBe(serverName);
-          done();
-        }
-      );
+      await startServer(config(parseConfigurationFile('server/keepalivetimeout-0')), port, store, version, serverName, (webServer, addrs, pkgName, pkgVersion) => {
+        expect(webServer).toBeDefined();
+        expect(webServer.keepAliveTimeout).toBeDefined();
+        expect(webServer.keepAliveTimeout).toBe(0);
+        expect(addrs).toBeDefined();
+        expect(addrs.proto).toBe(DEFAULT_PROTOCOL);
+        expect(addrs.host).toBe(DEFAULT_DOMAIN);
+        expect(addrs.port).toBe(port);
+        expect(pkgName).toBeDefined();
+        expect(pkgVersion).toBeDefined();
+        expect(pkgVersion).toBe(version);
+        expect(pkgName).toBe(serverName);
+        done();
+      });
     });
 
     test('should set keepAliveTimeout to 60 seconds', async (done) => {
@@ -91,27 +77,20 @@ describe('startServer via API', () => {
       const version = '1.0.0';
       const port = '6200';
 
-      await startServer(
-        config(parseConfigurationFile('server/keepalivetimeout-60')),
-        port,
-        store,
-        version,
-        serverName,
-        (webServer, addrs, pkgName, pkgVersion) => {
-          expect(webServer).toBeDefined();
-          expect(webServer.keepAliveTimeout).toBeDefined();
-          expect(webServer.keepAliveTimeout).toBe(60000);
-          expect(addrs).toBeDefined();
-          expect(addrs.proto).toBe(DEFAULT_PROTOCOL);
-          expect(addrs.host).toBe(DEFAULT_DOMAIN);
-          expect(addrs.port).toBe(port);
-          expect(pkgName).toBeDefined();
-          expect(pkgVersion).toBeDefined();
-          expect(pkgVersion).toBe(version);
-          expect(pkgName).toBe(serverName);
-          done();
-        }
-      );
+      await startServer(config(parseConfigurationFile('server/keepalivetimeout-60')), port, store, version, serverName, (webServer, addrs, pkgName, pkgVersion) => {
+        expect(webServer).toBeDefined();
+        expect(webServer.keepAliveTimeout).toBeDefined();
+        expect(webServer.keepAliveTimeout).toBe(60000);
+        expect(addrs).toBeDefined();
+        expect(addrs.proto).toBe(DEFAULT_PROTOCOL);
+        expect(addrs.host).toBe(DEFAULT_DOMAIN);
+        expect(addrs.port).toBe(port);
+        expect(pkgName).toBeDefined();
+        expect(pkgVersion).toBeDefined();
+        expect(pkgVersion).toBe(version);
+        expect(pkgName).toBe(serverName);
+        done();
+      });
     });
 
     test('should set keepAliveTimeout to 5 seconds per default', async (done) => {
@@ -120,50 +99,38 @@ describe('startServer via API', () => {
       const version = '1.0.0';
       const port = '6300';
 
-      await startServer(
-        config(parseConfigurationFile('server/keepalivetimeout-undefined')),
-        port,
-        store,
-        version,
-        serverName,
-        (webServer, addrs, pkgName, pkgVersion) => {
-          expect(webServer).toBeDefined();
-          expect(webServer.keepAliveTimeout).toBeDefined();
-          expect(webServer.keepAliveTimeout).toBe(5000);
-          expect(addrs).toBeDefined();
-          expect(addrs.proto).toBe(DEFAULT_PROTOCOL);
-          expect(addrs.host).toBe(DEFAULT_DOMAIN);
-          expect(addrs.port).toBe(port);
-          expect(pkgName).toBeDefined();
-          expect(pkgVersion).toBeDefined();
-          expect(pkgVersion).toBe(version);
-          expect(pkgName).toBe(serverName);
-          done();
-        }
-      );
+      await startServer(config(parseConfigurationFile('server/keepalivetimeout-undefined')), port, store, version, serverName, (webServer, addrs, pkgName, pkgVersion) => {
+        expect(webServer).toBeDefined();
+        expect(webServer.keepAliveTimeout).toBeDefined();
+        expect(webServer.keepAliveTimeout).toBe(5000);
+        expect(addrs).toBeDefined();
+        expect(addrs.proto).toBe(DEFAULT_PROTOCOL);
+        expect(addrs.host).toBe(DEFAULT_DOMAIN);
+        expect(addrs.port).toBe(port);
+        expect(pkgName).toBeDefined();
+        expect(pkgVersion).toBeDefined();
+        expect(pkgVersion).toBe(version);
+        expect(pkgName).toBe(serverName);
+        done();
+      });
     });
 
-    test('should provide all HTTPS server fails', async (done) => {
+    test('should provide all HTTPS server fails', async () => {
       const store = path.join(__dirname, 'partials/store');
       const serverName = 'verdaccio-test';
       const version = '1.0.0';
       const address = 'https://www.domain.com:443';
-      const realProcess = process;
+      // @ts-ignore
+      jest.spyOn(process, 'exit').mockImplementation(() => {});
 
       const conf = config();
       conf.https = {};
       // save process to catch exist
-      const exitMock = jest.fn();
-      // @ts-ignore
-      global.process = { ...realProcess, exit: exitMock };
-      await startServer(conf, address, store, version, serverName, () => {
+
+      startServer(conf, address, store, version, serverName, () => {
         expect(logger.fatal).toHaveBeenCalled();
         expect(logger.fatal).toHaveBeenCalledTimes(2);
-        done();
       });
-      expect(exitMock).toHaveBeenCalledWith(2);
-      // restore process
-      global.process = realProcess;
     });
 
     test('should start a https server with key and cert', async (done) => {
@@ -180,7 +147,7 @@ describe('startServer via API', () => {
       const conf = config();
       conf.https = {
         key: keyPath,
-        cert: certPath
+        cert: certPath,
       };
 
       await startServer(conf, address, store, version, serverName, (webServer, addrs) => {