Skip to content

Comments

feat: add integration tests for Java, NestJS, and React generators#221

Closed
vikasrao23 wants to merge 1 commit intoopen-feature:mainfrom
vikasrao23:feat/nestjs-react-integration-tests
Closed

feat: add integration tests for Java, NestJS, and React generators#221
vikasrao23 wants to merge 1 commit intoopen-feature:mainfrom
vikasrao23:feat/nestjs-react-integration-tests

Conversation

@vikasrao23
Copy link

Summary

Fixes #115, #116, #118

Implements comprehensive integration test coverage for three code generators (Java, NestJS, React) following the standardized Dagger-based testing pattern.


Changes by Generator

🟠 Java (#115)

New Files:

  • test/integration/cmd/java/run.go - Dagger test runner
  • test/java-integration/pom.xml - Maven project configuration
  • test/java-integration/src/main/java/dev/openfeature/Main.java - Test program

Test Coverage:

  • ✅ Compiles generated Java code with Maven
  • ✅ Tests all flag types (boolean, string, int, double, object)
  • ✅ Validates .value() and .valueWithDetails() methods
  • ✅ Validates .getKey() method
  • ✅ Uses OpenFeature Java SDK v1.14.0

🟢 NestJS (#116)

New Files:

  • test/integration/cmd/nestjs/run.go - Dagger test runner
  • test/nestjs-integration/package.json - npm configuration
  • test/nestjs-integration/tsconfig.json - TypeScript config
  • test/nestjs-integration/src/main.ts - NestJS application test

Test Coverage:

  • ✅ Compiles generated TypeScript code
  • ✅ Tests NestJS module integration with OpenFeature
  • ✅ Validates all flag types using @openfeature/nestjs-sdk
  • ✅ Tests both .value() and .valueWithDetails() methods
  • ✅ Validates .getKey() method

⚛️ React (#118)

New Files:

  • 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 Coverage:

  • ✅ Compiles generated React hooks (TypeScript)
  • ✅ Validates hook API (.useFlag(), .useFlagWithDetails(), .getKey())
  • ✅ Ensures generated code has correct structure
  • ✅ All 5 flag types validated

🔧 Shared Updates

  • test/integration/cmd/run.go - Added Java, NestJS, and React to main test runner
  • Makefile - Added individual targets:
    • make test-integration-java
    • make test-integration-nestjs
    • make test-integration-react

How It Works

Each test follows the same Dagger-based pattern:

  1. Build - Compile OpenFeature CLI from source (Go container)
  2. Generate - Run cli generate <language> with sample manifest
  3. Compile - Build generated code in language-specific container
  4. Execute/Validate - Run tests to verify functionality
  5. Report - Exit with success or failure

Benefits

  • Reproducible - Identical behavior locally and in CI
  • Isolated - No local language dependencies required
  • Parallel - Tests can run concurrently
  • Self-contained - Everything runs in containers

Running the Tests

Run individual tests:

make test-integration-java
make test-integration-nestjs
make test-integration-react

Run all integration tests:

make test-integration

Example Output

Java:

enableFeatureA: false
Discount Percentage: 0.15
greetingMessage: Hello there!
usernameMaxLength: 50
Generated Java code compiles successfully!

NestJS:

enableFeatureA: false
Discount Percentage: 0.15
greetingMessage: Hello there!
Generated NestJS code compiles successfully!

React:

EnableFeatureA flag key: enableFeatureA
DiscountPercentage flag key: discountPercentage
All generated React hooks are properly structured!
Generated React code compiles successfully!

Acceptance Criteria

Java (#115):

  • ✅ Java generator covered by integration test
  • ✅ Generated code compiles and executes
  • ✅ Integrated into CI suite
  • ✅ Follows documented testing structure

NestJS (#116):

  • ✅ NestJS generator covered by integration test
  • ✅ Generated code compiles and executes
  • ✅ Integrated into CI suite
  • ✅ Follows documented testing structure

React (#118):

  • ✅ React generator covered by integration test
  • ✅ Generated code compiles and validates
  • ✅ Integrated into CI suite
  • ✅ Follows documented testing structure

Additional Notes

  • Java: Uses Maven (most common build tool), Java 11+ compatible
  • NestJS: Uses npm, Node 20, TypeScript 5.3
  • React: Hook structure validation (full React environment testing would require browser/JSDOM)
  • No local dependencies needed - all tests run in containers via Dagger
  • Fast feedback - Compilation errors caught immediately

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

Implements integration test coverage for Java, NestJS, and React generators
following the standardized Dagger-based testing pattern.

Changes:

**Java (open-feature#115):**
- test/integration/cmd/java/run.go - Dagger test runner
- test/java-integration/pom.xml - Maven configuration
- test/java-integration/src/main/java/dev/openfeature/Main.java - Test program
- Validates all flag types with OpenFeature Java SDK

**NestJS (open-feature#116):**
- test/integration/cmd/nestjs/run.go - Dagger test runner
- test/nestjs-integration/package.json - npm configuration
- test/nestjs-integration/tsconfig.json - TypeScript config
- test/nestjs-integration/src/main.ts - NestJS test application
- Tests generated code with @openfeature/nestjs-sdk

**React (open-feature#118):**
- 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
- Validates generated hooks compile and have correct API

**Shared:**
- test/integration/cmd/run.go - Added all three tests to main runner
- Makefile - Added test-integration-java, test-integration-nestjs, test-integration-react targets

All tests:
1. Build the CLI from source
2. Generate language-specific code
3. Compile and validate generated code
4. Run as part of CI suite via test-integration

Acceptance criteria met:
✅ Java, NestJS, React generators covered by integration tests
✅ Generated code compiles and passes execution/validation
✅ Tests integrated into CI suite
✅ Follow documented integration testing structure

Closes open-feature#115
Closes open-feature#116
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 reliability of the OpenFeature CLI by adding robust integration tests for its Java, NestJS, and React code generators. By leveraging Dagger, these tests provide a consistent and isolated environment to validate the generated code's functionality, ensuring it compiles correctly and accurately evaluates feature flags across various types and methods. This improves developer confidence and streamlines the development workflow for future generator enhancements.

Highlights

  • New Integration Tests: Introduced comprehensive integration tests for Java, NestJS, and React code generators to ensure their correctness and reliability.
  • Dagger-based Testing Pattern: Implemented a standardized Dagger-based testing pattern for all new integration tests, ensuring reproducible, isolated, and parallel test execution within containers.
  • Extensive Test Coverage: Verified generated code compilation, accurate flag evaluation for all types (boolean, string, int, double, object), and proper functionality of .value(), .valueWithDetails(), and .getKey() methods for each language.
  • Makefile Updates: Updated the Makefile with new targets (test-integration-java, test-integration-nestjs, test-integration-react) for running individual language-specific integration tests, and integrated them into the main test-integration target.
Changelog
  • Makefile
    • Added test-integration-java, test-integration-nestjs, and test-integration-react targets.
    • Updated help message to include new integration test targets.
  • test/integration/cmd/java/run.go
    • Added a Dagger-based Go program to orchestrate Java integration tests.
  • test/integration/cmd/nestjs/run.go
    • Added a Dagger-based Go program to orchestrate NestJS integration tests.
  • test/integration/cmd/react/run.go
    • Added a Dagger-based Go program to orchestrate React integration tests.
  • test/integration/cmd/run.go
    • Updated the main integration test runner to execute Java, NestJS, and React tests.
  • test/java-integration/pom.xml
    • Added Maven project configuration for the Java integration test.
  • test/java-integration/src/main/java/dev/openfeature/Main.java
    • Added a Java application to test generated code with an in-memory OpenFeature provider.
  • test/nestjs-integration/package.json
    • Added npm package configuration for the NestJS integration test.
  • test/nestjs-integration/src/main.ts
    • Added a NestJS application to test generated code with an in-memory OpenFeature provider.
  • test/nestjs-integration/tsconfig.json
    • Added TypeScript configuration for the NestJS integration test.
  • test/react-integration/package.json
    • Added npm package configuration for the React integration test.
  • test/react-integration/src/test.ts
    • Added a TypeScript test file to validate the structure and API of generated React hooks.
  • test/react-integration/tsconfig.json
    • Added TypeScript configuration for the React integration test.
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

This pull request adds comprehensive integration tests for the Java, NestJS, and React code generators, following the existing Dagger-based testing pattern. The changes are well-structured and the tests cover the core functionality of the generated code. I have a couple of suggestions to improve maintainability and performance by refactoring duplicated code and enabling parallel test execution. Overall, this is a great addition for ensuring the quality of the code generators.

Comment on lines +38 to +45
cli := client.Container().
From("golang:1.24-alpine").
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

There's a significant amount of duplicated code for building the CLI across the new integration test runners (java/run.go, nestjs/run.go, react/run.go). This logic is identical in each file.

To improve maintainability and reduce redundancy, consider refactoring this into a shared helper function within the integration package.

For example, you could create a BuildCLI function in test/integration/integration.go:

// in test/integration/integration.go
func BuildCLI(client *dagger.Client, source *dagger.Directory) *dagger.Container {
    return client.Container().
        From("golang:1.24-alpine").
        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"})
}

Then, you could call it from each test runner like this:

cli := integration.BuildCLI(client, source)

Comment on lines +48 to +73
// Run the Java integration test
javaCmd := exec.Command("go", "run", "github.com/open-feature/cli/test/integration/cmd/java")
javaCmd.Stdout = os.Stdout
javaCmd.Stderr = os.Stderr
if err := javaCmd.Run(); err != nil {
fmt.Fprintf(os.Stderr, "Error running Java integration test: %v\n", err)
os.Exit(1)
}

// Run the NestJS integration test
nestjsCmd := exec.Command("go", "run", "github.com/open-feature/cli/test/integration/cmd/nestjs")
nestjsCmd.Stdout = os.Stdout
nestjsCmd.Stderr = os.Stderr
if err := nestjsCmd.Run(); err != nil {
fmt.Fprintf(os.Stderr, "Error running NestJS integration test: %v\n", err)
os.Exit(1)
}

// Run the React integration test
reactCmd := exec.Command("go", "run", "github.com/open-feature/cli/test/integration/cmd/react")
reactCmd.Stdout = os.Stdout
reactCmd.Stderr = os.Stderr
if err := reactCmd.Run(); err != nil {
fmt.Fprintf(os.Stderr, "Error running React integration test: %v\n", err)
os.Exit(1)
}

Choose a reason for hiding this comment

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

medium

The main integration test runner executes each test sequentially. This can be inefficient, especially as more tests are added. The PR description also mentions that tests can run in parallel. To improve performance and align with that benefit, consider refactoring this to run the tests concurrently using goroutines and a sync.WaitGroup. This would also reduce code duplication.

Here's a conceptual example of how you could structure it:

func main() {
    fmt.Println("=== Running all integration tests ===")

    tests := map[string]string{
        "C#":      "github.com/open-feature/cli/test/integration/cmd/csharp",
        "Go":      "github.com/open-feature/cli/test/integration/cmd/go",
        "NodeJS":  "github.com/open-feature/cli/test/integration/cmd/nodejs",
        "Angular": "github.com/open-feature/cli/test/integration/cmd/angular",
        "Java":    "github.com/open-feature/cli/test/integration/cmd/java",
        "NestJS":  "github.com/open-feature/cli/test/integration/cmd/nestjs",
        "React":   "github.com/open-feature/cli/test/integration/cmd/react",
    }

    var wg sync.WaitGroup
    errChan := make(chan error, len(tests))

    for name, path := range tests {
        wg.Add(1)
        go func(name, path string) {
            defer wg.Done()
            cmd := exec.Command("go", "run", path)
            cmd.Stdout = os.Stdout
            cmd.Stderr = os.Stderr
            if err := cmd.Run(); err != nil {
                errChan <- fmt.Errorf("error running %s integration test: %w", name, err)
            }
        }(name, path)
    }

    wg.Wait()
    close(errChan)

    hasErrors := false
    for err := range errChan {
        fmt.Fprintln(os.Stderr, err)
        hasErrors = true
    }

    if hasErrors {
        os.Exit(1)
    }

    fmt.Println("=== All integration tests passed successfully ===")
}

@vikasrao23
Copy link
Author

Closing this combined PR in favor of three separate, focused PRs:

This makes reviewing and merging easier!

@vikasrao23 vikasrao23 closed this Feb 21, 2026
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 java generator

1 participant