midwayjs / midway

🍔 A Node.js Serverless Framework for front-end/full-stack developers. Build the application for next decade. Works on AWS, Alibaba Cloud, Tencent Cloud and traditional VM/Container. Super easy integrate with React and Vue. 🌈
https://www.midwayjs.org/
MIT License
7.34k stars 573 forks source link

TypeError: Cannot read property 'logger' of undefined after run "f test" in a new faas-vue project #664

Closed yoodu closed 3 years ago

yoodu commented 3 years ago

1) /test/index.test.ts should use default event: TypeError: Cannot read property 'logger' of undefined at FCRuntime.wrapperEventInvoker (node_modules/@midwayjs/fcli-plugin-invoke/node_modules/@midwayjs/serverless-fc-starter/src/runtime.ts:236:23) at /Users/fwk/Documents/_project/faas-vue/node_modules/@midwayjs/fcli-plugin-invoke/node_modules/@midwayjs/serverless-fc-starter/src/runtime.ts:43:21 at AsyncFunction. (.faas_debug_tmp/api.js:89:37) at FaaSInvokePlugin.invoke [as invokeFun] (node_modules/@midwayjs/fcli-plugin-invoke/src/index.ts:512:24) at FaaSInvokePlugin.callInvoke (node_modules/@midwayjs/fcli-plugin-invoke/src/index.ts:557:22) at CommandCore.execLiftcycle (node_modules/@midwayjs/command-core/src/core.ts:182:11) at CommandCore.invoke (node_modules/@midwayjs/command-core/src/core.ts:161:5) at /Users/fwk/Documents/_project/faas-vue/node_modules/@midwayjs/fcli-plugin-invoke/src/invoke.ts:26:5 at invokeFun (node_modules/@midwayjs/fcli-plugin-invoke/src/invoke.ts:43:31) at Context. (test/index.test.ts:8:20) [use --full-trace to display the full stack trace]

Error: /Users/fwk/.npm-global/lib/node_modules/@midwayjs/faas-cli/node_modules/mocha/bin/_mocha --require,/Users/fwk/.npm-global/lib/node_modules/@midwayjs/faas-cli/node_modules/@midwayjs/fcli-plugin-test/node_modules/ts-node/register/index.js,--extension=ts,js,--timeout=60000,--exit=true,--require=/Users/fwk/.npm-global/lib/node_modules/@midwayjs/faas-cli/node_modules/@midwayjs/fcli-plugin-test/dist/mocha-clean.js,test/index.test.ts,test/token.test.ts exit with code 1 at ChildProcess. (/Users/fwk/.npm-global/lib/node_modules/@midwayjs/faas-cli/node_modules/@midwayjs/fcli-plugin-test/src/test.ts:135:28) at Object.onceWrapper (events.js:428:26) at ChildProcess.emit (events.js:321:20) at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12) { code: 1 }

czy88840616 commented 3 years ago

似乎是本地开发没传递 context

https://github.com/midwayjs/midway/blob/serverless/packages/serverless-fc-starter/src/runtime.ts#L236

@Lxxyx 看看。

echosoar commented 3 years ago

看起来是脚手架里面的单测没有基于trigger来创建入参,我调整一下

echosoar commented 3 years ago
import { invoke } from '@midwayjs/serverless-invoke';
import { HTTPTrigger } from '@midwayjs/serverless-fc-trigger';
import assert from 'assert';
describe('/test/index.test.ts', () => {
  it('should use default event', async () => {
    const result = await invoke({
      functionName: 'index',
      data: [
        new HTTPTrigger({
          path: '/help',
          method: 'GET',
        })
      ],
    });
    // API Gateway must be get a string text
    assert(result.body === '{"message":"Hello Midway!"}');
  });
});