Skip to content

Commit d7bebd9

Browse files
committed
fix: fix code review comments
1 parent 71b6545 commit d7bebd9

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

lib/commands/powershell.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export async function startPowerShellSession(this: NovaWindowsDriver): Promise<v
4444
}
4545
const envVars = Array.from(envVarsSet);
4646
for (const envVar of envVars) {
47-
this.caps.appWorkingDir = this.caps.appWorkingDir.replaceAll(`%${envVar}%`, process.env[envVar.toUpperCase()] ?? '');
47+
this.caps.appWorkingDir = this.caps.appWorkingDir.replaceAll(`%${envVar}%`, spawnEnv[envVar.toUpperCase()] ?? '');
4848
}
4949
this.sendPowerShellCommand(`Set-Location -Path '${this.caps.appWorkingDir}'`);
5050
}
@@ -82,7 +82,7 @@ export async function startPowerShellSession(this: NovaWindowsDriver): Promise<v
8282
this.log.info(`Detected the following environment variables in app path: ${envVars.map((envVar) => `%${envVar}%`).join(', ')}`);
8383

8484
for (const envVar of envVars) {
85-
this.caps.app = this.caps.app.replaceAll(`%${envVar}%`, process.env[envVar.toUpperCase()] ?? '');
85+
this.caps.app = this.caps.app.replaceAll(`%${envVar}%`, spawnEnv[envVar.toUpperCase()] ?? '');
8686
}
8787

8888
await this.changeRootElement(this.caps.app);
@@ -108,7 +108,6 @@ export async function sendIsolatedPowerShellCommand(this: NovaWindowsDriver, com
108108
const powerShell = spawn('powershell.exe', ['-NoExit', '-Command', '-'], { env: spawnEnv });
109109
try {
110110
powerShell.stdout.setEncoding('utf8');
111-
powerShell.stdout.setEncoding('utf8');
112111

113112
let localStdOut = '';
114113
let localStdErr = '';
@@ -135,7 +134,7 @@ export async function sendIsolatedPowerShellCommand(this: NovaWindowsDriver, com
135134
}
136135
const envVars = Array.from(envVarsSet);
137136
for (const envVar of envVars) {
138-
this.caps.appWorkingDir = this.caps.appWorkingDir.replaceAll(`%${envVar}%`, process.env[envVar.toUpperCase()] ?? '');
137+
this.caps.appWorkingDir = this.caps.appWorkingDir.replaceAll(`%${envVar}%`, spawnEnv[envVar.toUpperCase()] ?? '');
139138
}
140139
powerShell.stdin.write(`Set-Location -Path '${this.caps.appWorkingDir}'\n`);
141140
}

lib/driver.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,16 @@ export class NovaWindowsDriver extends BaseDriver<NovaWindowsDriverConstraints,
176176
if (caps.app && caps.appTopLevelWindow) {
177177
throw new errors.InvalidArgumentError('Invalid capabilities. Specify either app or appTopLevelWindow.');
178178
}
179+
if (caps.appEnvironment) {
180+
const invalidKeys = Object.entries(caps.appEnvironment as Record<string, unknown>)
181+
.filter(([, v]) => typeof v !== 'string')
182+
.map(([k]) => k);
183+
if (invalidKeys.length > 0) {
184+
throw new errors.InvalidArgumentError(
185+
`Invalid capabilities. 'appEnvironment' values must be strings. Invalid keys: ${invalidKeys.join(', ')}`
186+
);
187+
}
188+
}
179189
if (this.caps.shouldCloseApp === undefined) {
180190
this.caps.shouldCloseApp = true; // set default value
181191
}

0 commit comments

Comments
 (0)