github.com/saucelabs/saucectl@v0.175.1/internal/cypress/v1alpha/native.go (about)

     1  package v1alpha
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  	"os"
     7  	"path/filepath"
     8  
     9  	"github.com/saucelabs/saucectl/internal/msg"
    10  )
    11  
    12  // Config represents the cypress.json native configuration file.
    13  type Config struct {
    14  	// Path is the location of the config file itself.
    15  	Path string `yaml:"-" json:"-"`
    16  
    17  	FixturesFolder    interface{} `json:"fixturesFolder,omitempty"`
    18  	IntegrationFolder string      `json:"integrationFolder,omitempty"`
    19  	PluginsFile       string      `json:"pluginsFile,omitempty"`
    20  	SupportFile       string      `json:"supportFile,omitempty"`
    21  }
    22  
    23  // AbsIntegrationFolder returns the absolute path to Config.IntegrationFolder.
    24  func (c Config) AbsIntegrationFolder() string {
    25  	return filepath.Join(filepath.Join(filepath.Dir(c.Path), c.IntegrationFolder))
    26  }
    27  
    28  // configFromFile loads cypress configuration into Config structure.
    29  func configFromFile(fileName string) (Config, error) {
    30  	var c Config
    31  
    32  	fd, err := os.Open(fileName)
    33  	if err != nil {
    34  		return c, fmt.Errorf(msg.UnableToLocateCypressCfg, fileName)
    35  	}
    36  	err = json.NewDecoder(fd).Decode(&c)
    37  	c.Path = fileName
    38  	return c, err
    39  }