Skip to content

Commit 0fe90b6

Browse files
fix: user credential issue in windows
1 parent 6f13411 commit 0fe90b6

2 files changed

Lines changed: 15 additions & 19 deletions

File tree

test/commands/lightning/dev/component-preview/prompts.nut.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ describe('lightning preview component prompts', () => {
4545

4646
beforeEach(async () => {
4747
session = await getSession();
48-
const org = await Org.create({ aliasOrUsername: session.orgs.get('default')?.username });
49-
connection = org.getConnection();
48+
const username = session.orgs.get('default')?.username;
49+
const orgController = await Org.create({ aliasOrUsername: username });
50+
connection = orgController.getConnection();
5051
// Unset required org configuration to trigger prompt behavior
5152
await MetaUtils.setLightningPreviewEnabled(connection, false);
5253
await MetaUtils.setMyDomainFirstPartyCookieRequirement(connection, true);

test/commands/lightning/dev/helpers/browserUtils.ts

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { spawnSync } from 'node:child_process';
1817
import { chromium, type Browser, type Page } from 'playwright';
19-
import { TestSession } from '@salesforce/cli-plugins-testkit';
18+
import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
19+
20+
type OrgDisplayUserResult = { accessToken?: string };
2021

2122
/**
2223
* Returns the access token for frontdoor sid authentication. Required for
23-
* Playwright testing.
24+
* Playwright testing. Uses testkit execCmd so the correct CLI executable is
25+
* used on all platforms (e.g. sf on Unix, sf.cmd on Windows).
2426
*
2527
* @param session - TestSession with a default scratch org.
2628
* @returns The session ID string.
@@ -32,23 +34,16 @@ export function getAccessToken(session: TestSession): string {
3234
if (!username || !projectDir) {
3335
throw new Error('Session has no default scratch org username or project dir');
3436
}
35-
const result = spawnSync('sf', ['org', 'display', 'user', '-o', username, '--json'], {
37+
const result = execCmd<OrgDisplayUserResult>(`org display user -o ${username} --json`, {
3638
cwd: projectDir,
37-
encoding: 'utf8',
38-
maxBuffer: 10 * 1024,
39+
cli: 'sf',
40+
ensureExitCode: 0,
3941
});
40-
if (result.status !== 0) {
41-
throw new Error(`sf org display user failed: ${result.stderr ?? result.error?.message ?? 'unknown'}`);
42-
}
43-
let displayUser: { result?: { accessToken?: string } };
44-
try {
45-
displayUser = JSON.parse(result.stdout ?? '{}') as { result?: { accessToken?: string } };
46-
} catch {
47-
throw new Error('sf org display user did not return valid JSON');
48-
}
49-
const accessToken = displayUser.result?.accessToken ?? '';
42+
const accessToken = result.jsonOutput?.result?.accessToken ?? '';
5043
if (!accessToken) {
51-
throw new Error('sf org display user result missing accessToken');
44+
throw new Error(
45+
`sf org display user result missing accessToken: ${result.shellOutput.stdout} ${result.shellOutput.stderr ?? ''}`,
46+
);
5247
}
5348
return accessToken;
5449
}

0 commit comments

Comments
 (0)