Skip to content

Commit

Permalink
Merge 4deb3a5 into d8b6233
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyanziano committed Apr 23, 2019
2 parents d8b6233 + 4deb3a5 commit 1bfe0e5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [client] Fixed issue where tab icon glyphs weren't working on Mac in PR [1428](https://github.com/Microsoft/BotFramework-Emulator/pull/1428)
- [client] Fixed issue where cancelling out of opening a transcript was creating a broken livechat window in PR [1441](https://github.com/Microsoft/BotFramework-Emulator/pull/1441)
- [client] Fixed invisible scrollbar styling in log panel in PR [1442](https://github.com/Microsoft/BotFramework-Emulator/pull/1442)
- [main] Fixed issue where opening a livechat or bot via protocol wasn't working because ngrok wasn't being started on startup in PR [1446](https://github.com/Microsoft/BotFramework-Emulator/pull/1446)

## Removed
- [main] Removed custom user agent string from outgoing requests in PR [1427](https://github.com/Microsoft/BotFramework-Emulator/pull/1427)
Expand Down
16 changes: 15 additions & 1 deletion packages/app/main/src/protocolHandler.spec.ts
Expand Up @@ -77,9 +77,13 @@ jest.mock('./settingsData/store', () => ({
},
}),
}));

let mockGetSpawnStatus = jest.fn(() => ({ triedToSpawn: true }));
const mockRecycle = jest.fn(() => null);
const mockEmulator = {
ngrok: {
getSpawnStatus: () => ({ triedToSpawn: true }),
getSpawnStatus: () => mockGetSpawnStatus(),
recycle: () => mockRecycle(),
},
};
jest.mock('./emulator', () => ({
Expand Down Expand Up @@ -134,6 +138,8 @@ describe('Protocol handler tests', () => {
statusCode: 200,
body: '["activity1", "activity2", "activity3"]',
};
mockRecycle.mockClear();
mockGetSpawnStatus.mockClear();
});

afterAll(() => {
Expand Down Expand Up @@ -283,8 +289,12 @@ describe('Protocol handler tests', () => {
const overrides = { endpoint: parseEndpointOverrides(protocol.parsedArgs) };
const overriddenBot = applyBotConfigOverrides(mockOpenedBot, overrides);

// ngrok should be kick-started if it hasn't tried to spawn yet
mockGetSpawnStatus = jest.fn(() => ({ triedToSpawn: false }));

await ProtocolHandler.openBot(protocol);

expect(mockRecycle).toHaveBeenCalled();
expect(mockCallsMade).toHaveLength(2);
expect(mockCallsMade[0].commandName).toBe(SharedConstants.Commands.Bot.Open);
expect(mockCallsMade[0].args).toEqual(['path/to/bot.bot', 'someSecret']);
Expand Down Expand Up @@ -374,8 +384,12 @@ describe('Protocol handler tests', () => {
mockEndpoint.name = 'New livechat';
mockedBot.services.push(mockEndpoint);

// ngrok should be kick-started if it hasn't tried to spawn yet
mockGetSpawnStatus = jest.fn(() => ({ triedToSpawn: false }));

await ProtocolHandler.openLiveChat(protocol);

expect(mockRecycle).toHaveBeenCalled();
expect(mockCallsMade).toHaveLength(1);
expect(mockCallsMade[0].commandName).toBe(SharedConstants.Commands.Bot.RestartEndpointService);
expect(mockCallsMade[0].args).toEqual([]);
Expand Down
18 changes: 14 additions & 4 deletions packages/app/main/src/protocolHandler.ts
Expand Up @@ -202,8 +202,13 @@ export const ProtocolHandler = new class ProtocolHandlerImpl implements Protocol
const appSettings: FrameworkSettings = getSettings().framework;

if (appSettings.ngrokPath) {
const ngrokSpawnStatus = Emulator.getInstance().ngrok.getSpawnStatus();
if (!ngrokSpawnStatus.triedToSpawn || (ngrokSpawnStatus.triedToSpawn && ngrokSpawnStatus.err)) {
let ngrokSpawnStatus = Emulator.getInstance().ngrok.getSpawnStatus();
// if ngrok hasn't spawned yet, we need to start it up
if (!ngrokSpawnStatus.triedToSpawn) {
await Emulator.getInstance().ngrok.recycle();
}
ngrokSpawnStatus = Emulator.getInstance().ngrok.getSpawnStatus();
if (ngrokSpawnStatus.triedToSpawn && ngrokSpawnStatus.err) {
throw new Error(`Error while trying to spawn ngrok instance: ${ngrokSpawnStatus.err || ''}`);
}

Expand Down Expand Up @@ -304,8 +309,13 @@ export const ProtocolHandler = new class ProtocolHandlerImpl implements Protocol

const appSettings: FrameworkSettings = getSettings().framework;
if (appSettings.ngrokPath) {
const ngrokSpawnStatus = Emulator.getInstance().ngrok.getSpawnStatus();
if (!ngrokSpawnStatus.triedToSpawn || (ngrokSpawnStatus.triedToSpawn && ngrokSpawnStatus.err)) {
let ngrokSpawnStatus = Emulator.getInstance().ngrok.getSpawnStatus();
// if ngrok hasn't spawned yet, we need to start it up
if (!ngrokSpawnStatus.triedToSpawn) {
await Emulator.getInstance().ngrok.recycle();
}
ngrokSpawnStatus = Emulator.getInstance().ngrok.getSpawnStatus();
if (ngrokSpawnStatus.triedToSpawn && ngrokSpawnStatus.err) {
throw new Error(`Error while trying to spawn ngrok instance: ${ngrokSpawnStatus.err || ''}`);
}

Expand Down

0 comments on commit 1bfe0e5

Please sign in to comment.