Skip to content

Comments

feat: add integration tests for React generator#224

Open
vikasrao23 wants to merge 2 commits intoopen-feature:mainfrom
vikasrao23:feat/react-only-118
Open

feat: add integration tests for React generator#224
vikasrao23 wants to merge 2 commits intoopen-feature:mainfrom
vikasrao23:feat/react-only-118

Conversation

@vikasrao23
Copy link

Fixes #118

Adds Dagger-based integration tests for the React code generator.

Changes

  • test/integration/cmd/react/run.go - Dagger test runner
  • test/react-integration/package.json - npm project with @openfeature/react-sdk
  • test/react-integration/tsconfig.json - TypeScript configuration
  • test/react-integration/src/test.ts - Hook structure validation
  • Makefile - Added test-integration-react target
  • test/integration/cmd/run.go - Integrated into main runner

Test Coverage

✅ CLI builds from source
✅ React/TypeScript code generation
✅ TypeScript compilation
✅ Hook API structure validation (useFlag, useFlagWithDetails, getKey)
✅ All 5 flag types validated

Note on Testing Approach

React hooks require a React environment (component tree, context providers) to execute. This test validates:

  • ✅ Generated code compiles (TypeScript type checking)
  • ✅ Hook functions exist with correct signatures
  • .getKey() method works (doesn't need React context)

Full runtime testing would require browser/JSDOM environment.

Run It

make test-integration-react

Signed-off-by: vikasrao23 vikasrao23@users.noreply.github.com

Implements integration test coverage for the React generator following
the standardized Dagger-based testing pattern.

Changes:
- test/integration/cmd/react/run.go - Dagger test runner
- test/react-integration/package.json - npm configuration
- test/react-integration/tsconfig.json - TypeScript config
- test/react-integration/src/test.ts - Hook structure validation
- test/integration/cmd/run.go - Added React test to main runner
- Makefile - Added test-integration-react target

The test:
1. Builds the CLI from source
2. Generates React/TypeScript hooks
3. Compiles with TypeScript
4. Validates hook API structure (useFlag, useFlagWithDetails, getKey)
5. Verifies all 5 flag types compile correctly

Note: Full runtime testing of hooks requires React environment (browser/JSDOM).
This test validates compilation and API structure.

Acceptance criteria met:
✅ React generator covered by integration test
✅ Generated code compiles successfully
✅ Test integrated into CI suite
✅ Follows documented integration testing structure

Closes open-feature#118

Signed-off-by: vikasrao23 <vikasrao23@users.noreply.github.com>
@gemini-code-assist
Copy link

Summary of Changes

Hello @vikasrao23, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the testing infrastructure by adding comprehensive integration tests for the React code generator. These tests leverage Dagger to build the CLI, generate React client code, and then validate its compilation and the structural integrity of the generated React hooks. This ensures that any changes to the React generator maintain compatibility and produce functional, well-formed code, improving the reliability of the generated SDKs.

Highlights

  • New React Integration Tests: Introduced Dagger-based integration tests specifically for the React code generator, ensuring the generated code's quality and correctness.
  • Code Generation Validation: The new tests validate that the generated React/TypeScript code compiles successfully, and that the React hooks (useFlag, useFlagWithDetails) and getKey method have the correct structure and signatures.
  • Makefile and Test Runner Updates: The Makefile was updated with a new test-integration-react target, and the main integration test runner (test/integration/cmd/run.go) now includes the execution of these new React tests.
  • Dedicated Test Environment: A dedicated React integration test environment was set up with its own package.json, tsconfig.json, and a validation script (src/test.ts) to simulate a real-world React project.
Changelog
  • Makefile
    • Added test-integration-react target to the help message.
    • Defined a new test-integration-react target to execute the Dagger-based React integration test.
  • test/integration/cmd/react/run.go
    • Added a new Go program to serve as the Dagger test runner for the React generator.
    • Implemented logic to build the CLI, generate React client code, and set up a Node.js container to compile and validate the generated code.
  • test/integration/cmd/run.go
    • Integrated the execution of the new React integration test into the main run.go script, ensuring it runs as part of the complete integration test suite.
  • test/react-integration/package.json
    • Created a new package.json file for the React integration test project.
    • Configured necessary dependencies including @openfeature/react-sdk, react, and TypeScript development tools.
  • test/react-integration/src/test.ts
    • Added a TypeScript file to perform structural validation of the generated React hooks.
    • Included checks for the existence and type of getKey, useFlag, and useFlagWithDetails methods, and verified flag key correctness.
  • test/react-integration/tsconfig.json
    • Added a tsconfig.json file to configure TypeScript compilation for the React integration test project.
    • Specified compiler options for React JSX, module resolution, and output directory.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request introduces integration tests for the React code generator using Dagger. The changes include updates to the Makefile to add a new target for React integration tests, a new Go file (test/integration/cmd/react/run.go) to orchestrate the Dagger-based testing, and new files for the React integration test environment (package.json, tsconfig.json, src/test.ts). The run.go file in test/integration/cmd has also been updated to include the new React integration test in the overall test suite. The new tests validate the compilation of generated React code, the existence of hook functions with correct signatures, and the functionality of the .getKey() method. Overall, the changes are well-structured and add valuable testing coverage.

Comment on lines +40 to +45
WithExec([]string{"apk", "add", "--no-cache", "git"}).
WithDirectory("/src", source).
WithWorkdir("/src").
WithExec([]string{"go", "mod", "tidy"}).
WithExec([]string{"go", "mod", "download"}).
WithExec([]string{"go", "build", "-o", "cli", "./cmd/openfeature"})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

It's good practice to specify the exact version of golangci-lint or go tools in Dagger containers to ensure reproducible builds and avoid unexpected changes due to upstream updates. While golang:1.24-alpine is specific, the go mod tidy and go mod download commands could potentially pull different versions of dependencies over time. Consider pinning specific versions for critical tools or dependencies.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! I've pinned the Go version to golang:1.24.3-alpine for reproducible builds. This ensures the exact same Go toolchain is used across all test runs. ✅

Comment on lines 59 to 65
From("node:20-alpine").
WithWorkdir("/app").
WithDirectory("/app", testFiles).
WithDirectory("/app/src/generated", generatedFiles).
WithExec([]string{"npm", "install"}).
WithExec([]string{"npm", "run", "build"}).
WithExec([]string{"node", "dist/test.js"})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to the Go build environment, consider pinning specific versions for node and npm dependencies in the Dagger container to ensure consistent test results across different runs and environments. For example, instead of node:20-alpine, you might use node:20.x.y-alpine if a specific patch version is desired, and explicitly define npm versions in package.json.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely! I've pinned the Node version to node:20.18.1-alpine to ensure consistent npm and Node.js behavior across test runs. This prevents unexpected changes from upstream updates. ✅

Comment on lines 10 to 12
"@openfeature/react-sdk": "^1.0.0",
"@openfeature/server-sdk": "^1.34.0",
"react": "^18.2.0"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

It's generally recommended to use exact versions for dependencies in package.json for integration tests to ensure reproducibility. Using ^1.0.0 or ^1.34.0 allows for minor and patch updates, which could potentially introduce breaking changes or unexpected behavior in the test environment. Consider using exact versions like "@openfeature/react-sdk": "1.0.0".

Suggested change
"@openfeature/react-sdk": "^1.0.0",
"@openfeature/server-sdk": "^1.34.0",
"react": "^18.2.0"
"@openfeature/react-sdk": "1.0.0",
"@openfeature/server-sdk": "1.34.0",
"react": "18.2.0"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great suggestion! I've switched to exact versions for all dependencies:

  • @openfeature/react-sdk: 1.0.2
  • @openfeature/server-sdk: 1.34.0
  • react: 18.2.0

This prevents unexpected breaking changes or behavior differences in the test environment. ✅

Comment on lines 15 to 17
"@types/node": "^20.0.0",
"@types/react": "^18.2.0",
"typescript": "^5.3.0"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to direct dependencies, using exact versions for devDependencies in package.json helps maintain a stable and reproducible test environment. Consider pinning these to exact versions.

Suggested change
"@types/node": "^20.0.0",
"@types/react": "^18.2.0",
"typescript": "^5.3.0"
"@types/node": "20.0.0",
"@types/react": "18.2.0",
"typescript": "5.3.0"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed! I've pinned all devDependencies to exact versions:

  • @types/node: 20.17.10
  • @types/react: 18.2.79
  • typescript: 5.3.3

This maintains a stable and reproducible test environment across all runs. ✅

console.log('All generated React hooks are properly structured!');
console.log('Generated React code compiles successfully!');
process.exit(0);
} catch (error: any) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The error: any type annotation is too broad. It's better to use a more specific type if possible, or at least unknown and then narrow it down. This improves type safety and makes the code more robust.

Suggested change
} catch (error: any) {
} catch (error: unknown) {

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent point! I've changed it to error: unknown and added proper type narrowing:

} catch (error: unknown) {
  const message = error instanceof Error ? error.message : String(error);
  console.error('Error:', message);
  process.exit(1);
}

This improves type safety and makes the code more robust. ✅

- Pin exact Go version to golang:1.24.3-alpine for reproducible builds
- Pin exact Node version to node:20.18.1-alpine for consistency
- Use exact dependency versions in package.json to prevent unexpected updates
- Replace 'error: any' with 'error: unknown' for better type safety
- Add proper error message handling with type narrowing

All changes improve test reproducibility and code robustness.

Refs: open-feature#118
Signed-off-by: Vikas Rao <mvrao@uci.edu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: integration tests for react generator

2 participants