Skip to content

Commit

Permalink
feat: shorter scratch org lifetime (#433)
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Mar 24, 2023
1 parent 7b028b2 commit 0c36a10
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
15 changes: 4 additions & 11 deletions src/testSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,10 @@ export class TestSession<T extends TestSessionOptions = TestSessionOptions> exte
}

let baseCmd =
executable === 'sf' ? `${executable} env create scratch --json` : `${executable} force:org:create --json`;
executable === 'sf'
? `${executable} env create scratch --json -y ${org.duration ?? '1'}`
: `${executable} force:org:create --json -d ${org.duration ?? '1'}`;
baseCmd += ` -w ${org.wait ?? 60}`;

if (org.config) {
baseCmd += ` -f ${org.config}`;
Expand All @@ -339,10 +342,6 @@ export class TestSession<T extends TestSessionOptions = TestSessionOptions> exte
baseCmd += ` -a ${org.alias}`;
}

if (org.duration) {
baseCmd += executable === 'sf' ? ` -y ${org.duration}` : ` -d ${org.duration}`;
}

if (org.setDefault) {
baseCmd += executable === 'sf' ? ' -d' : ' -s';
}
Expand All @@ -356,12 +355,6 @@ export class TestSession<T extends TestSessionOptions = TestSessionOptions> exte
baseCmd += executable === 'sf' ? ` -e ${org.edition}` : ` edition=${org.edition}`;
}

if (org.wait) {
baseCmd += ` -w ${org.wait}`;
} else {
baseCmd += ' -w 60';
}

const rv = shell.exec(baseCmd, this.shelljsExecOptions) as shell.ShellString;
rv.stdout = stripAnsi(rv.stdout);
rv.stderr = stripAnsi(rv.stderr);
Expand Down
6 changes: 3 additions & 3 deletions test/unit/testSession.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ describe('TestSession', () => {
expect(execStub.callCount).to.equal(scratchOrgs.length * (retries + 1));
expect(session.orgs.get(username)).to.deep.equal({ username, orgId: '12345' });
expect(execStub.firstCall.args[0]).to.equal(
'sf env create scratch --json -f config/project-scratch-def.json -w 60'
'sf env create scratch --json -y 1 -w 60 -f config/project-scratch-def.json'
);
});

Expand Down Expand Up @@ -215,7 +215,7 @@ describe('TestSession', () => {
expect(session.orgs.get(username)).to.deep.equal({ username, orgId: '12345' });
expect(session.orgs.get('default')).to.deep.equal({ username, orgId: '12345' });
expect(execStub.firstCall.args[0]).to.equal(
'sf env create scratch --json -f config/project-scratch-def.json -a my-org -y 1 -d -e developer -w 60'
'sf env create scratch --json -y 1 -w 60 -f config/project-scratch-def.json -a my-org -d -e developer'
);
expect(process.env.HOME).to.equal(session.homeDir);
expect(process.env.USERPROFILE).to.equal(session.homeDir);
Expand Down Expand Up @@ -256,7 +256,7 @@ describe('TestSession', () => {

it('should error if setup command fails', async () => {
stubMethod(sandbox, shelljs, 'which').returns(true);
const expectedCmd = 'sf env create scratch --json -f config/project-scratch-def.json -w 60';
const expectedCmd = 'sf env create scratch --json -y 1 -w 60 -f config/project-scratch-def.json';
const execRv = 'Cannot foo before bar';
const shellString = new ShellString(JSON.stringify(execRv));
shellString.code = 1;
Expand Down

0 comments on commit 0c36a10

Please sign in to comment.