-
-
Notifications
You must be signed in to change notification settings - Fork 622
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add tests for project root finder util (#1483)
- Loading branch information
Showing
3 changed files
with
28 additions
and
3 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 @@ | ||
{} |
24 changes: 24 additions & 0 deletions
24
packages/utils/__tests__/find-project-root/project/find-project-root.test.ts
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,24 @@ | ||
// eslint-disable-next-line node/no-unpublished-import | ||
import { findProjectRoot } from '../../../src/path-utils'; | ||
import { join } from 'path'; | ||
|
||
beforeAll(() => { | ||
// This sets the project root as the root dir, needed since some tests change process cwd. | ||
process.chdir(join(__dirname, '../../../../../')); | ||
}); | ||
|
||
describe('findProjectRoot function', () => { | ||
it('works correctly', () => { | ||
/* when no directory is passed, it takes the current process working directory as starting point | ||
which contains package.json thus it should be the project root */ | ||
const projectRoot = findProjectRoot(); | ||
expect(projectRoot).toEqual(process.cwd()); | ||
}); | ||
|
||
it('works correctly with a non-default dir', () => { | ||
/* when passing a custom directory, it's used as the starting point and so it should yield the path | ||
nearest package.json from the given directory */ | ||
const projectRoot = findProjectRoot(__dirname); | ||
expect(projectRoot).toEqual(join(__dirname, '..')); | ||
}); | ||
}); |
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