From a1587040492e4f24895e5177a1676145026653df Mon Sep 17 00:00:00 2001
From: Sergei Zharinov <zharinov@users.noreply.github.com>
Date: Thu, 23 Dec 2021 14:55:11 +0300
Subject: [PATCH] test(manager/npm): Refactor snapshot tests (#13269)

---
 lib/manager/npm/extract/index.spec.ts | 298 +++++++++++++++++++++++---
 1 file changed, 266 insertions(+), 32 deletions(-)

diff --git a/lib/manager/npm/extract/index.spec.ts b/lib/manager/npm/extract/index.spec.ts
index c9c74ae51d..bab3066868 100644
--- a/lib/manager/npm/extract/index.spec.ts
+++ b/lib/manager/npm/extract/index.spec.ts
@@ -38,8 +38,9 @@ describe('manager/npm/extract/index', () => {
         'package.json',
         defaultConfig
       );
-      // FIXME: explicit assert condition
-      expect(res).toMatchSnapshot();
+      expect(res).toMatchSnapshot({
+        deps: [{ skipReason: 'invalid-name' }],
+      });
     });
     it('ignores vendorised package.json', async () => {
       const res = await npmExtract.extractPackageFile(
@@ -80,8 +81,25 @@ describe('manager/npm/extract/index', () => {
         'package.json',
         defaultConfig
       );
-      // FIXME: explicit assert condition
-      expect(res).toMatchSnapshot();
+      expect(res).toMatchSnapshot({
+        deps: [
+          { depName: 'autoprefixer', currentValue: '6.5.0' },
+          { depName: 'bower', currentValue: '~1.6.0' },
+          { depName: 'browserify', currentValue: '13.1.0' },
+          { depName: 'browserify-css', currentValue: '0.9.2' },
+          { depName: 'cheerio', currentValue: '=0.22.0' },
+          { depName: 'config', currentValue: '1.21.0' },
+          { depName: 'enabled', skipReason: 'invalid-value' },
+          { depName: 'angular', currentValue: '^1.5.8' },
+          { depName: 'angular-touch', currentValue: '1.5.8' },
+          { depName: 'angular-sanitize', currentValue: '1.5.8' },
+          { depName: '@angular/core', currentValue: '4.0.0-beta.1' },
+          { depName: 'config', currentValue: '1.21.0' },
+          { depName: '@angular/cli', currentValue: '8.0.0' },
+          { depName: 'angular', currentValue: '1.33.0' },
+          { depName: 'glob', currentValue: '1.0.0' },
+        ],
+      });
     });
     it('returns an array of dependencies with resolution comments', async () => {
       const res = await npmExtract.extractPackageFile(
@@ -90,8 +108,26 @@ describe('manager/npm/extract/index', () => {
         defaultConfig
       );
       expect(res?.deps).toHaveLength(13);
-      // FIXME: explicit assert condition
-      expect(res).toMatchSnapshot();
+      expect(res).toMatchSnapshot({
+        constraints: {},
+        deps: [
+          ...[{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}],
+          {
+            depName: undefined,
+            depType: 'resolutions',
+            managerData: { key: '//' },
+            prettyDepType: 'resolutions',
+            skipReason: 'invalid-name',
+          },
+          {
+            depName: 'config',
+            currentValue: '1.21.0',
+            depType: 'resolutions',
+            managerData: { key: '**/config' },
+            prettyDepType: 'resolutions',
+          },
+        ],
+      });
     });
     it('finds a lock file', async () => {
       fs.readLocalFile = jest.fn((fileName) => {
@@ -105,8 +141,7 @@ describe('manager/npm/extract/index', () => {
         'package.json',
         defaultConfig
       );
-      // FIXME: explicit assert condition
-      expect(res).toMatchSnapshot();
+      expect(res).toMatchSnapshot({ yarnLock: 'yarn.lock' });
     });
     it('finds and filters .npmrc', async () => {
       fs.readLocalFile = jest.fn((fileName) => {
@@ -176,8 +211,11 @@ describe('manager/npm/extract/index', () => {
         'package.json',
         defaultConfig
       );
-      // FIXME: explicit assert condition
-      expect(res).toMatchSnapshot();
+      expect(res).toMatchSnapshot({
+        lernaClient: 'npm',
+        lernaPackages: undefined,
+        managerData: { lernaJsonFile: 'lerna.json' },
+      });
     });
     it('finds "npmClient":"npm" in lerna.json', async () => {
       fs.readLocalFile = jest.fn((fileName) => {
@@ -191,8 +229,11 @@ describe('manager/npm/extract/index', () => {
         'package.json',
         defaultConfig
       );
-      // FIXME: explicit assert condition
-      expect(res).toMatchSnapshot();
+      expect(res).toMatchSnapshot({
+        lernaClient: 'npm',
+        lernaPackages: undefined,
+        managerData: { lernaJsonFile: 'lerna.json' },
+      });
     });
     it('finds "npmClient":"yarn" in lerna.json', async () => {
       fs.readLocalFile = jest.fn((fileName) => {
@@ -206,8 +247,11 @@ describe('manager/npm/extract/index', () => {
         'package.json',
         defaultConfig
       );
-      // FIXME: explicit assert condition
-      expect(res).toMatchSnapshot();
+      expect(res).toMatchSnapshot({
+        lernaClient: 'yarn',
+        lernaPackages: undefined,
+        managerData: { lernaJsonFile: 'lerna.json' },
+      });
     });
     it('finds simple yarn workspaces', async () => {
       fs.readLocalFile = jest.fn((fileName) => {
@@ -221,8 +265,7 @@ describe('manager/npm/extract/index', () => {
         'package.json',
         defaultConfig
       );
-      // FIXME: explicit assert condition
-      expect(res).toMatchSnapshot();
+      expect(res).toMatchSnapshot({ yarnWorkspacesPackages: ['packages/*'] });
     });
     it('finds simple yarn workspaces with lerna.json and useWorkspaces: true', async () => {
       fs.readLocalFile = jest.fn((fileName) => {
@@ -236,8 +279,7 @@ describe('manager/npm/extract/index', () => {
         'package.json',
         defaultConfig
       );
-      // FIXME: explicit assert condition
-      expect(res).toMatchSnapshot();
+      expect(res).toMatchSnapshot({ yarnWorkspacesPackages: ['packages/*'] });
     });
     it('finds complex yarn workspaces', async () => {
       fs.readLocalFile = jest.fn((fileName) => {
@@ -251,8 +293,7 @@ describe('manager/npm/extract/index', () => {
         'package.json',
         defaultConfig
       );
-      // FIXME: explicit assert condition
-      expect(res).toMatchSnapshot();
+      expect(res).toMatchSnapshot({ yarnWorkspacesPackages: ['packages/*'] });
     });
     it('extracts engines', async () => {
       const pJson = {
@@ -282,8 +323,69 @@ describe('manager/npm/extract/index', () => {
         'package.json',
         defaultConfig
       );
-      // FIXME: explicit assert condition
-      expect(res).toMatchSnapshot();
+      expect(res).toMatchSnapshot({
+        constraints: {
+          node: '>= 8.9.2',
+          npm: '^8.0.0',
+          pnpm: '^1.2.0',
+          vscode: '>=1.49.3',
+          yarn: 'disabled',
+        },
+        deps: [
+          { depName: 'angular', currentValue: '1.6.0' },
+          { depName: '@angular/cli', currentValue: '1.6.0' },
+          { depName: 'foo', currentValue: '*', skipReason: 'any-version' },
+          {
+            depName: 'bar',
+            currentValue: 'file:../foo/bar',
+            skipReason: 'file',
+          },
+          { depName: 'baz', currentValue: '', skipReason: 'empty' },
+          {
+            depName: 'other',
+            currentValue: 'latest',
+            skipReason: 'unknown-version',
+          },
+          {
+            depName: 'atom',
+            currentValue: '>=1.7.0 <2.0.0',
+            skipReason: 'unknown-engines',
+            depType: 'engines',
+          },
+          {
+            depName: 'node',
+            currentValue: '>= 8.9.2',
+            datasource: 'github-tags',
+            versioning: 'node',
+            depType: 'engines',
+          },
+          {
+            depName: 'npm',
+            currentValue: '^8.0.0',
+            datasource: 'npm',
+            depType: 'engines',
+          },
+          {
+            depName: 'pnpm',
+            currentValue: '^1.2.0',
+            datasource: 'npm',
+            depType: 'engines',
+          },
+          {
+            depName: 'yarn',
+            currentValue: 'disabled',
+            datasource: 'npm',
+            depType: 'engines',
+            skipReason: 'unknown-version',
+          },
+          {
+            depName: 'vscode',
+            currentValue: '>=1.49.3',
+            depType: 'engines',
+            datasource: 'github-tags',
+          },
+        ],
+      });
     });
     it('extracts volta', async () => {
       const pJson = {
@@ -304,8 +406,18 @@ describe('manager/npm/extract/index', () => {
         'package.json',
         defaultConfig
       );
-      // FIXME: explicit assert condition
-      expect(res).toMatchSnapshot();
+      expect(res).toMatchSnapshot({
+        deps: [
+          ...[{}, {}, {}, {}],
+          {
+            depType: 'volta',
+            currentValue: '6.11.2',
+            depName: 'pnpm',
+            prettyDepType: 'volta',
+            skipReason: 'unknown-volta',
+          },
+        ],
+      });
     });
 
     it('extracts volta yarn unknown-version', async () => {
@@ -325,8 +437,30 @@ describe('manager/npm/extract/index', () => {
         'package.json',
         defaultConfig
       );
-      // FIXME: explicit assert condition
-      expect(res).toMatchSnapshot();
+      expect(res).toMatchSnapshot({
+        deps: [
+          {},
+          {
+            commitMessageTopic: 'Node.js',
+            currentValue: '8.9.2',
+            datasource: 'github-tags',
+            depName: 'node',
+            depType: 'volta',
+            lookupName: 'nodejs/node',
+            prettyDepType: 'volta',
+            versioning: 'node',
+          },
+          {
+            commitMessageTopic: 'Yarn',
+            currentValue: 'unknown',
+            datasource: 'npm',
+            depName: 'yarn',
+            depType: 'volta',
+            prettyDepType: 'volta',
+            skipReason: 'unknown-version',
+          },
+        ],
+      });
     });
     it('extracts non-npmjs', async () => {
       const pJson = {
@@ -354,8 +488,91 @@ describe('manager/npm/extract/index', () => {
         'package.json',
         defaultConfig
       );
-      // FIXME: explicit assert condition
-      expect(res).toMatchSnapshot();
+      expect(res).toMatchSnapshot({
+        deps: [
+          { depName: 'a', skipReason: 'unknown-version' },
+          { depName: 'b', skipReason: 'unversioned-reference' },
+          {
+            depName: 'c',
+            currentValue: 'v1.1.0',
+            datasource: 'github-tags',
+            sourceUrl: 'https://github.com/owner/c',
+          },
+          {
+            depName: 'd',
+            currentValue: 'github:owner/d#a7g3eaf',
+            skipReason: 'unversioned-reference',
+          },
+          {
+            depName: 'e',
+            currentValue: null,
+            currentDigest: '49b5aca613b33c5b626ae68c03a385f25c142f55',
+            datasource: 'github-tags',
+            sourceUrl: 'https://github.com/owner/e',
+          },
+          {
+            depName: 'f',
+            currentValue: 'v2.0.0',
+            datasource: 'github-tags',
+            sourceUrl: 'https://github.com/owner/f',
+          },
+          {
+            depName: 'g',
+            currentValue: 'gitlab:owner/g#v1.0.0',
+            skipReason: 'unknown-version',
+          },
+          {
+            depName: 'h',
+            currentValue: 'github:-hello/world#v1.0.0',
+            skipReason: 'unknown-version',
+          },
+          {
+            depName: 'i',
+            currentValue: '@foo/bar#v2.0.0',
+            skipReason: 'unknown-version',
+          },
+          {
+            depName: 'j',
+            currentValue: 'github:frank#v0.0.1',
+            skipReason: 'unknown-version',
+          },
+          {
+            depName: 'k',
+            currentValue: null,
+            currentDigest: '49b5aca',
+            currentRawValue: 'github:owner/k#49b5aca',
+            datasource: 'github-tags',
+            sourceUrl: 'https://github.com/owner/k',
+          },
+          {
+            depName: 'l',
+            currentValue: null,
+            currentDigest: 'abcdef0',
+            currentRawValue: 'github:owner/l.git#abcdef0',
+            datasource: 'github-tags',
+            sourceUrl: 'https://github.com/owner/l',
+          },
+          {
+            depName: 'm',
+            currentValue: 'v1.0.0',
+            currentRawValue: 'https://github.com/owner/m.git#v1.0.0',
+            datasource: 'github-tags',
+            sourceUrl: 'https://github.com/owner/m',
+          },
+          {
+            depName: 'n',
+            currentValue: 'v2.0.0',
+            datasource: 'github-tags',
+            sourceUrl: 'https://github.com/owner/n',
+          },
+          {
+            depName: 'o',
+            currentValue: 'v2.0.0',
+            datasource: 'github-tags',
+            sourceUrl: 'https://github.com/owner/o',
+          },
+        ],
+      });
     });
     it('extracts npm package alias', async () => {
       fs.readLocalFile = jest.fn((fileName) => {
@@ -377,8 +594,13 @@ describe('manager/npm/extract/index', () => {
         'package.json',
         defaultConfig
       );
-      // FIXME: explicit assert condition
-      expect(res).toMatchSnapshot();
+      expect(res).toMatchSnapshot({
+        deps: [
+          { lookupName: 'foo' },
+          { lookupName: '@foo/bar' },
+          { depName: 'c' },
+        ],
+      });
     });
 
     it('sets skipInstalls false if Yarn zero-install is used', async () => {
@@ -410,8 +632,20 @@ describe('manager/npm/extract/index', () => {
         'package.json',
         defaultConfig
       );
-      // FIXME: explicit assert condition
-      expect(res).toMatchSnapshot();
+      expect(res).toMatchSnapshot({
+        constraints: { yarn: '3.0.0' },
+        deps: [
+          {
+            commitMessageTopic: 'Yarn',
+            currentValue: '3.0.0',
+            datasource: 'npm',
+            depName: 'yarn',
+            depType: 'packageManager',
+            lookupName: '@yarnpkg/cli',
+            prettyDepType: 'packageManager',
+          },
+        ],
+      });
     });
   });
   describe('.postExtract()', () => {
-- 
GitLab