From 3ca6855d4c687fa38cc50b598c2d1f04436c1efe Mon Sep 17 00:00:00 2001
From: Sergei Zharinov <zharinov@users.noreply.github.com>
Date: Mon, 27 Sep 2021 10:06:38 +0300
Subject: [PATCH] test(nuget): Refactor versioning tests (#11903)

---
 .../nuget/__snapshots__/index.spec.ts.snap    |  49 --------
 lib/versioning/nuget/index.spec.ts            | 115 ++++++++++--------
 2 files changed, 61 insertions(+), 103 deletions(-)
 delete mode 100644 lib/versioning/nuget/__snapshots__/index.spec.ts.snap

diff --git a/lib/versioning/nuget/__snapshots__/index.spec.ts.snap b/lib/versioning/nuget/__snapshots__/index.spec.ts.snap
deleted file mode 100644
index ee47b71862..0000000000
--- a/lib/versioning/nuget/__snapshots__/index.spec.ts.snap
+++ /dev/null
@@ -1,49 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`versioning/nuget/index isStable 1.0.0+c30d7625 1`] = `true`;
-
-exports[`versioning/nuget/index isStable 1.2019.3.22 1`] = `true`;
-
-exports[`versioning/nuget/index isStable 2.0.2-pre20191018090318 1`] = `false`;
-
-exports[`versioning/nuget/index isStable 2.3.4-beta+1990ef74 1`] = `false`;
-
-exports[`versioning/nuget/index isStable 3.0.0-beta 1`] = `false`;
-
-exports[`versioning/nuget/index isStable 9.0.3 1`] = `true`;
-
-exports[`versioning/nuget/index isVersion and isValid 1.0.0+c30d7625 1`] = `"1.0.0+c30d7625"`;
-
-exports[`versioning/nuget/index isVersion and isValid 1.0.0+c30d7625 2`] = `"1.0.0+c30d7625"`;
-
-exports[`versioning/nuget/index isVersion and isValid 1.2019.3.22 1`] = `"1.2019.3.22"`;
-
-exports[`versioning/nuget/index isVersion and isValid 1.2019.3.22 2`] = `"1.2019.3.22"`;
-
-exports[`versioning/nuget/index isVersion and isValid 2.0.2-pre20191018090318 1`] = `"2.0.2-pre20191018090318"`;
-
-exports[`versioning/nuget/index isVersion and isValid 2.0.2-pre20191018090318 2`] = `"2.0.2-pre20191018090318"`;
-
-exports[`versioning/nuget/index isVersion and isValid 2.3.4-beta+1990ef74 1`] = `"2.3.4-beta+1990ef74"`;
-
-exports[`versioning/nuget/index isVersion and isValid 2.3.4-beta+1990ef74 2`] = `"2.3.4-beta+1990ef74"`;
-
-exports[`versioning/nuget/index isVersion and isValid 3.0.0.beta 1`] = `null`;
-
-exports[`versioning/nuget/index isVersion and isValid 3.0.0.beta 2`] = `null`;
-
-exports[`versioning/nuget/index isVersion and isValid 3.0.0-beta 1`] = `"3.0.0-beta"`;
-
-exports[`versioning/nuget/index isVersion and isValid 3.0.0-beta 2`] = `"3.0.0-beta"`;
-
-exports[`versioning/nuget/index isVersion and isValid 5.1.2-+ 1`] = `null`;
-
-exports[`versioning/nuget/index isVersion and isValid 5.1.2-+ 2`] = `null`;
-
-exports[`versioning/nuget/index isVersion and isValid 9.0.3 1`] = `"9.0.3"`;
-
-exports[`versioning/nuget/index isVersion and isValid 9.0.3 2`] = `"9.0.3"`;
-
-exports[`versioning/nuget/index isVersion and isValid 17.04 1`] = `"17.04"`;
-
-exports[`versioning/nuget/index isVersion and isValid 17.04 2`] = `"17.04"`;
diff --git a/lib/versioning/nuget/index.spec.ts b/lib/versioning/nuget/index.spec.ts
index c2f6bd2a39..d2d05f3846 100644
--- a/lib/versioning/nuget/index.spec.ts
+++ b/lib/versioning/nuget/index.spec.ts
@@ -1,62 +1,69 @@
 import nuget from '.';
 
 describe('versioning/nuget/index', () => {
-  describe('isVersion and isValid', () => {
-    [
-      '9.0.3',
-      '1.2019.3.22',
-      '3.0.0-beta',
-      '2.0.2-pre20191018090318',
-      '1.0.0+c30d7625',
-      '2.3.4-beta+1990ef74',
-      '17.04',
-      '3.0.0.beta',
-      '5.1.2-+',
-    ].forEach((version) => {
-      it(version, () => {
-        // FIXME: explicit assert condition
-        expect(nuget.isVersion(version)).toMatchSnapshot();
-        expect(nuget.isValid(version)).toMatchSnapshot();
-      });
-    });
+  test.each`
+    input                        | expected
+    ${'9.0.3'}                   | ${true}
+    ${'1.2019.3.22'}             | ${true}
+    ${'3.0.0-beta'}              | ${true}
+    ${'2.0.2-pre20191018090318'} | ${true}
+    ${'1.0.0+c30d7625'}          | ${true}
+    ${'2.3.4-beta+1990ef74'}     | ${true}
+    ${'17.04'}                   | ${true}
+    ${'3.0.0.beta'}              | ${false}
+    ${'5.1.2-+'}                 | ${false}
+  `('isValid("$input") === $expected', ({ input, expected }) => {
+    const res = !!nuget.isValid(input);
+    expect(res).toBe(expected);
   });
-  describe('isStable', () => {
-    [
-      '9.0.3',
-      '1.2019.3.22',
-      '3.0.0-beta',
-      '2.0.2-pre20191018090318',
-      '1.0.0+c30d7625',
-      '2.3.4-beta+1990ef74',
-    ].forEach((version) => {
-      it(version, () => {
-        // FIXME: explicit assert condition
-        expect(nuget.isStable(version)).toMatchSnapshot();
-      });
-    });
+
+  test.each`
+    input                        | expected
+    ${'9.0.3'}                   | ${true}
+    ${'1.2019.3.22'}             | ${true}
+    ${'3.0.0-beta'}              | ${true}
+    ${'2.0.2-pre20191018090318'} | ${true}
+    ${'1.0.0+c30d7625'}          | ${true}
+    ${'2.3.4-beta+1990ef74'}     | ${true}
+    ${'17.04'}                   | ${true}
+    ${'3.0.0.beta'}              | ${false}
+    ${'5.1.2-+'}                 | ${false}
+  `('isVersion("$input") === $expected', ({ input, expected }) => {
+    const res = !!nuget.isVersion(input);
+    expect(res).toBe(expected);
   });
-  describe('isEqual', () => {
-    it('should ignore leading zeros', () => {
-      expect(nuget.equals('17.4', '17.04')).toBe(true);
-    });
-    it('should treat missing trailing version parts as zero', () => {
-      expect(nuget.equals('1.4', '1.4.0')).toBe(true);
-      expect(nuget.equals('1.0.110', '1.0.110.0')).toBe(true);
-    });
-    it('should ignore hash suffixes', () => {
-      expect(nuget.equals('1.0.0', '1.0.0+c30d7625')).toBe(true);
-    });
+
+  test.each`
+    input                        | expected
+    ${'9.0.3'}                   | ${true}
+    ${'1.2019.3.22'}             | ${true}
+    ${'3.0.0-beta'}              | ${false}
+    ${'2.0.2-pre20191018090318'} | ${false}
+    ${'1.0.0+c30d7625'}          | ${true}
+    ${'2.3.4-beta+1990ef74'}     | ${false}
+  `('isStable("$input") === $expected', ({ input, expected }) => {
+    expect(nuget.isStable(input)).toBe(expected);
   });
-  describe('isGreaterThan', () => {
-    it('should compare using release number then suffix', () => {
-      expect(nuget.isGreaterThan('2.4.2', '2.4.1')).toBe(true);
-      expect(nuget.isGreaterThan('2.4-beta', '2.4-alpha')).toBe(true);
-      expect(nuget.isGreaterThan('1.9', '2')).toBe(false);
-      expect(nuget.isGreaterThan('1.9', '1.9.1')).toBe(false);
-    });
-    it('should prioritize non-prerelease over prerelease', () => {
-      expect(nuget.isGreaterThan('2.4.0', '2.4.0-beta')).toBe(true);
-      expect(nuget.isGreaterThan('2.4.0-alpha', '2.4.0')).toBe(false);
-    });
+
+  test.each`
+    a            | b                   | expected
+    ${'17.4'}    | ${'17.04'}          | ${true}
+    ${'1.4'}     | ${'1.4.0'}          | ${true}
+    ${'1.0.110'} | ${'1.0.110.0'}      | ${true}
+    ${'1.0.0'}   | ${'1.0.0+c30d7625'} | ${true}
+  `('equals($a, $b) === $expected', ({ a, b, expected }) => {
+    expect(nuget.equals(a, b)).toBe(expected);
+  });
+
+  test.each`
+    a                | b               | expected
+    ${'2.4.2'}       | ${'2.4.1'}      | ${true}
+    ${'2.4-beta'}    | ${'2.4-alpha'}  | ${true}
+    ${'1.9'}         | ${'2'}          | ${false}
+    ${'1.9'}         | ${'1.9.1'}      | ${false}
+    ${'2.4.0'}       | ${'2.4.0-beta'} | ${true}
+    ${'2.4.0-alpha'} | ${'2.4.0'}      | ${false}
+  `('isGreaterThan($a, $b) === $expected', ({ a, b, expected }) => {
+    expect(nuget.isGreaterThan(a, b)).toBe(expected);
   });
 });
-- 
GitLab