shot

2018-11-08 admin

shot是什么

什么是shot,Injects a fake HTTP request/response into a node HTTP server

shot使用教程帮助文档

shot Logo

Injects a fake HTTP request/response into a node HTTP server for simulating server logic, writing tests, or debugging. Does not use a socket connection so can be run against an inactive server (server not in listen mode).

Build Status

Lead Maintainer: Matt Harrison

Example

// Load modules

const Http = require('http');
const Shot = require('shot');

// Declare internals

const internals = {};

internals.main = async function () {

    const dispatch = function (req, res) {

        const reply = 'Hello World';
        res.writeHead(200, { 'Content-Type': 'text/plain', 'Content-Length': reply.length });
        res.end(reply);
    };

    const server = Http.createServer(dispatch);

    const res = await Shot.inject(dispatch, { method: 'get', url: '/' });
    console.log(res.payload);
};

internals.main();

Note how server.listen is never called.

API

See the API Reference

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。

转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]

本文地址:https://www.javascriptcn.com/read-44893.html

文章标题:shot

回到顶部