Skip to content

Commit ef1df0a

Browse files
committed
test(coverage): cover pathRelativeToTarget recursive prefix branch
Adds tests for previously-untested pathRelativeToTarget exports: - target='.' or '' → returns normalized path verbatim - path equals target → returns '**' - path nested under target → returns relative path - path with recursive '**/' prefix matches target (line 177) → returns the relative path including the recursive segment - path outside target → returns undefined exclude-paths.mts: 97.87% → 100% statements.
1 parent c90b5f7 commit ef1df0a

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

packages/cli/test/unit/commands/scan/exclude-paths.test.mts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
assertNoNegationPatterns,
1313
excludePathToProjectIgnorePath,
1414
normalizeExcludePath,
15+
pathRelativeToTarget,
1516
projectIgnorePathsToReachExcludePaths,
1617
} from '../../../../src/commands/scan/exclude-paths.mts'
1718
import { InputError } from '../../../../src/utils/error/errors.mts'
@@ -186,4 +187,36 @@ describe('exclude-paths', () => {
186187
)
187188
})
188189
})
190+
191+
describe('pathRelativeToTarget', () => {
192+
it('returns the normalized path when target is "."', () => {
193+
expect(pathRelativeToTarget('foo/bar', '.')).toBe('foo/bar')
194+
})
195+
196+
it('returns the normalized path when target is empty string', () => {
197+
expect(pathRelativeToTarget('foo/bar', '')).toBe('foo/bar')
198+
})
199+
200+
it('returns "**" when path equals target', () => {
201+
expect(pathRelativeToTarget('packages/cli', 'packages/cli')).toBe('**')
202+
})
203+
204+
it('strips the target prefix from a nested path', () => {
205+
expect(
206+
pathRelativeToTarget('packages/cli/src/foo', 'packages/cli'),
207+
).toBe('src/foo')
208+
})
209+
210+
it('strips the target prefix when path uses recursive **/ prefix (line 177)', () => {
211+
// path = "packages/cli/**/dist/foo" with target = "packages/cli"
212+
// → matches recursiveTargetPrefix "packages/cli/**/" branch.
213+
expect(
214+
pathRelativeToTarget('packages/cli/**/dist/foo', 'packages/cli'),
215+
).toBe('**/dist/foo')
216+
})
217+
218+
it('returns undefined when path is outside the target', () => {
219+
expect(pathRelativeToTarget('other/dir', 'packages/cli')).toBeUndefined()
220+
})
221+
})
189222
})

0 commit comments

Comments
 (0)