Skip to content

Commit 51a9ab0

Browse files
committed
build: fixed testing with new yargs update
1 parent dc9b31d commit 51a9ab0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+428
-359
lines changed

__tests__/commands/apps/apps.create.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import { Client } from '@vonage/server-client';
88

99
const confirmMock = jest.fn();
1010
const writeFileMock = jest.fn();
11-
const yargs = { exit: jest.fn() };
11+
const exitMock = jest.fn();
12+
const yargs = jest.fn().mockImplementation(() => ({ exit: exitMock }));
1213

1314
jest.unstable_mockModule('yargs', () => ({ default: yargs }));
1415
jest.unstable_mockModule('../../../src/ux/confirm.js', () => ({ confirm: confirmMock }));
@@ -21,7 +22,7 @@ describe('Command: vonage apps create', () => {
2122
mockConsole();
2223
confirmMock.mockReset();
2324
writeFileMock.mockReset();
24-
yargs.exit.mockReset();
25+
exitMock.mockReset();
2526
});
2627

2728
test('Should create app and save private key', async () => {

__tests__/commands/apps/apps.list.test.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import { mockConsole } from '../../helpers.js';
1515
import { Client } from '@vonage/server-client';
1616

1717
const spinnerMock = jest.fn();
18-
const yargs = { exit: jest.fn() };
18+
const exitMock = jest.fn();
19+
const yargs = jest.fn().mockImplementation(() => ({ exit: exitMock }));
1920

2021
jest.unstable_mockModule('yargs', () => ({ default: yargs }));
2122
jest.unstable_mockModule('../../../src/ux/spinner.js', () => ({ spinner: spinnerMock }));
@@ -29,13 +30,12 @@ const makeSDK = (listAllApplications) => ({
2930
describe('Command: vonage apps', () => {
3031
beforeEach(() => {
3132
spinnerMock.mockReset();
32-
yargs.exit.mockReset();
3333
spinnerMock.mockReturnValue({ stop: jest.fn(), fail: jest.fn() });
3434
mockConsole();
3535
});
3636

3737
test('Will list applications when there are none', async () => {
38-
const sdk = makeSDK(async function* () { yield* []; });
38+
const sdk = makeSDK(async function*() { yield* []; });
3939

4040
await handler({ SDK: sdk });
4141

@@ -45,7 +45,7 @@ describe('Command: vonage apps', () => {
4545

4646
test('Will list one application that does not have any capabilities', async () => {
4747
const app = getTestApp();
48-
const listAllApplications = jest.fn(async function* () { yield app; });
48+
const listAllApplications = jest.fn(async function*() { yield app; });
4949
const sdk = makeSDK(listAllApplications);
5050

5151
await handler({ SDK: sdk });
@@ -77,7 +77,7 @@ describe('Command: vonage apps', () => {
7777
),
7878
);
7979
const appTwo = getTestApp();
80-
const sdk = makeSDK(async function* () { yield appOne; yield appTwo; });
80+
const sdk = makeSDK(async function*() { yield appOne; yield appTwo; });
8181

8282
await handler({ SDK: sdk });
8383

@@ -99,7 +99,7 @@ describe('Command: vonage apps', () => {
9999
const appOne = getTestApp();
100100
const appTwo = getTestApp();
101101
const appThree = getTestApp();
102-
const sdk = makeSDK(async function* () { yield appOne; yield appTwo; yield appThree; });
102+
const sdk = makeSDK(async function*() { yield appOne; yield appTwo; yield appThree; });
103103

104104
await handler({ SDK: sdk, appName: appTwo.name });
105105

@@ -119,7 +119,7 @@ describe('Command: vonage apps', () => {
119119
const appOne = addVoiceCapabilities(getTestApp());
120120
const appTwo = getTestApp();
121121
const appThree = addVoiceCapabilities(addMessagesCapabilities(getTestApp()));
122-
const sdk = makeSDK(async function* () { yield appOne; yield appTwo; yield appThree; });
122+
const sdk = makeSDK(async function*() { yield appOne; yield appTwo; yield appThree; });
123123

124124
await handler({ SDK: sdk, capability: coerceCapability('voice') });
125125

@@ -141,7 +141,7 @@ describe('Command: vonage apps', () => {
141141
const appOne = addVoiceCapabilities(getTestApp());
142142
const appTwo = getTestApp();
143143
const appThree = addMessagesCapabilities(getTestApp());
144-
const sdk = makeSDK(async function* () { yield appOne; yield appTwo; yield appThree; });
144+
const sdk = makeSDK(async function*() { yield appOne; yield appTwo; yield appThree; });
145145

146146
await handler({ SDK: sdk, capability: coerceCapability('voice,messages') });
147147

@@ -163,7 +163,7 @@ describe('Command: vonage apps', () => {
163163
const appOne = addVoiceCapabilities(getTestApp());
164164
const appTwo = addVoiceCapabilities(addMessagesCapabilities(getTestApp()));
165165
const appThree = addMessagesCapabilities(getTestApp());
166-
const sdk = makeSDK(async function* () { yield appOne; yield appTwo; yield appThree; });
166+
const sdk = makeSDK(async function*() { yield appOne; yield appTwo; yield appThree; });
167167

168168
await handler({ SDK: sdk, capability: coerceCapability('voice+messages') });
169169

@@ -178,7 +178,7 @@ describe('Command: vonage apps', () => {
178178

179179
test('Will output JSON', async () => {
180180
const app = getTestApp();
181-
const sdk = makeSDK(async function* () { yield app; });
181+
const sdk = makeSDK(async function*() { yield app; });
182182

183183
await handler({ SDK: sdk, json: true });
184184

@@ -188,7 +188,7 @@ describe('Command: vonage apps', () => {
188188

189189
test('Will output YAML', async () => {
190190
const app = getTestApp();
191-
const sdk = makeSDK(async function* () { yield app; });
191+
const sdk = makeSDK(async function*() { yield app; });
192192

193193
await handler({ SDK: sdk, yaml: true });
194194

@@ -208,15 +208,15 @@ describe('Command: vonage apps', () => {
208208
});
209209

210210
test('Will exit 99 when API calls fails', async () => {
211-
const sdk = makeSDK(async function* () {
211+
const sdk = makeSDK(async function*() {
212212
yield* [];
213213
throw new Error('API Error');
214214
});
215215

216216
await handler({ SDK: sdk });
217217

218218
expect(console.table).not.toHaveBeenCalled();
219-
expect(yargs.exit).toHaveBeenCalledWith(99);
219+
expect(exitMock).toHaveBeenCalledWith(99);
220220
});
221221
});
222222

__tests__/commands/apps/apps.show.test.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@ import { Client } from '@vonage/server-client';
1414
import { mockConsole } from '../../helpers.js';
1515
import { faker } from '@faker-js/faker';
1616

17-
const yargs = { exit: jest.fn() };
17+
const exitMock = jest.fn();
18+
const yargs = jest.fn().mockImplementation(() => ({ exit: exitMock }));
19+
1820
jest.unstable_mockModule('yargs', () => ({ default: yargs }));
1921

2022
const { handler } = await import('../../../src/commands/apps/show.js');
2123

2224
describe('Command: vonage apps', () => {
2325
beforeEach(() => {
2426
mockConsole();
25-
yargs.exit.mockReset();
27+
exitMock.mockReset();
2628
});
2729

2830
test('Will display the basic application details', async () => {
@@ -39,7 +41,7 @@ describe('Command: vonage apps', () => {
3941
},
4042
};
4143

42-
await handler({id: app.id, SDK: sdkMock});
44+
await handler({ id: app.id, SDK: sdkMock });
4345
expect(console.log).toHaveBeenCalledTimes(2);
4446

4547
expect(console.log).toHaveBeenNthCalledWith(
@@ -67,7 +69,7 @@ describe('Command: vonage apps', () => {
6769
},
6870
};
6971

70-
await handler({config: {cli: {appId: app}}, SDK: sdkMock, json: true});
72+
await handler({ config: { cli: { appId: app } }, SDK: sdkMock, json: true });
7173
expect(console.log).toHaveBeenCalledTimes(1);
7274

7375
expect(console.log).toHaveBeenNthCalledWith(
@@ -94,7 +96,7 @@ describe('Command: vonage apps', () => {
9496
},
9597
};
9698

97-
await handler({config: {cli: {appId: app}}, SDK: sdkMock, yaml: true});
99+
await handler({ config: { cli: { appId: app } }, SDK: sdkMock, yaml: true });
98100

99101
expect(console.log).toHaveBeenNthCalledWith(
100102
1,
@@ -120,7 +122,7 @@ describe('Command: vonage apps', () => {
120122
},
121123
};
122124

123-
await handler({config: {cli: {appId: app}}, SDK: sdkMock});
125+
await handler({ config: { cli: { appId: app } }, SDK: sdkMock });
124126

125127
expect(console.log).toHaveBeenNthCalledWith(
126128
3,
@@ -150,7 +152,7 @@ describe('Command: vonage apps', () => {
150152
},
151153
};
152154

153-
await handler({config: {cli: {appId: app}}, SDK: sdkMock});
155+
await handler({ config: { cli: { appId: app } }, SDK: sdkMock });
154156

155157
expect(console.log).toHaveBeenNthCalledWith(
156158
3,
@@ -182,7 +184,7 @@ describe('Command: vonage apps', () => {
182184
},
183185
};
184186

185-
await handler({config: {cli: {appId: app}}, SDK: sdkMock});
187+
await handler({ config: { cli: { appId: app } }, SDK: sdkMock });
186188
expect(console.log).toHaveBeenNthCalledWith(
187189
3,
188190
[
@@ -209,7 +211,7 @@ describe('Command: vonage apps', () => {
209211
},
210212
};
211213

212-
await handler({config: {cli: {appId: app}}, SDK: sdkMock});
214+
await handler({ config: { cli: { appId: app } }, SDK: sdkMock });
213215
expect(console.log).toHaveBeenNthCalledWith(
214216
3,
215217
[
@@ -236,7 +238,7 @@ describe('Command: vonage apps', () => {
236238
},
237239
};
238240

239-
await handler({config: {cli: {appId: app}}, SDK: sdkMock});
241+
await handler({ config: { cli: { appId: app } }, SDK: sdkMock });
240242
expect(console.log).toHaveBeenNthCalledWith(
241243
3,
242244
[
@@ -262,7 +264,7 @@ describe('Command: vonage apps', () => {
262264
},
263265
};
264266

265-
await handler({config: {cli: {appId: app}}, SDK: sdkMock});
267+
await handler({ config: { cli: { appId: app } }, SDK: sdkMock });
266268
expect(console.log).toHaveBeenNthCalledWith(
267269
3,
268270
[
@@ -322,7 +324,7 @@ describe('Command: vonage apps', () => {
322324
},
323325
};
324326

325-
await handler({config: {cli: {appId: app}}, SDK: sdkMock});
327+
await handler({ config: { cli: { appId: app } }, SDK: sdkMock });
326328
expect(console.log).toHaveBeenNthCalledWith(
327329
3,
328330
[
@@ -383,7 +385,7 @@ describe('Command: vonage apps', () => {
383385
},
384386
};
385387

386-
await handler({id: app.id, SDK: sdkMock});
388+
await handler({ id: app.id, SDK: sdkMock });
387389

388390
expect(console.log).toHaveBeenNthCalledWith(
389391
3,

0 commit comments

Comments
 (0)