nodejs_feature_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package integrationtests_test
  2. import (
  3. "strings"
  4. "testing"
  5. "github.com/langgenius/dify-sandbox/internal/core/runner/types"
  6. "github.com/langgenius/dify-sandbox/internal/service"
  7. )
  8. func TestNodejsBase64(t *testing.T) {
  9. // Test case for base64
  10. resp := service.RunNodeJsCode(`
  11. const base64 = Buffer.from("hello world").toString("base64");
  12. console.log(Buffer.from(base64, "base64").toString());
  13. `, "", &types.RunnerOptions{
  14. EnableNetwork: true,
  15. })
  16. if resp.Code != 0 {
  17. t.Error(resp)
  18. }
  19. if !strings.Contains(resp.Data.(*service.RunCodeResponse).Stdout, "hello world") {
  20. t.Errorf("unexpected output: %s\n", resp.Data.(*service.RunCodeResponse).Stdout)
  21. }
  22. if resp.Data.(*service.RunCodeResponse).Stderr != "" {
  23. t.Errorf("unexpected error: %s\n", resp.Data.(*service.RunCodeResponse).Stderr)
  24. }
  25. }
  26. func TestNodejsJSON(t *testing.T) {
  27. // Test case for json
  28. resp := service.RunNodeJsCode(`
  29. console.log(JSON.stringify({"hello": "world"}));
  30. `, "", &types.RunnerOptions{
  31. EnableNetwork: true,
  32. })
  33. if resp.Code != 0 {
  34. t.Error(resp)
  35. }
  36. if !strings.Contains(resp.Data.(*service.RunCodeResponse).Stdout, `{"hello":"world"}`) {
  37. t.Errorf("unexpected output: %s\n", resp.Data.(*service.RunCodeResponse).Stdout)
  38. }
  39. if resp.Data.(*service.RunCodeResponse).Stderr != "" {
  40. t.Errorf("unexpected error: %s\n", resp.Data.(*service.RunCodeResponse).Stderr)
  41. }
  42. }