-
Notifications
You must be signed in to change notification settings - Fork 28
feat: display peerDependencies in deps page #123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ const createMockManifest = ( | |
| dependencies: Record<string, string>; | ||
| devDependencies: Record<string, string>; | ||
| optionalDependencies: Record<string, string>; | ||
| peerDependencies: Record<string, string>; | ||
| }> = {} | ||
| ): PackageManifest => ({ | ||
| name: 'test-package', | ||
|
|
@@ -39,6 +40,7 @@ const createMockManifest = ( | |
| dependencies: versionData.dependencies || {}, | ||
| devDependencies: versionData.devDependencies || {}, | ||
| optionalDependencies: versionData.optionalDependencies, | ||
| peerDependencies: versionData.peerDependencies, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
@@ -87,8 +89,51 @@ describe('Deps Component', () => { | |
| }); | ||
| }); | ||
|
|
||
| describe('peerDependencies', () => { | ||
| it('should display peerDependencies section', () => { | ||
| const manifest = createMockManifest({ | ||
| peerDependencies: { | ||
| 'react': '^18.0.0', | ||
| }, | ||
| }); | ||
|
|
||
| render(<Deps manifest={manifest} version="1.0.0" />); | ||
|
|
||
| expect(screen.getByText('PeerDependencies (1)')).toBeInTheDocument(); | ||
| expect(screen.getByText('react')).toBeInTheDocument(); | ||
| expect(screen.getByText('^18.0.0')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should display empty peerDependencies section when none exist', () => { | ||
| const manifest = createMockManifest({ | ||
| dependencies: { 'lodash': '^4.17.21' }, | ||
| }); | ||
|
|
||
| render(<Deps manifest={manifest} version="1.0.0" />); | ||
|
|
||
| expect(screen.getByText('PeerDependencies (0)')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should display multiple peerDependencies', () => { | ||
| const manifest = createMockManifest({ | ||
| peerDependencies: { | ||
| 'react': '^18.0.0', | ||
| 'react-dom': '^18.0.0', | ||
| 'next': '^13.0.0', | ||
| }, | ||
| }); | ||
|
|
||
| render(<Deps manifest={manifest} version="1.0.0" />); | ||
|
|
||
| expect(screen.getByText('PeerDependencies (3)')).toBeInTheDocument(); | ||
| expect(screen.getByText('react')).toBeInTheDocument(); | ||
| expect(screen.getByText('react-dom')).toBeInTheDocument(); | ||
| expect(screen.getByText('next')).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('all dependency types together', () => { | ||
| it('should display all three dependency types', () => { | ||
| it('should display all four dependency types', () => { | ||
| const manifest = createMockManifest({ | ||
| dependencies: { | ||
| 'react': '^18.2.0', | ||
|
|
@@ -102,13 +147,17 @@ describe('Deps Component', () => { | |
| optionalDependencies: { | ||
| 'fsevents': '^2.3.0', | ||
| }, | ||
| peerDependencies: { | ||
| 'webpack': '^5.0.0', | ||
| }, | ||
| }); | ||
|
|
||
| render(<Deps manifest={manifest} version="1.0.0" />); | ||
|
|
||
| expect(screen.getByText('Dependencies (2)')).toBeInTheDocument(); | ||
| expect(screen.getByText('DevDependencies (3)')).toBeInTheDocument(); | ||
| expect(screen.getByText('OptionalDependencies (1)')).toBeInTheDocument(); | ||
| expect(screen.getByText('PeerDependencies (1)')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should handle missing version data gracefully', () => { | ||
|
|
@@ -121,6 +170,7 @@ describe('Deps Component', () => { | |
| expect(screen.getByText('Dependencies (0)')).toBeInTheDocument(); | ||
| expect(screen.getByText('DevDependencies (0)')).toBeInTheDocument(); | ||
| expect(screen.getByText('OptionalDependencies (0)')).toBeInTheDocument(); | ||
| expect(screen.getByText('PeerDependencies (0)')).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
|
|
||
|
|
@@ -137,5 +187,18 @@ describe('Deps Component', () => { | |
| const link = screen.getByRole('link', { name: 'fsevents' }); | ||
| expect(link).toHaveAttribute('href', '/package/fsevents?version=%5E2.3.0'); | ||
| }); | ||
|
|
||
| it('should create correct links for peerDependencies', () => { | ||
| const manifest = createMockManifest({ | ||
| peerDependencies: { | ||
| 'react': '^18.0.0', | ||
| }, | ||
| }); | ||
|
|
||
| render(<Deps manifest={manifest} version="1.0.0" />); | ||
|
|
||
| const link = screen.getByRole('link', { name: 'react' }); | ||
| expect(link).toHaveAttribute('href', '/package/react?version=%5E18.0.0'); | ||
| }); | ||
|
Comment on lines
+191
to
+202
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test is a good addition. Similar to my other comment, this test is very similar to the one for Example: it.each([
{ depType: 'optionalDependencies', pkg: 'fsevents', version: '^2.3.0' },
{ depType: 'peerDependencies', pkg: 'react', version: '^18.0.0' },
])('should create correct links for $depType', ({ depType, pkg, version }) => {
const manifest = createMockManifest({
[depType]: { [pkg]: version },
});
render(<Deps manifest={manifest} version=\"1.0.0\" />);
const link = screen.getByRole('link', { name: pkg });
expect(link).toHaveAttribute('href', `/package/${pkg}?version=${encodeURIComponent(version)}`);
});This would make the tests more maintainable. |
||
| }); | ||
| }); | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new test suite for
peerDependenciesis great for coverage. However, it's almost identical to the existing suite foroptionalDependencies. To avoid code duplication in tests, you could usedescribe.eachfromvitestto parameterize these tests. This would make the test file more concise and easier to maintain if other dependency types need similar tests in the future.Here's an example of how you could combine the tests for
optionalDependenciesandpeerDependencies:Since this would involve refactoring existing tests, you might consider doing it in a follow-up PR.