Skip to content

Commit 8170fb3

Browse files
committed
fix: fix failing tests in cli by restoring the original ClioHost instance after each test run
1 parent d6d2708 commit 8170fb3

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

packages/aws-cdk/test/cli/cli.test.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -437,19 +437,27 @@ describe('notices configuration tests', () => {
437437
});
438438

439439
describe('gc command tests', () => {
440+
let originalCliIoHostInstance: any;
441+
440442
beforeEach(() => {
441443
jest.clearAllMocks();
444+
originalCliIoHostInstance = CliIoHost.instance;
445+
});
446+
447+
afterEach(() => {
448+
CliIoHost.instance = originalCliIoHostInstance;
442449
});
443450

444451
test('should warn when --role-arn is used with gc command', async () => {
445452
const gcSpy = jest.spyOn(cdkToolkitModule.CdkToolkit.prototype, 'garbageCollect').mockResolvedValue();
446-
447-
// Make exec use our TestIoHost and adds properties to TestIoHost to match ClioHosr
453+
454+
// Make exec use our TestIoHost and adds properties to TestIoHost to match CliIoHost
448455
const warnSpy = jest.fn();
449-
(ioHost as any).defaults = { warn: warnSpy, debug: jest.fn() };
456+
(ioHost as any).defaults = { warn: warnSpy, debug: jest.fn(), result: jest.fn() };
450457
(ioHost as any).asIoHelper = () => ioHelper;
458+
(ioHost as any).logLevel = 'info';
451459
jest.spyOn(CliIoHost, 'instance').mockReturnValue(ioHost as any);
452-
460+
453461
const mockConfig = {
454462
loadConfigFiles: jest.fn().mockResolvedValue(undefined),
455463
settings: {
@@ -462,13 +470,13 @@ describe('gc command tests', () => {
462470
get: jest.fn().mockReturnValue([]),
463471
},
464472
};
465-
473+
466474
Configuration.fromArgsAndFiles = jest.fn().mockResolvedValue(mockConfig);
467475

468476
await exec(['gc', '--unstable=gc', '--role-arn', 'arn:aws:iam::123456789012:role/TestRole']);
469477

470478
expect(warnSpy).toHaveBeenCalledWith(
471-
'The --role-arn option is not supported for the gc command and will be ignored.'
479+
'The --role-arn option is not supported for the gc command and will be ignored.',
472480
);
473481
expect(gcSpy).toHaveBeenCalled();
474482
});

0 commit comments

Comments
 (0)