Skip to content

Commit 2cf7273

Browse files
committed
Wire up isolateConfig to SDK command tests
Add isolateConfig()/restoreConfig() to command test files to ensure tests are isolated from developer's environment variables (SFCC_*, MRT_*). Files updated: - test/cli/base-command.test.ts - test/cli/instance-command.test.ts - test/cli/mrt-command.test.ts - test/cli/oauth-command.test.ts - test/cli/ods-command.test.ts
1 parent 9091e4c commit 2cf7273

5 files changed

Lines changed: 30 additions & 0 deletions

File tree

packages/b2c-tooling-sdk/test/cli/base-command.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import {expect} from 'chai';
77
import {Config} from '@oclif/core';
88
import {BaseCommand} from '@salesforce/b2c-tooling-sdk/cli';
9+
import {isolateConfig, restoreConfig} from '../helpers/config-isolation.js';
910

1011
// Create a concrete test command class
1112
class TestBaseCommand extends BaseCommand<typeof TestBaseCommand> {
@@ -53,10 +54,15 @@ describe('cli/base-command', () => {
5354
let command: TestBaseCommand;
5455

5556
beforeEach(async () => {
57+
isolateConfig();
5658
config = await Config.load();
5759
command = new TestBaseCommand([], config);
5860
});
5961

62+
afterEach(() => {
63+
restoreConfig();
64+
});
65+
6066
describe('getExtraParams', () => {
6167
it('returns undefined when no extra params', async () => {
6268
const cmd = command as MockableBaseCommand;

packages/b2c-tooling-sdk/test/cli/instance-command.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {expect} from 'chai';
77
import {Config} from '@oclif/core';
88
import {InstanceCommand} from '@salesforce/b2c-tooling-sdk/cli';
99
import type {B2COperationContext, B2COperationResult, B2COperationType} from '@salesforce/b2c-tooling-sdk/cli';
10+
import {isolateConfig, restoreConfig} from '../helpers/config-isolation.js';
1011

1112
// Create a test command class
1213
class TestInstanceCommand extends InstanceCommand<typeof TestInstanceCommand> {
@@ -65,10 +66,15 @@ describe('cli/instance-command', () => {
6566
let command: TestInstanceCommand;
6667

6768
beforeEach(async () => {
69+
isolateConfig();
6870
config = await Config.load();
6971
command = new TestInstanceCommand([], config);
7072
});
7173

74+
afterEach(() => {
75+
restoreConfig();
76+
});
77+
7278
describe('requireServer', () => {
7379
it('throws error when no server', async () => {
7480
const cmd = command as MockableInstanceCommand;

packages/b2c-tooling-sdk/test/cli/mrt-command.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import {expect} from 'chai';
77
import {Config} from '@oclif/core';
88
import {MrtCommand} from '@salesforce/b2c-tooling-sdk/cli';
9+
import {isolateConfig, restoreConfig} from '../helpers/config-isolation.js';
910

1011
// Create a test command class
1112
class TestMrtCommand extends MrtCommand<typeof TestMrtCommand> {
@@ -40,10 +41,15 @@ describe('cli/mrt-command', () => {
4041
let command: TestMrtCommand;
4142

4243
beforeEach(async () => {
44+
isolateConfig();
4345
config = await Config.load();
4446
command = new TestMrtCommand([], config);
4547
});
4648

49+
afterEach(() => {
50+
restoreConfig();
51+
});
52+
4753
describe('requireMrtCredentials', () => {
4854
it('throws error when no credentials', async () => {
4955
const cmd = command as MockableMrtCommand;

packages/b2c-tooling-sdk/test/cli/oauth-command.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import {expect} from 'chai';
77
import {Config} from '@oclif/core';
88
import {OAuthCommand} from '@salesforce/b2c-tooling-sdk/cli';
9+
import {isolateConfig, restoreConfig} from '../helpers/config-isolation.js';
910

1011
// Create a test command class
1112
class TestOAuthCommand extends OAuthCommand<typeof TestOAuthCommand> {
@@ -44,10 +45,15 @@ describe('cli/oauth-command', () => {
4445
let command: TestOAuthCommand;
4546

4647
beforeEach(async () => {
48+
isolateConfig();
4749
config = await Config.load();
4850
command = new TestOAuthCommand([], config);
4951
});
5052

53+
afterEach(() => {
54+
restoreConfig();
55+
});
56+
5157
describe('parseAuthMethods', () => {
5258
it('returns undefined when no auth methods specified', async () => {
5359
const cmd = command as MockableOAuthCommand;

packages/b2c-tooling-sdk/test/cli/ods-command.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import {expect} from 'chai';
77
import {Config} from '@oclif/core';
88
import {OdsCommand} from '@salesforce/b2c-tooling-sdk/cli';
9+
import {isolateConfig, restoreConfig} from '../helpers/config-isolation.js';
910

1011
// Create a test command class
1112
class TestOdsCommand extends OdsCommand<typeof TestOdsCommand> {
@@ -39,10 +40,15 @@ describe('cli/ods-command', () => {
3940
let command: TestOdsCommand;
4041

4142
beforeEach(async () => {
43+
isolateConfig();
4244
config = await Config.load();
4345
command = new TestOdsCommand([], config);
4446
});
4547

48+
afterEach(() => {
49+
restoreConfig();
50+
});
51+
4652
describe('odsClient', () => {
4753
it('throws error when no OAuth credentials', async () => {
4854
const cmd = command as MockableOdsCommand;

0 commit comments

Comments
 (0)