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.4k stars 577 forks source link

单元测试中invoke 、HTTPTrigger 传query无效 #712

Closed yoodu closed 3 years ago

yoodu commented 4 years ago

函数定义如下,单元测试执行结果为:{"message":"test"} ,而通过线上调用正常。

  @Func('account.test')
  async test() {
    const { pName, mail } = this.ctx.query
    console.log('test', pName) //结果为test undefined

    return {
      message: 'test',
      pName,
      mail,
    }
  }

index.text.ts 如下

import { invoke } from '@midwayjs/serverless-invoke'
import { HTTPTrigger } from '@midwayjs/serverless-fc-trigger'
describe('/test/index.test.ts', () => {
  it('test', async () => {
    const result =  await invoke({
        functionName: 'test',
        data: [
          new HTTPTrigger({
            path: '/account/test',
            method: 'GET',
            query: { pName: 'aaa', mail: 'f@s.com' },
          }),
        ],
      })
        assert.equal(result.vcode.length, 6)
  })
czy88840616 commented 3 years ago

@yoodu 参考 https://github.com/midwayjs/cli/blob/master/packages/faas-cli-plugin-invoke/test/http.test.ts

yoodu commented 3 years ago

还是一样不行

czy88840616 commented 3 years ago

我们单测是过的,没问题的,贴下你的仓库?