Skip to content

Commit b867485

Browse files
feat: integration tests for nodejs generator (#140)
* feat: add renovate.json file #122 Signed-off-by: Adityasinghvats <[email protected]> * chore: remove packageRules from renovate.json Signed-off-by: Adityasinghvats <[email protected]> * feat(nodejs-integration): add Node.js integration test and related files Signed-off-by: Adityasinghvats <[email protected]> * feat: integration tests for nodejs generator (#117) Signed-off-by: Adityasinghvats <[email protected]> * fix: fix whitespace issue in Makefile Signed-off-by: Adityasinghvats <[email protected]> * fix: fix whitespace issue in Makefile Signed-off-by: Adityasinghvats <[email protected]> * fix: fix whitespaces in Makefile Signed-off-by: Adityasinghvats <[email protected]> --------- Signed-off-by: Adityasinghvats <[email protected]>
1 parent 6145c2e commit b867485

7 files changed

Lines changed: 815 additions & 1 deletion

File tree

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,9 @@ dist
2828
# openfeature cli config
2929
.openfeature.yaml
3030

31-
.idea/
31+
.idea/
32+
33+
node_modules/
34+
npm-debug.log*
35+
generated/
36+
*.log

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ test-integration-go:
1515
@echo "Running Go integration test with Dagger..."
1616
@go run ./test/integration/cmd/go/run.go
1717

18+
.PHONY: test-integration-nodejs
19+
test-integration-nodejs:
20+
@echo "Running NodeJS integration test with Dagger..."
21+
@go run ./test/integration/cmd/nodejs/run.go
22+
1823
.PHONY: test-integration
1924
test-integration:
2025
@echo "Running all integration tests with Dagger..."

test/integration/cmd/nodejs/run.go

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"dagger.io/dagger"
6+
"fmt"
7+
"github.com/open-feature/cli/test/integration"
8+
"os"
9+
"path/filepath"
10+
)
11+
12+
type Test struct {
13+
ProjectDir string
14+
TestDir string
15+
}
16+
17+
func New(projectDir, testDir string) *Test {
18+
return &Test{
19+
ProjectDir: projectDir,
20+
TestDir: testDir,
21+
}
22+
}
23+
func (t *Test) Run(ctx context.Context, client *dagger.Client) (*dagger.Container, error) {
24+
source := client.Host().Directory(t.ProjectDir)
25+
testFiles := client.Host().Directory(t.TestDir, dagger.HostDirectoryOpts{
26+
Include: []string{"package.json", "test.ts"},
27+
})
28+
29+
cli := client.Container().
30+
From("golang:1.24-alpine").
31+
WithDirectory("/src", source).
32+
WithWorkdir("/src").
33+
WithExec([]string{"go", "build", "-o", "cli", "./cmd/openfeature"})
34+
35+
generated := cli.WithExec([]string{
36+
"./cli", "generate", "nodejs",
37+
"--manifest=/src/sample/sample_manifest.json",
38+
"--output=/tmp/generated",
39+
})
40+
41+
generatedFiles := generated.Directory("/tmp/generated")
42+
43+
nodeContainer := client.Container().
44+
From("node:22-alpine").
45+
WithExec([]string{"npm", "install", "-g", "typescript"}).
46+
WithDirectory("/app/generated", generatedFiles).
47+
WithDirectory("/app", testFiles).
48+
WithWorkdir("/app").
49+
WithExec([]string{"npm", "install"}).
50+
WithExec([]string{"npm", "test"})
51+
52+
return nodeContainer, nil
53+
}
54+
func (t *Test) Name() string {
55+
return "nodejs"
56+
}
57+
func main() {
58+
ctx := context.Background()
59+
60+
projectDir, err := filepath.Abs(os.Getenv("PWD"))
61+
if err != nil {
62+
fmt.Fprintf(os.Stderr, "Failed to get project dir: %v\n", err)
63+
os.Exit(1)
64+
}
65+
66+
testDir, err := filepath.Abs(filepath.Join(projectDir, "test/nodejs-integration"))
67+
if err != nil {
68+
fmt.Fprintf(os.Stderr, "Failed to get test dir: %v\n", err)
69+
os.Exit(1)
70+
}
71+
test := New(projectDir, testDir)
72+
73+
if err := integration.RunTest(ctx, test); err != nil {
74+
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
75+
os.Exit(1)
76+
}
77+
}

test/integration/cmd/run.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ func main() {
2828
fmt.Fprintf(os.Stderr, "Error running Go integration test: %v\n", err)
2929
os.Exit(1)
3030
}
31+
//Run the nodejs test
32+
nodeCmd := exec.Command("go", "run", "github.com/open-feature/cli/test/integration/cmd/nodejs")
33+
nodeCmd.Stdout = os.Stdout
34+
nodeCmd.Stderr = os.Stderr
35+
if err := nodeCmd.Run(); err != nil {
36+
fmt.Fprintf(os.Stderr, "Error running nodejs integration test: %v\n", err)
37+
os.Exit(1)
38+
}
3139

3240
// Add more tests here as they are available
3341

0 commit comments

Comments
 (0)