Giter Site home page Giter Site logo

Comments (4)

rauchg avatar rauchg commented on May 13, 2024

I wrote test-listen to make the job of passing a http server (as the one that could be returned by serve(async (req, res) => {}) from micro), and make it listen on a random ephemeral port.

Using ava:

import test from 'ava';
import listen from 'test-listen';

test('it works', async t => {
  // initialize `srv` using `serve` from `micro` first!
  const url = await listen(srv);
  t.ok(/http:\/\/localhost:\d+/.test(url));
  const data = await request(url);
  t.same('1', data);
});

Example:
https://github.com/zeit/test-listen/blob/master/test/index.js#L9

from micro.

Morriz avatar Morriz commented on May 13, 2024

Tnx! But than I would have to rewrite my code to fit the test...that's not what you meant, right?

Your example shows a simple export:

import {send} from 'micro-core'

export default async function(req, res) {
  send(res, 200, 'Ready!')
}

Which is served using the micro cli. So why use the micro cli at all if we have to write tests that consume serve'd functions?

I am disliking the convenience abstraction more and more...it obfuscates stuff and does not educate people, and it leads to maintenance you don't want

Why not just put out a great manual/stack on how to set it up without micro?

On 18 mei 2016, at 18:50, Guillermo Rauch [email protected] wrote:

I wrote test-listen to make the job of passing a http server (as the one that could be returned by serve(async (req, res) => {}) from micro), and make it listen on a random ephemeral port.

Using ava:

import test from 'ava';
import listen from 'test-listen';

test('it works', async t => {
// initialize srv using serve from micro first!
const url = await listen(srv);
t.ok(/http://localhost:\d+/.test(url));
const data = await request(url);
t.same('1', data);
});
Example:
https://github.com/zeit/test-listen/blob/master/test/index.js#L9 https://github.com/zeit/test-listen/blob/master/test/index.js#L9

You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub #36 (comment)

from micro.

Morriz avatar Morriz commented on May 13, 2024

Nevermind, I figured it out...I can just start it with serve(listen(... in the test itself...

would be nice to have it in the readme tho ;)

from micro.

rauchg avatar rauchg commented on May 13, 2024

@Morriz I agree it would be nice. Also having a complete project example repository with tests.

from micro.

Related Issues (20)

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.