Skip to content

Commit

Permalink
refactor(test): simplified parameteric tests for exclude filter
Browse files Browse the repository at this point in the history
  • Loading branch information
vvagaytsev committed Dec 4, 2023
1 parent b028a1c commit b1462fa
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions core/test/unit/src/vcs/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,22 +426,23 @@ const commonGitHandlerTests = (gitScanMode: GitScanMode) => {
// When ONLY exclude filter is defined,
// the exclusion paths with and without glob prefix **/ works in the same way.
context("when only exclude filter is specified", () => {
const globConfigs = [false, true]

function renderTestName(glob: boolean): string {
return glob ? "with globs" : "without globs"
}

function buildExcludePattern(path: string, glob: boolean): string {
return glob ? join("**", path) : path
}
const testParams = [
{
name: "without globs",
pathBuilder: (path: string) => path,
},
{
name: "with globs",
pathBuilder: (path: string) => join("**", path),
},
]

context("should filter out files that match the exclude filter", () => {
for (const glob of globConfigs) {
it(renderTestName(glob), async () => {
for (const testParam of testParams) {
it(testParam.name, async () => {
// FIXME
if (handler.name === "git-repo") {
if (!glob) {
if (testParam.name === "without globs") {
return
}
}
Expand Down Expand Up @@ -471,7 +472,7 @@ const commonGitHandlerTests = (gitScanMode: GitScanMode) => {
path: tmpPath,
scanRoot: undefined,
include: undefined,
exclude: [buildExcludePattern("foo.*", glob)],
exclude: [testParam.pathBuilder("foo.*")],
log,
})
)
Expand All @@ -487,8 +488,8 @@ const commonGitHandlerTests = (gitScanMode: GitScanMode) => {
context(
"should filter out all files from directories (including their sub-directories) that match the exclude filter",
() => {
for (const glob of globConfigs) {
it(renderTestName(glob), async () => {
for (const testParam of testParams) {
it(testParam.name, async () => {
// FIXME
if (handler.name === "git-repo") {
return
Expand Down Expand Up @@ -530,10 +531,7 @@ const commonGitHandlerTests = (gitScanMode: GitScanMode) => {
path: tmpPath,
scanRoot: undefined,
include: undefined, // when include: [], getFiles() always returns an empty result
exclude: [
buildExcludePattern(excludedDirName, glob),
buildExcludePattern(excludedSubDirectoryName, glob),
],
exclude: [testParam.pathBuilder(excludedDirName), testParam.pathBuilder(excludedSubDirectoryName)],
log,
})
)
Expand Down

0 comments on commit b1462fa

Please sign in to comment.