The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/pkg/build/e2e-playwright/e2e.go

106 lines
2.5 KiB

package main
import (
"context"
"fmt"
"strings"
"dagger.io/dagger"
)
var (
// Locations in the container to write results to
testResultsDir = "/playwright-test-results"
htmlResultsDir = "/playwright-html-report"
blobResultsDir = "/playwright-blob-report"
)
type RunTestOpts struct {
GrafanaService *dagger.Service
FrontendContainer *dagger.Container
HostSrc *dagger.Directory
Shard string
HTMLReportExportDir string
BlobReportExportDir string
TestResultsExportDir string
}
func RunTest(
ctx context.Context,
d *dagger.Client,
opts RunTestOpts,
) (*dagger.Container, error) {
playwrightCommand := buildPlaywrightCommand(opts)
grafanaHost, err := opts.GrafanaService.Hostname(ctx)
if err != nil {
return nil, err
}
e2eContainer := opts.FrontendContainer.
WithWorkdir("/src").
WithDirectory("/src", opts.HostSrc).
WithMountedCache(".nx", d.CacheVolume("nx-cache")).
WithEnvVariable("CI", "true").
WithEnvVariable("GRAFANA_URL", fmt.Sprintf("http://%s:%d", grafanaHost, grafanaPort)).
WithServiceBinding(grafanaHost, opts.GrafanaService).
WithEnvVariable("bustcache", "1").
WithEnvVariable("PLAYWRIGHT_HTML_OPEN", "never").
WithEnvVariable("PLAYWRIGHT_HTML_OUTPUT_DIR", htmlResultsDir).
WithEnvVariable("PLAYWRIGHT_BLOB_OUTPUT_DIR", blobResultsDir).
WithExec(playwrightCommand, dagger.ContainerWithExecOpts{
Expect: dagger.ReturnTypeAny,
})
if opts.TestResultsExportDir != "" {
_, err := e2eContainer.Directory(testResultsDir).Export(ctx, opts.TestResultsExportDir)
if err != nil {
return nil, err
}
}
if opts.HTMLReportExportDir != "" {
_, err := e2eContainer.Directory(htmlResultsDir).Export(ctx, opts.HTMLReportExportDir)
if err != nil {
return nil, err
}
}
if opts.BlobReportExportDir != "" {
_, err := e2eContainer.Directory(blobResultsDir).Export(ctx, opts.BlobReportExportDir)
if err != nil {
return nil, err
}
}
return e2eContainer, nil
}
func buildPlaywrightCommand(opts RunTestOpts) []string {
playwrightReporters := []string{
"dot", // minimal output in shards
}
if opts.HTMLReportExportDir != "" {
playwrightReporters = append(playwrightReporters, "html")
}
if opts.BlobReportExportDir != "" {
playwrightReporters = append(playwrightReporters, "blob")
}
playwrightCommand := []string{
"yarn",
"e2e:playwright",
"--reporter",
strings.Join(playwrightReporters, ","),
"--output",
testResultsDir,
}
if opts.Shard != "" {
playwrightCommand = append(playwrightCommand, "--shard", opts.Shard)
}
return playwrightCommand
}