to

Try It


Auto Test via axios inside Node.js itself

npm install axios

Promise based HTTP client for the browser and node.js

// Automation Testing
console.log("=== Automation Testing ===");

const axios = require('axios');

axios.post('http://localhost/latex2svg', {
  latex: '$$\frac{1}{2}$$'
}).then(res => {
    console.log(`Response.data : `, res.data);
});

Requester (Sublime Text Package)

HTTP Requester, even support GraphQL for automation tests. Text based, fast and portable.

https://requester.org/#documentation

Browser Web Fetch


Using Fetch

index.html

function latex2svg(latex) {

  fetch('/.netlify/functions/latex2svg', {
      method: 'POST',
      body: JSON.stringify(latex),
      headers: new Headers({
        'Content-Type': 'application/json'
      }),
      mode: 'cors' // no-cors, cors, *same-origin
    }).then(response => {
      return response.json();
    }).then(json => {
      container = document.getElementById('svg_container');
      container.innerHTML = json.svg;
    }).catch( error => {
      console.log("Something Wrong");
   });;
}

latex2svg({ "latex" : '\$\$\\LaTeX \\frac{1}{3}\$\$'});
mode: no-cors

no-cors is required to cross origin access when tring to load my service directly in your own html.

Netlify Deployment


Free serverless web service

GitHub (Push = Auto Deploy)

git push and deploy, np at all.

netlify-lambda functions

Each lambda function is a module. Build command is required for lambda functions.
npm run netlify-lambda build functions

functions/lambda.js

source of lambda function, not compiled.
exports.handler = function(event, context, callback) {
   // event.body
   // context for dev/prod environment info
   callback(null, {
     statusCode: 200,
     body: {svg: "<svg></svg>"}
   });
}

netlify.toml

[build]
    function = "lambda" // the compiled path of lambda functions

Tests


nodemon app.js 
  or 
npm run start

axios to send the test requests after launch automatically.
It's possible to write the automation tests with assert too.

Sublime Text with Requester(pacakge)


tests.pyr (ctrl+r to send requests/ cmd+r to resend)
## localhost node app.js test
requests.post('http://localhost/.netlify/functions/latex2svg',
    json = {"latex": "$$\frac{}$$"})

## localhost netlify-lambda serve functions test.
requests.post('http://localhost:9000/.netlify/functions/latex2svg',
    json = {"latex": "$$\\frac{1}{6}$$"})

## netlify-lambda function server test
requests.post('https://rintaroutw-latex2svg.netlify.com/.netlify/functions/latex2svg',
    json = {"latex": "$$\\frac{1}{6}$$"})