Skip to content

Conversation

@izumin5210
Copy link
Member

Summary

This PR adds comprehensive snapshot tests for the printer functions in both protoc-gen-pothos and protoc-gen-nexus packages, ensuring code generation quality and consistency.

What's Changed

  • Added test coverage for all printer functions: , , , and
  • Total of 63 test cases covering various protobuf patterns and edge cases
  • Support for multiple protobuf implementations: ts-proto, protobuf-es, google-protobuf, protobufjs
  • Snapshot testing to track generated code output and detect regressions

Test Coverage

  • Simple and complex message types
  • Nested types and enums
  • Oneof fields (required and optional)
  • Empty messages
  • Extension fields
  • Edge cases like squashed unions and cross-package imports

Benefits

  • Provides confidence when making changes to code generation logic
  • Documents expected output for various input patterns
  • Enables safe refactoring of printer implementations
  • Catches unintended changes in generated code

🤖 Generated with Claude Code

izumin5210 and others added 25 commits June 7, 2025 09:24
- Add comprehensive tests for createObjectTypeCode function
- Test various protobuf message types (simple, nested, oneof, empty)
- Support both ts-proto and protobuf-es libraries
- Include tests for messages with GraphQL extensions
- Generate snapshots to verify code output

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add tests for createEnumTypeCode function
- Test simple enums, enums without unspecified value
- Test nested enums and enums with extensions
- Support both ts-proto and protobuf-es libraries

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add tests for createInputObjectTypeCode function
- Test simple inputs, nested fields, oneof fields, empty inputs
- Test partial input types generation
- Support both ts-proto and protobuf-es libraries
- Include toProto function generation for protobuf-es

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add tests for createOneofUnionTypeCode function
- Test required and optional oneof unions
- Test squashed oneof unions
- Test imported oneof members
- Support both ts-proto and protobuf-es libraries
- Test different file layouts (proto_file vs graphql_type)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add tests for createObjectTypeCode function
- Test simple messages, nested fields, oneofs, empty messages
- Support google-protobuf and protobufjs libraries
- Include interface type generation
- Test messages with GraphQL extensions

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add tests for createEnumTypeCode function
- Test simple enums, enums without unspecified value
- Test nested enums and enums with extensions
- Support google-protobuf and protobufjs libraries

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add tests for createInputObjectTypeCode function
- Test simple inputs, nested fields, oneof fields, empty inputs
- Test partial input types generation
- Support google-protobuf and protobufjs libraries
- Include toProto function generation

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add comprehensive tests for oneofUnionType code generation
- Test simple oneof unions (required and optional)
- Test squashed unions from import_squashed_union edge case
- Cover both google-protobuf and protobufjs libraries
- Generate snapshots for expected output validation

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…egistry

- Use getTestapisFileDescriptorSet and createFileRegistry directly
- Create ObjectType directly from descriptor message
- Remove plugin wrapper and global variable hack
- Change packageName type to TestapisPackage for type safety
- Fix test case to use correct message name 'PrefixedMessage'

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…istry

- Use getTestapisFileDescriptorSet and createFileRegistry directly
- Create EnumType directly from descriptor enum
- Remove plugin wrapper and global variable hack
- Change packageName type to TestapisPackage for type safety
- Add special handling for nested enums and package name differences
- Fix test case to use correct enum name 'PrefixedEnum'

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…n approach

- Use buildCodeGeneratorRequest and plugin to get proper Schema context
- Remove direct registry usage as InputObjectType requires Schema context
- Change packageName type to TestapisPackage for type safety
- Add partialInputs parameter to support partial input testing
- Simplify partial input test case

Note: This is a temporary solution. A better approach would be to
construct InputObjectType directly from descriptors, but that requires
more investigation into the Schema/File context requirements.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Use buildCodeGeneratorRequest and createEcmaScriptPlugin
- Change packageName type to TestapisPackage for type safety
- Remove unnecessary plugin wrapper and global variable hack
- Keep special handling for import_oneof_member_from_other_file edge case

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…gistry

- Use getTestapisFileDescriptorSet and createFileRegistry directly
- Create ObjectType directly from descriptor message
- Remove plugin wrapper and global variable hack
- Change packageName type to TestapisPackage for type safety
- Fix test case to use correct message name 'PrefixedMessage'
- Remove ts-proto support as nexus doesn't support it

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…stry

- Use getTestapisFileDescriptorSet and createFileRegistry directly
- Create EnumType directly from descriptor enum
- Remove plugin wrapper and global variable hack
- Change packageName type to TestapisPackage for type safety
- Add special handling for nested enums and package name differences
- Fix test case to use correct enum name 'PrefixedEnum'
- Remove protobuf parameter from helper function

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
… approach

- Use buildCodeGeneratorRequest and plugin to get proper Schema context
- Change packageName type to TestapisPackage for type safety
- Add partialInputs parameter to support partial input testing
- Simplify partial input test case
- Remove unnecessary plugin wrapper for partial inputs test

Note: Similar to pothos, this uses the plugin approach as InputObjectType
requires Schema context for proper type creation.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Use buildCodeGeneratorRequest and createEcmaScriptPlugin
- Change packageName type to TestapisPackage for type safety
- Remove unnecessary plugin wrapper and global variable hack
- Keep special handling for import_squashed_union.pkg1 edge case

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…ect message construction

- Create InputObjectType directly from descriptor message
- Remove plugin wrapper completely and use registry directly
- Use inputType.toPartialInput() for partial inputs
- Rename parameter to typeNameInProto to clarify proto message name usage
- Update test cases to use actual proto message names instead of GraphQL type names

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…ct message construction

- Create InputObjectType directly from descriptor message
- Remove plugin wrapper completely and use registry directly
- Use inputType.toPartialInput() for partial inputs
- Rename parameter to typeNameInProto to clarify proto message name usage
- Update test cases to use actual proto message names instead of GraphQL type names

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…ct descriptor construction

- Create OneofUnionType directly from descriptor oneof field
- Create SquashedOneofUnionType directly from descriptor message
- Remove plugin wrapper completely and use registry directly
- Add explicit oneofFieldName parameter for clarity
- Split into two functions for regular and squashed unions
- Update test cases to use actual proto message and field names

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…t descriptor construction

- Replace plugin wrapper approach with getTestapisFileDescriptorSet and createFileRegistry
- Create OneofUnionType directly from descriptor oneof field
- Add explicit oneofFieldName parameter to generateOneofUnionTypeCode
- Split generation logic into generateOneofUnionTypeCode and generateSquashedOneofUnionTypeCode
- Update test calls to use proto message names (OneofParent) and oneof field names

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…n in enumType test

- Change parameter name from enumTypeName to enumTypeNameInProto for clarity
- Use dot notation for nested enums (e.g., ParentMessage.NestedEnum)
- Simplify enum lookup logic to directly use proto names
- Add special handling for testapi.enums package name discrepancy

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
… in enumType test

- Change parameter name from enumTypeName to enumTypeNameInProto for clarity
- Use dot notation for nested enums (e.g., ParentMessage.NestedEnum)
- Simplify enum lookup logic to directly use proto names
- Add special handling for testapi.enums package name discrepancy

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@changeset-bot
Copy link

changeset-bot bot commented Jun 8, 2025

⚠️ No Changeset found

Latest commit: 1c0bf9a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@izumin5210 izumin5210 added the tests 🔬 Pull requests that add tests or improve testing system label Jun 8, 2025
izumin5210 and others added 2 commits June 8, 2025 13:31
- Apply consistent parameterized test pattern across all printer tests
- Use declarative test case structure with TestCase and TestSuite types
- Replace repetitive test code with test.each() for better maintainability
- Update all test snapshots to match new test names
- Improve code organization and reduce duplication

This refactoring makes it easier to add new test cases and maintain existing ones
by using a single test implementation that iterates over test configurations.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@izumin5210 izumin5210 merged commit 6eb27de into main Jun 9, 2025
26 of 33 checks passed
@izumin5210 izumin5210 deleted the test/objecttype-printer branch June 9, 2025 01:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests 🔬 Pull requests that add tests or improve testing system

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants