github.com/saucelabs/saucectl@v0.175.1/internal/cmd/ini/cypress.go (about) 1 package ini 2 3 import ( 4 // imports embed to load .sauceignore 5 _ "embed" 6 "fmt" 7 "os" 8 "strconv" 9 "strings" 10 11 "github.com/rs/zerolog/log" 12 cmds "github.com/saucelabs/saucectl/internal/cmd" 13 "github.com/saucelabs/saucectl/internal/config" 14 "github.com/saucelabs/saucectl/internal/cypress" 15 v1 "github.com/saucelabs/saucectl/internal/cypress/v1" 16 "github.com/saucelabs/saucectl/internal/cypress/v1alpha" 17 "github.com/saucelabs/saucectl/internal/segment" 18 "github.com/saucelabs/saucectl/internal/usage" 19 "github.com/spf13/cobra" 20 "golang.org/x/text/cases" 21 "golang.org/x/text/language" 22 ) 23 24 func CypressCmd() *cobra.Command { 25 cfg := &initConfig{ 26 frameworkName: cypress.Kind, 27 } 28 29 cmd := &cobra.Command{ 30 Use: "cypress", 31 Short: "Bootstrap a Cypress project.", 32 SilenceUsage: true, 33 Run: func(cmd *cobra.Command, args []string) { 34 tracker := segment.DefaultTracker 35 36 go func() { 37 tracker.Collect( 38 cases.Title(language.English).String(cmds.FullName(cmd)), 39 usage.Properties{}.SetFlags(cmd.Flags()), 40 ) 41 _ = tracker.Close() 42 }() 43 44 err := Run(cmd, cfg) 45 if err != nil { 46 log.Err(err).Msg("failed to execute init command") 47 os.Exit(1) 48 } 49 }, 50 } 51 52 cmd.Flags().StringVar(&cfg.frameworkVersion, "version", "", "Cypress version.") 53 cmd.Flags().StringVar(&cfg.cypressConfigFile, "cypress-config", "", "Path to the cypress config file.") 54 cmd.Flags().StringVar(&cfg.platformName, "platform", "", "OS name and version, such as 'Windows 11' or 'macOS 13'.") 55 cmd.Flags().StringVar(&cfg.browserName, "browser", "", "Browser name.") 56 cmd.Flags().StringVar(&cfg.artifactWhenStr, "artifacts-when", "fail", "When to download artifacts.") 57 58 return cmd 59 } 60 61 func configureCypress(cfg *initConfig) interface{} { 62 versions := strings.Split(cfg.frameworkVersion, ".") 63 version, err := strconv.Atoi(versions[0]) 64 if err != nil { 65 log.Err(err).Msg("failed to parse framework version") 66 } 67 if version < 10 { 68 return v1alpha.Project{ 69 TypeDef: config.TypeDef{ 70 APIVersion: v1alpha.APIVersion, 71 Kind: cypress.Kind, 72 }, 73 Sauce: config.SauceConfig{ 74 Region: cfg.region, 75 Sauceignore: ".sauceignore", 76 Concurrency: cfg.concurrency, 77 }, 78 RootDir: ".", 79 Cypress: v1alpha.Cypress{ 80 Version: cfg.frameworkVersion, 81 ConfigFile: cfg.cypressConfigFile, 82 }, 83 Suites: []v1alpha.Suite{ 84 { 85 Name: fmt.Sprintf("cypress - %s - %s", cfg.platformName, cfg.browserName), 86 PlatformName: cfg.platformName, 87 Browser: cfg.browserName, 88 Config: v1alpha.SuiteConfig{ 89 TestFiles: []string{"**/*.*"}, 90 }, 91 }, 92 }, 93 Artifacts: config.Artifacts{ 94 Download: config.ArtifactDownload{ 95 When: cfg.artifactWhen, 96 Directory: "./artifacts", 97 Match: []string{"*"}, 98 }, 99 }, 100 } 101 } 102 103 return v1.Project{ 104 TypeDef: config.TypeDef{ 105 APIVersion: v1.APIVersion, 106 Kind: cypress.Kind, 107 }, 108 Sauce: config.SauceConfig{ 109 Region: cfg.region, 110 Sauceignore: ".sauceignore", 111 Concurrency: cfg.concurrency, 112 }, 113 RootDir: ".", 114 Cypress: v1.Cypress{ 115 Version: cfg.frameworkVersion, 116 ConfigFile: cfg.cypressConfigFile, 117 }, 118 Suites: []v1.Suite{ 119 { 120 Name: fmt.Sprintf("cypress - %s - %s", cfg.platformName, cfg.browserName), 121 PlatformName: cfg.platformName, 122 Browser: cfg.browserName, 123 Config: v1.SuiteConfig{ 124 TestingType: "e2e", 125 SpecPattern: []string{"**/*.*"}, 126 }, 127 }, 128 }, 129 Artifacts: config.Artifacts{ 130 Download: config.ArtifactDownload{ 131 When: cfg.artifactWhen, 132 Directory: "./artifacts", 133 Match: []string{"*"}, 134 }, 135 }, 136 } 137 } 138 139 //go:embed sauceignore/cypress.sauceignore 140 var sauceignoreCypress string