Giter Site home page Giter Site logo

azure-functions-node-harness's Introduction

πŸ‘¨β€πŸ’» Chris(topher) Anderson

Howdy! πŸ‘‹

  • πŸ’¬ Ask me about JavaScript, serverless, NoSQL, PM culture, project ops, etc.
  • πŸ“« How to reach me: DM me on twitter
  • πŸ˜„ Pronouns: he/him/they
  • :octocat: Fun fact: I've got 3 chonky cat children 😼😽😾

azure-functions-node-harness's People

Contributors

christopheranderson avatar jsturtevant avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

jsturtevant

azure-functions-node-harness's Issues

Handle log tracing level functions

Currently if you have the following in your function under test:

context.log.info("Invalid response");

you will get an error:

context.log.info is not a function

Handle for:

  • error(message)
  • warn(message)
  • info(message)
  • verbose(message)

Parallel async triggers

Hey,

So, I have this function.

const delay = time => new Promise(resolve => setTimeout(resolve, time))

module.exports = async (context, req) => {
  await delay(500)

  const { query: { name } } = req

  if (name) {
    context.res = {
      status: 200,
      body: `Hello, ${name}`
    }
  } else {
    context.res = {
      status: 400,
      body: 'Name missing'
    }
  }

  context.done()
}

delay puts the function to sleep for a bit, before processing. Just trying out async capabilities of Azure Functions.

And here are my ava tests.

const test = require('ava')
const func = require('azure-functions-node-harness')

test('valid', async t => {
  const helloWorld = func('HelloWorld')

  const name = 'Ali'

  const context = await helloWorld.invokeHttpTrigger({
    query: {
      name
    }
  })

  const { res: { body, status } } = context

  t.deepEqual(status, 200)
  t.deepEqual(body, `Hello, ${name}`)
})

test('invalid', async t => {
  const helloWorld = func('HelloWorld')

  const context = await helloWorld.invokeHttpTrigger()

  const { res: { body, status } } = context

  t.deepEqual(status, 400)
  t.deepEqual(body, 'Name missing')
})

When these tests are ran in parallel, which is the default ava behavior, valid fails claiming that status is 400, while the test expects it to be 200.

But if I run the tests serially with test.serial(), they both pass just fine.

How can I run them in parallel, and make sure they don't overlap? Or whatever is going on right now.

Thanks!

Use funtion.json to figure out trigger type

Use function.json to figure out trigger type. This would be useful for http context scenarios. One possibility is to load the sample.dat and pass it to unit test as default request body.

Add functionality to generate a http request

A user currently has to generate all of the following. Instead give them a helper to pass just the body.

Properties on request object (https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-node#http-triggers-and-bindings):

  • body An object that contains the body of the request.
  • headers An object that contains the request headers.
  • method The HTTP method of the request.
  • originalUrl The URL of the request.
  • params An object that contains the routing parameters of the request.
  • query An object that contains the query parameters.
  • rawBody The body of the message as a string.

Sample helper would be something like (not complete example):

httpRequest: function(body){
        return{
            method: "POST",
            body:body,
            rawBody: JSON.stringify(body),
        };
    }

Could potentially fill load info like method from function.json

Add more trigger binding support

Add functionality and tests for all the different trigger bindings where it makes sense. Here is a list from the functions docs:

  • Schedule Azure Functions
  • HTTP (REST or webhook) Azure Functions
  • Blob Storage Azure Storage
  • Events Azure Event Hubs
  • Queues Azure Storage
  • Queues and topics Azure Service Bus
  • Storage tables Azure Storage
  • SQL tables Azure Mobile Apps
  • No-SQL DB Azure DocumentDB
  • Push Notifications Azure Notification Hubs
  • Twilio SMS Text Twilio
  • SendGrid email

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.