diff --git a/src/browserforce.ts b/src/browserforce.ts index 7cc59b72..117ec494 100644 --- a/src/browserforce.ts +++ b/src/browserforce.ts @@ -173,11 +173,9 @@ export default class Browserforce { const instanceUrl = this.getInstanceUrl(); // acme.my.salesforce.com // acme--.csN.my.salesforce.com - const matches = instanceUrl.match( - /https\:\/\/([^.]*)\.my\.salesforce\.com/ - ); + const matches = instanceUrl.match(/https\:\/\/(.*)\.my\.salesforce\.com/); if (matches) { - return matches[1]; + return matches[1].split('.')[0]; } return null; } @@ -185,10 +183,15 @@ export default class Browserforce { public getInstanceDomain() { const instanceUrl = this.getInstanceUrl(); // csN.salesforce.com - const matches = instanceUrl.match(/https\:\/\/([^.]*)\.salesforce\.com/); + // acme--.csN.my.salesforce.com + // NOT: test.salesforce.com login.salesforce.com + const matches = instanceUrl.match(/https\:\/\/(.*)\.salesforce\.com/); if (matches) { - if (!['test', 'login'].includes(matches[1])) { - return matches[1]; + const parts = matches[1].split('.'); + if (parts.length === 3 && parts[2] === 'my') { + return parts[1]; + } else if (!['test', 'login'].includes(parts[0])) { + return parts[0]; } } return null; diff --git a/src/plugins/communities/index.ts b/src/plugins/communities/index.ts index ce0e0023..9e5b7913 100644 --- a/src/plugins/communities/index.ts +++ b/src/plugins/communities/index.ts @@ -50,14 +50,15 @@ export default class Communities extends BrowserforcePlugin { config.domainName || this.browserforce.getMyDomain() || `comm-${Math.random() - .toString() - .substr(-22)}` + .toString(36) + .substr(2)}` ).substring(0, 22); await frameOrPage.waitFor(SELECTORS.DOMAIN_NAME_INPUT_TEXT); await frameOrPage.type(SELECTORS.DOMAIN_NAME_INPUT_TEXT, domainName); page.on('dialog', async dialog => { await dialog.accept(); }); + await frameOrPage.waitFor(SELECTORS.SAVE_BUTTON); await Promise.all([ page.waitForNavigation(), frameOrPage.click(SELECTORS.SAVE_BUTTON) diff --git a/test/browserforce.e2e-spec.ts b/test/browserforce.e2e-spec.ts index 2002b654..41abd621 100644 --- a/test/browserforce.e2e-spec.ts +++ b/test/browserforce.e2e-spec.ts @@ -28,4 +28,43 @@ describe('Browser', () => { bf.logout(); }); }); + describe('getMyDomain()', () => { + it('should determine a my domain for a scratch org', async function() { + this.timeout(1000 * 300); + this.slow(1000 * 30); + const defaultScratchOrg = await core.Org.create({}); + const ux = await UX.create(); + const bf = new Browserforce(defaultScratchOrg, ux.cli); + await bf.login(); + const myDomain = bf.getMyDomain(); + assert.notDeepEqual(null, myDomain); + await bf.logout(); + }); + }); + describe('getInstanceDomain()', () => { + it('should determine an instance domain for a scratch org with my domain', async function() { + this.timeout(1000 * 300); + this.slow(1000 * 30); + const defaultScratchOrg = await core.Org.create({}); + const ux = await UX.create(); + const bf = new Browserforce(defaultScratchOrg, ux.cli); + await bf.login(); + const instanceDomain = bf.getInstanceDomain(); + assert.notDeepEqual(null, instanceDomain); + await bf.logout(); + }); + }); + describe('getLightningUrl()', () => { + it('should determine a LEX URL for a scratch org with my domain', async function() { + this.timeout(1000 * 300); + this.slow(1000 * 30); + const defaultScratchOrg = await core.Org.create({}); + const ux = await UX.create(); + const bf = new Browserforce(defaultScratchOrg, ux.cli); + await bf.login(); + const lexUrl = bf.getLightningUrl(); + assert.notDeepEqual(null, lexUrl); + await bf.logout(); + }); + }); });