-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: startsWith cannot determine subdirectories correctly (#4916)
- Loading branch information
Showing
4 changed files
with
47 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@modern-js/app-tools': patch | ||
--- | ||
|
||
fix: startsWith cannot determine subdirectories correctly | ||
fix: startsWith 函数不能正确地判断子目录 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import path from 'node:path'; | ||
import { isSubDirOrEqual } from '../../src/analyze/utils'; | ||
|
||
describe('isSubDirOrEqual', () => { | ||
it('should return true for the same directories', () => { | ||
const parent = path.resolve('/Users/test'); | ||
const child = path.resolve('/Users/test'); | ||
expect(isSubDirOrEqual(parent, child)).toBe(true); | ||
}); | ||
|
||
it('should return true for a child directory', () => { | ||
const parent = path.resolve('/Users'); | ||
const child = path.resolve('/Users/test'); | ||
expect(isSubDirOrEqual(parent, child)).toBe(true); | ||
}); | ||
|
||
it('should return false for a non-child directory', () => { | ||
const parent = path.resolve('/Users/test'); | ||
const child = path.resolve('/Users/anotherTest'); | ||
expect(isSubDirOrEqual(parent, child)).toBe(false); | ||
}); | ||
|
||
it('should return false for a directory at a higher level', () => { | ||
const parent = path.resolve('/Users/test/deeper'); | ||
const child = path.resolve('/Users/test'); | ||
expect(isSubDirOrEqual(parent, child)).toBe(false); | ||
}); | ||
}); |