Skip to content

Commit

Permalink
playwright: Remove docker execution (#756)
Browse files Browse the repository at this point in the history
  • Loading branch information
FriggaHel authored Apr 25, 2023
1 parent f1f5fa1 commit 294447c
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 213 deletions.
10 changes: 0 additions & 10 deletions .sauce/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,10 @@ sauce:
build: "$BUILD_ID"
defaults:
timeout: 5m
docker:
fileTransfer: mount
rootDir: tests/e2e/playwright/
playwright:
version: 1.31.1
suites:
- name: "firefox test in docker"
mode: docker
testMatch: ['.*.js']
env:
hello: world
params:
browserName: "firefox"

- name: "chromium test in sauce"
platformName: "Windows 10"
testMatch: ['.*.js']
Expand Down
4 changes: 0 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ coverage:
go tool cover -func=coverage.out
@rm coverage.out

#playwright-ci: @ Run tests against playwright in CI mode
playwright-ci: build-linux
docker run --name playwright-ci -e "CI=true" -v $(shell pwd):/home/gitty/ -w "/home/gitty" --rm saucelabs/stt-playwright-node:latest "/home/gitty/saucectl" run -c ./.sauce/playwright.yml --verbose

#testcafe-ci: @ Run tests against testcafe in CI mode
testcafe-ci: build-linux
docker run --name testcafe-ci -e "CI=true" -v $(shell pwd):/home/gitty/ -w "/home/gitty" --rm saucelabs/stt-testcafe-node:latest "/home/gitty/saucectl" run -c ./.sauce/testcafe.yml --verbose
Expand Down
77 changes: 34 additions & 43 deletions api/saucectl.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1250,33 +1250,6 @@
{
"$ref": "#/allOf/0/then/allOf/0"
},
{
"$schema": "https://json-schema.org/draft-07/schema",
"title": "saucectl docker specific schema",
"description": "Subschema for docker specific settings",
"type": "object",
"properties": {
"docker": {
"description": "Properties specific to docker.",
"type": "object",
"properties": {
"fileTransfer": {
"description": "Control how files are made available to the docker image.",
"enum": [
"copy",
"mount"
]
},
"image": {
"description": "Override which docker image to use (in case you have a custom image).",
"type": "string"
}
},
"additionalProperties": false
}
},
"additionalProperties": true
},
{
"$ref": "#/allOf/0/then/allOf/1"
},
Expand All @@ -1301,13 +1274,6 @@
"description": "Settings that are applied onto every suite by default, if no value is set on a suite explicitly.",
"type": "object",
"properties": {
"mode": {
"description": "Instructs saucectl run tests remotely through Sauce Labs (sauce) or locally on docker.",
"enum": [
"docker",
"sauce"
]
},
"timeout": {
"$ref": "#/allOf/9/then/definitions/suite/properties/timeout"
}
Expand Down Expand Up @@ -1361,9 +1327,6 @@
"description": "The name of the test suite, which will be reflected in the test results in Sauce Labs.",
"type": "string"
},
"mode": {
"$ref": "#/allOf/3/then/properties/defaults/properties/mode"
},
"playwrightVersion": {
"$ref": "#/allOf/8/then/properties/playwright/properties/version"
},
Expand Down Expand Up @@ -1617,7 +1580,31 @@
"$ref": "#/allOf/0/then/allOf/0"
},
{
"$ref": "#/allOf/3/then/allOf/1"
"$schema": "https://json-schema.org/draft-07/schema",
"title": "saucectl docker specific schema",
"description": "Subschema for docker specific settings",
"type": "object",
"properties": {
"docker": {
"description": "Properties specific to docker.",
"type": "object",
"properties": {
"fileTransfer": {
"description": "Control how files are made available to the docker image.",
"enum": [
"copy",
"mount"
]
},
"image": {
"description": "Override which docker image to use (in case you have a custom image).",
"type": "string"
}
},
"additionalProperties": false
}
},
"additionalProperties": true
},
{
"$ref": "#/allOf/0/then/allOf/1"
Expand All @@ -1644,7 +1631,11 @@
"type": "object",
"properties": {
"mode": {
"$ref": "#/allOf/3/then/properties/defaults/properties/mode"
"description": "Instructs saucectl run tests remotely through Sauce Labs (sauce) or locally on docker.",
"enum": [
"docker",
"sauce"
]
},
"timeout": {
"$ref": "#/allOf/9/then/definitions/suite/properties/timeout"
Expand Down Expand Up @@ -1747,7 +1738,7 @@
"$ref": "#/allOf/0/then/properties/env"
},
"mode": {
"$ref": "#/allOf/3/then/properties/defaults/properties/mode"
"$ref": "#/allOf/5/then/properties/defaults/properties/mode"
},
"shard": {
"description": "When sharding is configured, saucectl automatically splits the tests (e.g. by spec or concurrency) so that they can easily run in parallel.",
Expand Down Expand Up @@ -2283,7 +2274,7 @@
"$ref": "#/allOf/0/then/allOf/0"
},
{
"$ref": "#/allOf/3/then/allOf/1"
"$ref": "#/allOf/5/then/allOf/1"
},
{
"$ref": "#/allOf/0/then/allOf/1"
Expand All @@ -2310,7 +2301,7 @@
"type": "object",
"properties": {
"mode": {
"$ref": "#/allOf/3/then/properties/defaults/properties/mode"
"$ref": "#/allOf/5/then/properties/defaults/properties/mode"
},
"timeout": {
"$ref": "#/allOf/9/then/definitions/suite/properties/timeout"
Expand Down Expand Up @@ -2423,7 +2414,7 @@
]
},
"mode": {
"$ref": "#/allOf/3/then/properties/defaults/properties/mode"
"$ref": "#/allOf/5/then/properties/defaults/properties/mode"
},
"shard": {
"description": "When sharding is configured, saucectl automatically splits the tests (e.g. by spec or concurrency) so that they can easily run in parallel.",
Expand Down
9 changes: 0 additions & 9 deletions api/v1alpha/framework/playwright.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
{
"$ref": "../subschema/artifacts.schema.json"
},
{
"$ref": "../subschema/docker.schema.json"
},
{
"$ref": "../subschema/npm.schema.json"
},
Expand All @@ -34,9 +31,6 @@
"description": "Settings that are applied onto every suite by default, if no value is set on a suite explicitly.",
"type": "object",
"properties": {
"mode": {
"$ref": "../subschema/common.schema.json#/definitions/mode"
},
"timeout": {
"$ref": "../subschema/common.schema.json#/definitions/timeout"
}
Expand Down Expand Up @@ -90,9 +84,6 @@
"description": "The name of the test suite, which will be reflected in the test results in Sauce Labs.",
"type": "string"
},
"mode": {
"$ref": "../subschema/common.schema.json#/definitions/mode"
},
"playwrightVersion": {
"$ref": "../subschema/common.schema.json#/definitions/version"
},
Expand Down
34 changes: 1 addition & 33 deletions internal/cmd/run/playwright.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/saucelabs/saucectl/internal/ci"
"github.com/saucelabs/saucectl/internal/config"
"github.com/saucelabs/saucectl/internal/credentials"
"github.com/saucelabs/saucectl/internal/docker"
"github.com/saucelabs/saucectl/internal/flags"
"github.com/saucelabs/saucectl/internal/framework"
"github.com/saucelabs/saucectl/internal/msg"
Expand Down Expand Up @@ -150,46 +149,15 @@ func runPlaywright(cmd *cobra.Command, isCLIDriven bool) (int, error) {
go func() {
props := usage.Properties{}
props.SetFramework("playwright").SetFVersion(p.Playwright.Version).SetFlags(cmd.Flags()).SetSauceConfig(p.Sauce).
SetArtifacts(p.Artifacts).SetDocker(p.Docker).SetNPM(p.Npm).SetNumSuites(len(p.Suites)).SetJobs(captor.Default.TestResults).
SetArtifacts(p.Artifacts).SetNPM(p.Npm).SetNumSuites(len(p.Suites)).SetJobs(captor.Default.TestResults).
SetSlack(p.Notifications.Slack).SetSharding(playwright.IsSharded(p.Suites)).SetLaunchOrder(p.Sauce.LaunchOrder)
tracker.Collect(cases.Title(language.English).String(cmds.FullName(cmd)), props)
_ = tracker.Close()
}()

cleanupArtifacts(p.Artifacts)

dockerProject, sauceProject := playwright.SplitSuites(p)
if len(dockerProject.Suites) != 0 {
exitCode, err := runPlaywrightInDocker(dockerProject)
if err != nil || exitCode != 0 {
return exitCode, err
}
}
if len(sauceProject.Suites) != 0 {
return runPlaywrightInSauce(sauceProject, regio)
}

return 0, nil
}

func runPlaywrightInDocker(p playwright.Project) (int, error) {
log.Info().Msg("Running Playwright in Docker")
printTestEnv("docker")

cd, err := docker.NewPlaywright(p, &testcompClient, &testcompClient, &restoClient, &restoClient, createReporters(p.Reporters, p.Notifications, p.Sauce.Metadata, &testcompClient, &restoClient,
"playwright", "docker"))
if err != nil {
return 1, err
}

p.Npm.Packages = cleanPlaywrightPackages(p.Npm, p.Playwright.Version)
return cd.RunProject()
}

func runPlaywrightInSauce(p playwright.Project, regio region.Region) (int, error) {
log.Info().Msg("Running Playwright in Sauce Labs")
printTestEnv("sauce")

r := saucecloud.PlaywrightRunner{
Project: p,
CloudRunner: saucecloud.CloudRunner{
Expand Down
88 changes: 0 additions & 88 deletions internal/docker/playwright.go

This file was deleted.

26 changes: 0 additions & 26 deletions internal/playwright/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ type Project struct {
Suite Suite `yaml:"suite,omitempty" json:"-"`
Suites []Suite `yaml:"suites,omitempty" json:"suites"`
BeforeExec []string `yaml:"beforeExec,omitempty" json:"beforeExec"`
Docker config.Docker `yaml:"docker,omitempty" json:"docker"`
Npm config.Npm `yaml:"npm,omitempty" json:"npm"`
RootDir string `yaml:"rootDir,omitempty" json:"rootDir"`
RunnerVersion string `yaml:"runnerVersion,omitempty" json:"runnerVersion"`
Expand Down Expand Up @@ -128,11 +127,6 @@ func SetDefaults(p *Project) {
p.Sauce.Concurrency = 2
}

// Set default docker file transfer to mount
if p.Docker.FileTransfer == "" {
p.Docker.FileTransfer = config.DockerFileMount
}

// Default rootDir to .
if p.RootDir == "" {
p.RootDir = "."
Expand Down Expand Up @@ -271,26 +265,6 @@ func shardSuitesByNumShards(suites []Suite) []Suite {
return shardedSuites
}

// SplitSuites divided Suites to dockerSuites and sauceSuites
func SplitSuites(p Project) (Project, Project) {
var dockerSuites []Suite
var sauceSuites []Suite
for _, s := range p.Suites {
if s.Mode == "docker" || (s.Mode == "" && p.Defaults.Mode == "docker") {
dockerSuites = append(dockerSuites, s)
} else {
sauceSuites = append(sauceSuites, s)
}
}

dockerProject := p
dockerProject.Suites = dockerSuites
sauceProject := p
sauceProject.Suites = sauceSuites

return dockerProject, sauceProject
}

// Validate validates basic configuration of the project and returns an error if any of the settings contain illegal
// values. This is not an exhaustive operation and further validation should be performed both in the client and/or
// server side depending on the workflow that is executed.
Expand Down

0 comments on commit 294447c

Please sign in to comment.