Skip to content

Commit

Permalink
Merge pull request #131 from amtrack/fix/previous-commit
Browse files Browse the repository at this point in the history
fix: fix errors introduced with v1.2.1
  • Loading branch information
amtrack authored Mar 25, 2019
2 parents 4036d0c + 6c6a182 commit 31d133e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 9 deletions.
17 changes: 10 additions & 7 deletions src/browserforce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,22 +173,25 @@ export default class Browserforce {
const instanceUrl = this.getInstanceUrl();
// acme.my.salesforce.com
// acme--<sandboxName>.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;
}

public getInstanceDomain() {
const instanceUrl = this.getInstanceUrl();
// csN.salesforce.com
const matches = instanceUrl.match(/https\:\/\/([^.]*)\.salesforce\.com/);
// acme--<sandboxName>.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;
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/communities/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
39 changes: 39 additions & 0 deletions test/browserforce.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});

0 comments on commit 31d133e

Please sign in to comment.