Skip to content

Commit 54e7b93

Browse files
committed
fix: only local config
1 parent f84c64f commit 54e7b93

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

src/commands/force/org/beta/create.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -269,15 +269,14 @@ export class Create extends SfdxCommand {
269269
this.logger.debug('Set Alias: %s result: %s', this.flags.setalias, result);
270270
}
271271
if (this.flags.setdefaultusername) {
272-
let config: Config;
273272
try {
274-
config = await Config.create({ isGlobal: false });
275-
} catch {
276-
config = await Config.create({ isGlobal: true });
273+
const config = await Config.create({ isGlobal: false });
274+
const result = config.set(Config.DEFAULT_USERNAME, username);
275+
await config.write();
276+
this.logger.debug('Set defaultUsername: %s result: %s', this.flags.setdefaultusername, result);
277+
} catch (error) {
278+
this.logger.debug('Set defaultUsername failed with error: %s', error);
277279
}
278-
const result = config.set(Config.DEFAULT_USERNAME, username);
279-
await config.write();
280-
this.logger.debug('Set defaultUsername: %s result: %s', this.flags.setdefaultusername, result);
281280
}
282281
}
283282
private async createScratchOrg(): Promise<ScratchOrgProcessObject> {

test/commands/force/org/scratchOrgCreate.test.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,13 @@ describe('org:create', () => {
199199
username: 'newScratchUsername',
200200
});
201201
const aliasStub = stubMethod(sandbox, Aliases.prototype, 'set');
202-
const configStub = stubMethod(sandbox, Config.prototype, 'set');
202+
const setStub = sandbox.spy();
203+
const writeStub = sandbox.spy();
204+
const configCreateStub = stubMethod(sandbox, Config, 'create').withArgs({ isGlobal: false }).resolves({
205+
set: setStub,
206+
write: writeStub,
207+
});
208+
// const configStub = stubMethod(sandbox, Config.prototype, 'set');
203209
await command.runIt();
204210
expect(prodOrg.firstCall.args[0]).to.deep.equal({
205211
apiversion: undefined,
@@ -217,7 +223,10 @@ describe('org:create', () => {
217223
orgConfig: {},
218224
});
219225
expect(aliasStub.firstCall.args).to.deep.equal(['sandboxAlias', 'newScratchUsername']);
220-
expect(configStub.firstCall.args).to.deep.equal(['defaultusername', 'newScratchUsername']);
226+
expect(configCreateStub.calledOnce).to.be.true;
227+
expect(writeStub.calledOnce).to.be.true;
228+
expect(configCreateStub.firstCall.firstArg).to.deep.equal({ isGlobal: false });
229+
expect(setStub.firstCall.args).to.deep.equal(['defaultusername', 'newScratchUsername']);
221230
});
222231

223232
it('will test json output', async () => {

0 commit comments

Comments
 (0)