Skip to content

Commit

Permalink
refactor: use it.each instead of for loop (#50)
Browse files Browse the repository at this point in the history
* test: use it.each instead of for-loop

* style: fmt
  • Loading branch information
Omochice authored May 5, 2024
1 parent a2f4042 commit fda8f51
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 123 deletions.
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
"version": "2.3.0",
"private": true,
"description": "renovate configuration for me",
"keywords": [
"renovate"
],
"keywords": ["renovate"],
"license": "zlib",
"author": "Omochice",
"scripts": {
Expand Down
44 changes: 20 additions & 24 deletions test/deno/deno-land.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,16 @@ describe("deno.land for import map", () => {
},
] as const;

for (const testCase of testCases) {
it(testCase.title, () => {
const re = regexps[0].map((r) => new RegExp(r, "gm"));
const matches = re
.map((r) => Array.from(testCase.input.matchAll(r)).map((e) => e.groups))
.filter((match) => match.length !== 0)
.flat();
expect(matches.length).toBe(1);
expect(matches[0]?.currentValue).toBe(testCase.currentValue);
expect(matches[0]?.depName).toBe(testCase.depName);
});
}
it.each(testCases)("$title", ({ input, currentValue, depName }) => {
const re = regexps[0].map((r) => new RegExp(r, "gm"));
const matches = re
.map((r) => Array.from(input.matchAll(r)).map((e) => e.groups))
.filter((match) => match.length !== 0)
.flat();
expect(matches.length).toBe(1);
expect(matches[0]?.currentValue).toBe(currentValue);
expect(matches[0]?.depName).toBe(depName);
});
});

describe("deno.land for import map", () => {
Expand Down Expand Up @@ -118,16 +116,14 @@ describe("deno.land for import map", () => {
},
] as const;

for (const testCase of testCases) {
it(testCase.title, () => {
const re = regexps[1].map((r) => new RegExp(r, "gm"));
const matches = re
.map((r) => Array.from(testCase.input.matchAll(r)).map((e) => e.groups))
.filter((match) => match.length !== 0)
.flat();
expect(matches.length).toBe(1);
expect(matches[0]?.currentValue).toBe(testCase.currentValue);
expect(matches[0]?.depName).toBe(testCase.depName);
});
}
it.each(testCases)("$title", ({ input, currentValue, depName }) => {
const re = regexps[1].map((r) => new RegExp(r, "gm"));
const matches = re
.map((r) => Array.from(input.matchAll(r)).map((e) => e.groups))
.filter((match) => match.length !== 0)
.flat();
expect(matches.length).toBe(1);
expect(matches[0]?.currentValue).toBe(currentValue);
expect(matches[0]?.depName).toBe(depName);
});
});
44 changes: 20 additions & 24 deletions test/deno/github-tag.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,16 @@ describe("github tag for import_map", () => {
},
];

for (const testCase of testCases) {
it(testCase.title, () => {
const re = regexps[0].map((r) => new RegExp(r, "gm"));
const matches = re
.map((r) => Array.from(testCase.input.matchAll(r)).map((e) => e.groups))
.filter((match) => match.length !== 0)
.flat();
expect(matches.length).toBe(1);
expect(matches[0]?.currentValue).toBe(testCase.currentValue);
expect(matches[0]?.depName).toBe(testCase.depName);
});
}
it.each(testCases)("$title", ({ input, currentValue, depName }) => {
const re = regexps[0].map((r) => new RegExp(r, "gm"));
const matches = re
.map((r) => Array.from(input.matchAll(r)).map((e) => e.groups))
.filter((match) => match.length !== 0)
.flat();
expect(matches.length).toBe(1);
expect(matches[0]?.currentValue).toBe(currentValue);
expect(matches[0]?.depName).toBe(depName);
});
});

describe("github tag for js file", () => {
Expand Down Expand Up @@ -157,16 +155,14 @@ describe("github tag for js file", () => {
},
];

for (const testCase of testCases) {
it(testCase.title, () => {
const re = regexps[1].map((r) => new RegExp(r, "gm"));
const matches = re
.map((r) => Array.from(testCase.input.matchAll(r)).map((e) => e.groups))
.filter((match) => match.length !== 0)
.flat();
expect(matches.length).toBe(1);
expect(matches[0]?.currentValue).toBe(testCase.currentValue);
expect(matches[0]?.depName).toBe(testCase.depName);
});
}
it.each(testCases)("$title", ({ input, currentValue, depName }) => {
const re = regexps[1].map((r) => new RegExp(r, "gm"));
const matches = re
.map((r) => Array.from(input.matchAll(r)).map((e) => e.groups))
.filter((match) => match.length !== 0)
.flat();
expect(matches.length).toBe(1);
expect(matches[0]?.currentValue).toBe(currentValue);
expect(matches[0]?.depName).toBe(depName);
});
});
44 changes: 20 additions & 24 deletions test/deno/jsr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,16 @@ describe("jsr for import map", () => {
},
] as const;

for (const testCase of testCases) {
it(testCase.title, () => {
const re = regexps[0].map((r) => new RegExp(r, "gm"));
const matches = re
.map((r) => Array.from(testCase.input.matchAll(r)).map((e) => e.groups))
.filter((match) => match.length !== 0)
.flat();
expect(matches.length).toBe(1);
expect(matches[0]?.currentValue).toBe(testCase.currentValue);
expect(matches[0]?.depName).toBe(testCase.depName);
});
}
it.each(testCases)("$title", ({ input, currentValue, depName }) => {
const re = regexps[0].map((r) => new RegExp(r, "gm"));
const matches = re
.map((r) => Array.from(input.matchAll(r)).map((e) => e.groups))
.filter((match) => match.length !== 0)
.flat();
expect(matches.length).toBe(1);
expect(matches[0]?.currentValue).toBe(currentValue);
expect(matches[0]?.depName).toBe(depName);
});
});

describe("jsr for js file", () => {
Expand Down Expand Up @@ -108,16 +106,14 @@ describe("jsr for js file", () => {
},
] as const;

for (const testCase of testCases) {
it(testCase.title, () => {
const re = regexps[1].map((r) => new RegExp(r, "gm"));
const matches = re
.map((r) => Array.from(testCase.input.matchAll(r)).map((e) => e.groups))
.filter((match) => match.length !== 0)
.flat();
expect(matches.length).toBe(1);
expect(matches[0]?.currentValue).toBe(testCase.currentValue);
expect(matches[0]?.depName).toBe(testCase.depName);
});
}
it.each(testCases)("$title", ({ input, currentValue, depName }) => {
const re = regexps[1].map((r) => new RegExp(r, "gm"));
const matches = re
.map((r) => Array.from(input.matchAll(r)).map((e) => e.groups))
.filter((match) => match.length !== 0)
.flat();
expect(matches.length).toBe(1);
expect(matches[0]?.currentValue).toBe(currentValue);
expect(matches[0]?.depName).toBe(depName);
});
});
44 changes: 20 additions & 24 deletions test/deno/nest-land.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,16 @@ describe("x.nest.land for import_map", () => {
},
];

for (const testCase of testCases) {
it(testCase.title, () => {
const re = regexps[0].map((r) => new RegExp(r, "gm"));
const matches = re
.map((r) => Array.from(testCase.input.matchAll(r)).map((e) => e.groups))
.filter((match) => match.length !== 0)
.flat();
expect(matches.length).toBe(1);
expect(matches[0]?.currentValue).toBe(testCase.currentValue);
expect(matches[0]?.depName).toBe(testCase.depName);
});
}
it.each(testCases)("$title", ({ input, currentValue, depName }) => {
const re = regexps[0].map((r) => new RegExp(r, "gm"));
const matches = re
.map((r) => Array.from(input.matchAll(r)).map((e) => e.groups))
.filter((match) => match.length !== 0)
.flat();
expect(matches.length).toBe(1);
expect(matches[0]?.currentValue).toBe(currentValue);
expect(matches[0]?.depName).toBe(depName);
});
});

describe("x.nest.land for js file", () => {
Expand Down Expand Up @@ -90,16 +88,14 @@ describe("x.nest.land for js file", () => {
},
];

for (const testCase of testCases) {
it(testCase.title, () => {
const re = regexps[1].map((r) => new RegExp(r, "gm"));
const matches = re
.map((r) => Array.from(testCase.input.matchAll(r)).map((e) => e.groups))
.filter((match) => match.length !== 0)
.flat();
expect(matches.length).toBe(1);
expect(matches[0]?.currentValue).toBe(testCase.currentValue);
expect(matches[0]?.depName).toBe(testCase.depName);
});
}
it.each(testCases)("$title", ({ input, currentValue, depName }) => {
const re = regexps[1].map((r) => new RegExp(r, "gm"));
const matches = re
.map((r) => Array.from(input.matchAll(r)).map((e) => e.groups))
.filter((match) => match.length !== 0)
.flat();
expect(matches.length).toBe(1);
expect(matches[0]?.currentValue).toBe(currentValue);
expect(matches[0]?.depName).toBe(depName);
});
});
44 changes: 20 additions & 24 deletions test/deno/npm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,16 @@ describe("npm for import map", () => {
},
] as const;

for (const testCase of testCases) {
it(testCase.title, () => {
const re = regexps[0].map((r) => new RegExp(r, "gm"));
const matches = re
.map((r) => Array.from(testCase.input.matchAll(r)).map((e) => e.groups))
.filter((match) => match.length !== 0)
.flat();
expect(matches.length).toBe(1);
expect(matches[0]?.currentValue).toBe(testCase.currentValue);
expect(matches[0]?.depName).toBe(testCase.depName);
});
}
it.each(testCases)("$title", ({ input, currentValue, depName }) => {
const re = regexps[0].map((r) => new RegExp(r, "gm"));
const matches = re
.map((r) => Array.from(input.matchAll(r)).map((e) => e.groups))
.filter((match) => match.length !== 0)
.flat();
expect(matches.length).toBe(1);
expect(matches[0]?.currentValue).toBe(currentValue);
expect(matches[0]?.depName).toBe(depName);
});
});

// NOTE: This feature is not required in the imports field in deno.json and source files.
Expand Down Expand Up @@ -250,16 +248,14 @@ describe("npm for js file", () => {
},
] as const;

for (const testCase of testCases) {
it(testCase.title, () => {
const re = regexps[1].map((r) => new RegExp(r, "gm"));
const matches = re
.map((r) => Array.from(testCase.input.matchAll(r)).map((e) => e.groups))
.filter((match) => match.length !== 0)
.flat();
expect(matches.length).toBe(1);
expect(matches[0]?.currentValue).toBe(testCase.currentValue);
expect(matches[0]?.depName).toBe(testCase.depName);
});
}
it.each(testCases)("$title", ({ input, currentValue, depName }) => {
const re = regexps[1].map((r) => new RegExp(r, "gm"));
const matches = re
.map((r) => Array.from(input.matchAll(r)).map((e) => e.groups))
.filter((match) => match.length !== 0)
.flat();
expect(matches.length).toBe(1);
expect(matches[0]?.currentValue).toBe(currentValue);
expect(matches[0]?.depName).toBe(depName);
});
});

0 comments on commit fda8f51

Please sign in to comment.