github.com/kubeshop/testkube@v1.17.23/contrib/executor/cypress/pkg/runner/cypress_test.go (about) 1 package runner 2 3 import ( 4 "context" 5 "fmt" 6 "os" 7 "path/filepath" 8 "testing" 9 10 cp "github.com/otiai10/copy" 11 "github.com/stretchr/testify/assert" 12 13 "github.com/kubeshop/testkube/pkg/api/v1/testkube" 14 "github.com/kubeshop/testkube/pkg/envs" 15 "github.com/kubeshop/testkube/pkg/utils/test" 16 ) 17 18 func TestRun_Integration(t *testing.T) { 19 test.IntegrationTest(t) 20 t.Parallel() 21 22 ctx := context.Background() 23 24 // setup 25 tempDir, err := os.MkdirTemp("", "*") 26 assert.NoErrorf(t, err, "failed to create temp dir: %v", err) 27 defer os.RemoveAll(tempDir) 28 repoDir := filepath.Join(tempDir, "repo") 29 assert.NoError(t, os.Mkdir(repoDir, 0755)) 30 _ = cp.Copy("../../examples", repoDir) 31 32 params := envs.Params{DataDir: tempDir} 33 runner, err := NewCypressRunner(ctx, "npm", params) 34 if err != nil { 35 t.Fail() 36 } 37 38 repoURI := "https://github.com/kubeshop/testkube-executor-cypress.git" 39 result, err := runner.Run( 40 ctx, 41 testkube.Execution{ 42 Content: &testkube.TestContent{ 43 Type_: string(testkube.TestContentTypeGitDir), 44 Repository: &testkube.Repository{ 45 Type_: "git", 46 Uri: repoURI, 47 Branch: "jacek/feature/json-output", 48 Path: "", 49 }, 50 }, 51 Command: []string{ 52 "./node_modules/cypress/bin/cypress", 53 }, 54 Args: []string{ 55 "run", 56 "--reporter", 57 "junit", 58 "--reporter-options", 59 "mochaFile=<reportFile>,toConsole=false", 60 "--project", 61 "<projectPath>", 62 "--env", 63 "<envVars>", 64 }, 65 }) 66 67 assert.NoErrorf(t, err, "Cypress Test Failed: ResultErr: %v, Err: %v ", result.ErrorMessage, err) 68 fmt.Printf("RESULT: %+v\n", result) 69 } 70 71 func TestRunErrors(t *testing.T) { 72 t.Parallel() 73 74 ctx := context.Background() 75 76 t.Run("no RUNNER_DATADIR", func(t *testing.T) { 77 t.Parallel() 78 79 params := envs.Params{DataDir: "/unknown"} 80 runner, err := NewCypressRunner(ctx, "yarn", params) 81 if err != nil { 82 t.Fail() 83 } 84 85 execution := testkube.NewQueuedExecution() 86 execution.Command = []string{ 87 "./node_modules/cypress/bin/cypress", 88 } 89 90 execution.Args = []string{ 91 "run", 92 "--reporter", 93 "junit", 94 "--reporter-options", 95 "mochaFile=<reportFile>,toConsole=false", 96 "--project", 97 "<projectPath>", 98 "--env", 99 "<envVars>", 100 } 101 102 // when 103 _, err = runner.Run(ctx, *execution) 104 105 // then 106 assert.Error(t, err) 107 }) 108 }