7
7
[switch ] $useHostWebServer = $false ,
8
8
[string ] $grep = " " ,
9
9
[ValidateSet (" auto" , " install" , " mount" )]
10
- [string ] $installNpmPackagesMode = " auto"
10
+ [string ] $installNpmPackagesMode = " auto" ,
11
+ [ValidateSet (" auto" , " supported" , " unsupported" )]
12
+ [string ] $fileChangesDetectionSupportMode = " auto"
11
13
)
12
14
13
15
function GetPlaywrightVersion () {
@@ -54,6 +56,33 @@ function NeedsToInstallNpmPackages() {
54
56
return $needsToInstallNpmPackages ;
55
57
}
56
58
59
+ function IsFileChangesDetectionSupported () {
60
+ if ($fileChangesDetectionSupportMode -eq " auto" ) {
61
+ $isDockerDesktopOnWindowsUsingWsl2 = IsDockerDesktopOnWindowsUsingWsl2
62
+ if ($isDockerDesktopOnWindowsUsingWsl2 ) {
63
+ Write-Host " Detected Docker Desktop running on WSL2. FILE_CHANGES_DETECTION_SUPPORTED=false environment variable will be added to the docker run command." - ForegroundColor Cyan
64
+ }
65
+
66
+ return ! $isDockerDesktopOnWindowsUsingWsl2 ;
67
+ } elseif ($fileChangesDetectionSupportMode -eq " supported" ) {
68
+ return $true
69
+ } elseif ($fileChangesDetectionSupportMode -eq " unsupported" ) {
70
+ return $false
71
+ }
72
+
73
+ throw " Unknown '-fileChangesDetectionSupportMode' option. Received: $fileChangesDetectionSupportMode . Available options are: 'auto | supported | unsupported'"
74
+ }
75
+
76
+ function IsDockerDesktopOnWindowsUsingWsl2 () {
77
+ if (! $IsWindows ) {
78
+ return $false
79
+ }
80
+
81
+ # See https://docs.docker.com/desktop/settings/windows/
82
+ $dockerDesktopSettings = Get-Content " $env: USERPROFILE \AppData\Roaming\Docker\settings.json" | ConvertFrom-Json
83
+ return $dockerDesktopSettings.wslEngineEnabled
84
+ }
85
+
57
86
function StartPlaywrightTests {
58
87
Write-Host " Starting playwright tests run in docker container...`n " - ForegroundColor Cyan
59
88
Write-Host " options:" - ForegroundColor DarkYellow
@@ -102,17 +131,25 @@ function StartPlaywrightTests {
102
131
Exit $LASTEXITCODE # see https://stackoverflow.com/questions/32348794/how-to-get-status-of-invoke-expression-successful-or-failed
103
132
}
104
133
105
-
106
134
function StartPlaywrightUI () {
107
135
Write-Host " Starting playwright tests with ui in docker container...`n "
108
136
Write-Host " options:" - ForegroundColor DarkYellow
109
137
Write-Host " -useHostWebServer=$useHostWebServer " - ForegroundColor DarkYellow
110
- Write-Host " -installNpmPackagesMode=$installNpmPackagesMode `n " - ForegroundColor DarkYellow
138
+ Write-Host " -installNpmPackagesMode=$installNpmPackagesMode " - ForegroundColor DarkYellow
139
+ Write-Host " -fileChangesDetectionSupportMode=$fileChangesDetectionSupportMode `n " - ForegroundColor DarkYellow
111
140
112
141
if ($useHostWebServer ) {
113
142
$useHostWebServerOption = " --add-host=host.docker.internal:host-gateway --env USE_DOCKER_HOST_WEBSERVER=true"
114
143
}
115
144
145
+ # For more info on the reason for the FILE_CHANGES_DETECTION_SUPPORTED environment variable
146
+ # see the section 'File changes aren't triggering an application rebuild when testing with UI mode' of the README at /demos/docker/README.md
147
+ if (IsFileChangesDetectionSupported) {
148
+ $fileChangesDetectionSupportedEnv = " --env FILE_CHANGES_DETECTION_SUPPORTED=true"
149
+ } else {
150
+ $fileChangesDetectionSupportedEnv = " --env FILE_CHANGES_DETECTION_SUPPORTED=false"
151
+ }
152
+
116
153
# Must use a random port or else there will be issues with the UI app where sometimes the tests don't load/refresh properly.
117
154
# I believe it has something to do with some websockets that the UI app uses. When the same port is used and the UI app is
118
155
# restarted, the tests don't load properly until the websockets timeout and then a new connection is established.
@@ -127,7 +164,7 @@ function StartPlaywrightUI() {
127
164
$startCommand = " /bin/bash -c 'npm ci && $startCommand '" # see https://stackoverflow.com/questions/28490874/docker-run-image-multiple-commands
128
165
}
129
166
130
- $dockerRunCommand = " docker run -it --rm --ipc=host $useHostWebServerOption --workdir=/app -p ${playwrightUiPort} :${playwrightUiPort} -v '${PWD} :/app' $nodeModulesMount mcr.microsoft.com/playwright:v$playwrightVersion -jammy $startCommand "
167
+ $dockerRunCommand = " docker run -it --rm --ipc=host $useHostWebServerOption $fileChangesDetectionSupportedEnv --workdir=/app -p ${playwrightUiPort} :${playwrightUiPort} -v '${PWD} :/app' $nodeModulesMount mcr.microsoft.com/playwright:v$playwrightVersion -jammy $startCommand "
131
168
if ($installNpmPackages ) {
132
169
Write-Host " NPM packages will be installed in the docker container." - ForegroundColor Cyan
133
170
}
0 commit comments