@@ -4,6 +4,13 @@ import path from 'node:path';
44import child_process from 'node:child_process' ;
55import { getGlobalVariable } from './env' ;
66
7+ /** Cached Windows test mode value, avoiding recomputation. */
8+ let _cachedWindowsTestMode : WindowsWslTestMode | null | undefined = undefined ;
9+
10+ /**
11+ * Type describing an object that will hold all relevant information
12+ * for supporting native Windows testing through WSL.
13+ */
714interface WindowsWslTestMode {
815 cmdPath : string ;
916 gitBinaryDirForWindows : string ;
@@ -12,14 +19,28 @@ interface WindowsWslTestMode {
1219 npmBinaryForWindowsPath : string ;
1320 wslRootPath : string ;
1421 wslUncBase : string ;
22+ windowsChromedriverPath : string ;
23+ windowsChromiumPath : string ;
1524}
1625
26+ /**
27+ * Path to a temporary directory inside the Windows host file system.
28+ * e.g. `/mnt/c/Users/runner/AppData/Local/Temp`
29+ */
1730export const windowsTmpDir = process . env [ 'NG_E2E_RUNNER_WINDOWS_TMP_DIR' ] ;
1831
32+ /**
33+ * Whether the given path needs to be translated to a Windows native path,
34+ * using `wslpath -w`. This is useful when detecting paths in CLI arguments.
35+ */
1936export function shouldInteropWslPath ( p : string ) : boolean {
2037 return p . startsWith ( '/' ) && fs . existsSync ( p ) ;
2138}
2239
40+ /**
41+ * Translates the given Unix WSL path into a Windows host system path, if
42+ * necessary, decided via {@link shouldInteropWslPath}.
43+ */
2344export function interopWslPathForOutsideIfNecessary ( p : string ) : string {
2445 const windowsMode = isWindowsTestMode ( ) ;
2546 assert ( windowsMode !== null ) ;
@@ -38,9 +59,20 @@ export function interopWslPathForOutsideIfNecessary(p: string): string {
3859 return p ;
3960}
4061
62+ /**
63+ * Gets whether we are currently testing native Windows.
64+ *
65+ * If so, returns an object exposing relevant information for
66+ * supporting such testing mode,
67+ */
4168export function isWindowsTestMode ( ) : WindowsWslTestMode | null {
69+ if ( _cachedWindowsTestMode !== undefined ) {
70+ return _cachedWindowsTestMode ;
71+ }
72+
4273 const cmdEnv = process . env [ 'NG_E2E_RUNNER_WINDOWS_CMD' ] ;
4374 if ( cmdEnv === undefined ) {
75+ _cachedWindowsTestMode = null ;
4476 return null ;
4577 }
4678
@@ -67,7 +99,7 @@ export function isWindowsTestMode(): WindowsWslTestMode | null {
6799 'bin/nodejs' ,
68100 ) ;
69101
70- return {
102+ return ( _cachedWindowsTestMode = {
71103 cmdPath : cmdEnv ,
72104 gitBinaryDirForWindows : path . dirname ( gitBinaryForWindows ) ,
73105 // We will copy the Node version outside of WSL because NPM might
@@ -76,13 +108,29 @@ export function isWindowsTestMode(): WindowsWslTestMode | null {
76108 nodeBinaryForWindowsPath : path . join ( npmDir , 'node.exe' ) ,
77109 nodeBinaryForWindowsInsideWslPath : path . resolve ( nodeRepositoryDir , 'node.exe' ) ,
78110 npmBinaryForWindowsPath : windowsNpmBin ,
111+ windowsChromedriverPath : path . resolve (
112+ bazelTestWorkingDir ,
113+ `../org_chromium_chromedriver_windows/chromedriver_win32/chromedriver.exe` ,
114+ ) ,
115+ windowsChromiumPath : path . resolve (
116+ bazelTestWorkingDir ,
117+ `../org_chromium_chromium_windows/chrome-win/chrome.exe` ,
118+ ) ,
79119 wslRootPath,
80120 wslUncBase,
81- } ;
121+ } ) ;
82122}
83123
84124/**
125+ * Takes the given process environment and computes a `WSLENV` environment
126+ * variable value that allows for the process environment to be usable
127+ * within the Windows host environment (e.g. in `cmd.exe`).
128+ *
129+ * By default, WSL does not inherit process environment variables, unless
130+ * explicitly specified via the `WSLENV` variable; which is also smart enough
131+ * to automatically translate paths of environment variables from Unix to Windows.
85132 *
133+ * See: https://devblogs.microsoft.com/commandline/share-environment-vars-between-wsl-and-windows/
86134 */
87135export function createWslEnv ( env : NodeJS . ProcessEnv ) : string {
88136 const result : string [ ] = [ ] ;
0 commit comments