Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(cdk): remove mockery #27242

Merged
merged 2 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/aws-cdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@
"constructs": "^10.0.0",
"fast-check": "^3.13.0",
"jest": "^29.7.0",
"jest-mock": "^29.7.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, this is already installed with jest anyway. Just needs be explicit now, since we are importing a utility function from it.

"madge": "^5.0.2",
"make-runnable": "^1.4.1",
"mockery": "^2.1.0",
"nock": "^13.3.3",
"sinon": "^9.2.4",
"ts-jest": "^29.1.1",
Expand Down
36 changes: 12 additions & 24 deletions packages/aws-cdk/test/cdk-docs.test.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,30 @@
/* eslint-disable import/order */
import * as mockery from 'mockery';
import * as child_process from 'child_process';
import { mocked } from 'jest-mock';
import { CommandHandler } from '../lib/command-api';
import { realHandler } from '../lib/commands/docs';

const argv = {
browser: 'echo %u',
commandHandler: undefined as (CommandHandler | undefined),
};

describe('`cdk docs`', () => {
beforeEach(done => {
mockery.registerMock('../../lib/logging', {
debug() { return; },
error() { return; },
print() { return; },
warning() { return; },
});
mockery.enable({ useCleanCache: true, warnOnReplace: true, warnOnUnregistered: false });
done();
});
// eslint-disable-next-line no-console
console.log = jest.fn();
jest.mock('child_process');

afterAll(done => {
mockery.disable();
mockery.deregisterAll();
done();
});
describe('`cdk docs`', () => {

test('exits with 0 when everything is OK', async () => {
const mockChildProcessExec: any = (_: string, cb: (err?: Error, stdout?: string, stderr?: string) => void) => cb();
mocked(child_process.exec).mockImplementation(mockChildProcessExec);

const result = await realHandler({ args: argv } as any);
expect(result).toBe(0);
});

test('exits with 0 when opening the browser fails', async () => {
mockery.registerMock('child_process', {
exec(_: string, cb: (err: Error, stdout?: string, stderr?: string) => void) {
cb(new Error('TEST'));
},
});
const mockChildProcessExec: any = (_: string, cb: (err: Error, stdout?: string, stderr?: string) => void) => cb(new Error('TEST'));
mocked(child_process.exec).mockImplementation(mockChildProcessExec);

const result = await realHandler({ args: argv } as any);
expect(result).toBe(0);
});
Expand Down
19 changes: 3 additions & 16 deletions packages/aws-cdk/test/cdk-doctor.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
/* eslint-disable import/order */
import * as mockery from 'mockery';
import { realHandler } from '../lib/commands/doctor';

describe('`cdk doctor`', () => {
beforeEach(done => {
mockery.registerMock('../../lib/logging', {
print: () => undefined,
});
mockery.enable({ useCleanCache: true, warnOnReplace: true, warnOnUnregistered: false });
done();
});

afterEach(done => {
mockery.disable();
mockery.deregisterAll();
done();
});
// eslint-disable-next-line no-console
console.log = jest.fn();

describe('`cdk doctor`', () => {
test('exits with 0 when everything is OK', async () => {
const argv: any = {};
const result = await realHandler({ args: argv } as any);
Expand Down
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10423,11 +10423,6 @@ mock-fs@^4.14.0:
resolved "https://registry.npmjs.org/mock-fs/-/mock-fs-4.14.0.tgz#ce5124d2c601421255985e6e94da80a7357b1b18"
integrity sha512-qYvlv/exQ4+svI3UOvPUpLDF0OMX5euvUH0Ny4N5QyRyhNdgAgUrVH3iUINSzEPLvx0kbo/Bp28GJKIqvE7URw==

mockery@^2.1.0:
version "2.1.0"
resolved "https://registry.npmjs.org/mockery/-/mockery-2.1.0.tgz#5b0aef1ff564f0f8139445e165536c7909713470"
integrity sha512-9VkOmxKlWXoDO/h1jDZaS4lH33aWfRiJiNT/tKj+8OGzrcFDLo8d0syGdbsc3Bc4GvRXPb+NMMvojotmuGJTvA==

modify-values@^1.0.0, modify-values@^1.0.1:
version "1.0.1"
resolved "https://registry.npmjs.org/modify-values/-/modify-values-1.0.1.tgz#b3939fa605546474e3e3e3c63d64bd43b4ee6022"
Expand Down