Repository: Yoctol/bottender (ts)

Issue:
should not print handlerDidEnd in ConsoleBot fallback mode
```
You > ...
Bot > ...
Bot > handlerDidEnd: []
```

Pull request:
fix ConsoleBot handlerDidEnd
fix #251

Patch:
diff --git a/src/context/ConsoleContext.js b/src/context/ConsoleContext.js
index c170cdae..368d4762 100644
--- a/src/context/ConsoleContext.js
+++ b/src/context/ConsoleContext.js
@@ -16,6 +16,11 @@ type Options = {|
   fallbackMethods: boolean,
 |};
 
+const methodBlackList = [
+  'then', // promise
+  'handlerDidEnd', // context lifecycle
+];
+
 export default class ConsoleContext extends Context implements PlatformContext {
   _client: ConsoleClient;
   _event: ConsoleEvent;
@@ -36,8 +41,8 @@ export default class ConsoleContext extends Context implements PlatformContext {
           if (target[key]) {
             return target[key];
           }
-          // should return undefined when check if it is a promise
-          if (key === 'then') return;
+
+          if (methodBlackList.some(method => method === key)) return;
           return async (...args) => {
             await target._methodMissing(key, args);
           };


Test patch:
diff --git a/src/context/__tests__/ConsoleContext.spec.js b/src/context/__tests__/ConsoleContext.spec.js
index e2d88386..64b8eba1 100644
--- a/src/context/__tests__/ConsoleContext.spec.js
+++ b/src/context/__tests__/ConsoleContext.spec.js
@@ -105,6 +105,13 @@ describe('method missing', () => {
 
     expect(context.isHandled).toBe(true);
   });
+
+  it('should not proxy blacklisted methods', async () => {
+    const { context } = setup({ fallbackMethods: true });
+
+    expect(context.handlerDidEnd).toBeUndefined();
+    expect(context.then).toBeUndefined();
+  });
 });
 
 describe('#typing', () => {