Giter VIP home page Giter VIP logo

stub-azure-function-context's People

Contributors

bartlomiejmont avatar dependabot[bot] avatar dhensby avatar katrinsharp avatar kellybennett avatar naktibalda avatar semantic-release-bot avatar w0rldart avatar willmorgan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

stub-azure-function-context's Issues

How to pass context state?

Hi,

consider having a function that makes a call to an external database such as Cosmos DB. In the business logic I plan to have an abstract database class for which I can build my own in-memory implementation for testing.

When I run a test the function needs to know if it should use CosmosDB as backend or the in-memory implementation for testing.

My idea was to evaluate "context.state.testing" for this, however I don't seem to be able to set this.

Return type for functionRunner

Currently the functionRunner has a return type of Promise<any>.
This results in a few typescript-eslint errors:

Assigning result :
Screenshot 2023-06-15 at 10 57 23

Trying to type with Promise<Context> :
Screenshot 2023-06-15 at 11 01 02

For now we've got around this by adding an overload to our project:

import * as stubAzureFunctionContext from 'stub-azure-function-context';

declare module 'stub-azure-function-context' {
  export function functionRunner(
    azFunction: AzureFunction,
    bindingDefinitions?: stubAzureFunctionContext.BindingDefinition[] | string,
    bindingData?: Record<string, stubAzureFunctionContext.Binding>,
    augmentContext?: stubAzureFunctionContext.AugmentContextCallback,
  ): Promise<Context>;
}

It'd be ideal if the type were narrowed in the package itself. Is there a reason it's currently any? Is Context a sufficient type?

Document route bindings

Struggling to work out how to pass routing parameters, any chance of a documentation update to show this?

When binding definitions in a test file will differ from function.json definitions?

First, appreciate the time you guys spent to craft this. Very thorough implementation of Azure protocol.

I'm probably missing something but specifying binding definitions in the test file seems redundant to me. Since I'm testing some function I really want binding definitions to be the same as in the function.json because that's how Azure runtime will invoke my function.

The question is: what's the valid scenario where I may want to override binding definitions configured in function.json? I'm thinking about adding a little helper which would parse and load relevant bits from the config file, so that a user only needs to provide a trigger object.

http binding - route property

https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-http-webhook-trigger?tabs=python-v2%2Cin-process%2Cfunctionsv2&pivots=programming-language-javascript#customize-the-http-endpoint

  {
      "bindings": [
      {
          "type": "httpTrigger",
          "name": "req",
          "direction": "in",
          "methods": [ "get" ],
          "route": "products/{category:alpha}/{id:int?}"
      },
      {
          "type": "http",
          "name": "res",
          "direction": "out"
      }
      ]
  }
  module.exports = async function (context, req) {
  
      var category = context.bindingData.category;
      var id = context.bindingData.id;
      var message = `Category: ${category}, ID: ${id}`;
  
      context.res = {
          body: message;
      }
  }

I've got simular code as in the link above but using functionRunner context.bindingData.id; remains undefined. is this supported in the lib ? It was working in the prevous version ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.