npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-testing-server

v1.6.1

Published

Simple Node.js server to generate .html, .json, .js, .css, .jpg, .png pages for end-to-end and API testing

Downloads

51

Readme

node-testing-server

Actions Status npm version NPM License

Simple node.js server to generate .html, .json, .js, .css, .jpg, .png pages for end-to-end and API testing

Supported versions

Node.js:

  • 10.x
  • 11.x
  • 12.x
  • 13.x
  • 14.x
  • 15.x
  • 16.x
  • 17.x
  • 18.x
  • 19.x
  • 20.x

Installation

npm install node-testing-server --save-dev

Importing and configuring

You can require node-testing-server and configure it like this:

let { nodeTestingServer } = require('node-testing-server');

// Settings for node testing server
nodeTestingServer.config = {
    hostname: 'localhost',
    port: 3001,
    logsEnabled: 0,
    pages: {
        '/test.html': `<ul class="items">
                        <li>First</li>
                        <li>Second</li>
                        <li>Third</li>
                        <li>Fourth</li>
                        <li>Fifth</li>
                        <li>Sixth</li>
                        <li>Seventh</li>
                        <li>Eighth</li>
                        <li>Ninth</li>
                        <li>Tenth</li>
                    </ul>`
    }
};

Also if you want to specify a status code that will be returned by the page:

let { nodeTestingServer } = require('node-testing-server');

// Settings for node testing server
nodeTestingServer.config = {
    hostname: 'localhost',
    port: 3001,
    logsEnabled: 0,
    pages: {
        '/test.html': {
            pageStatusCode: 201,
            pageBody: `<ul class="items">
                        <li>First</li>
                        <li>Second</li>
                        <li>Third</li>
                        <li>Fourth</li>
                        <li>Fifth</li>
                        <li>Sixth</li>
                        <li>Seventh</li>
                        <li>Eighth</li>
                        <li>Ninth</li>
                        <li>Tenth</li>
                    </ul>`
        }
    }
};

By default logs are disabled (logsEnabled is set to 0). You can set logsEnabled config to one of 3 levels:

  • 0 - logs disabled
  • 1 - partial logs are enabled - prints out:
    • incoming request METHOD, URL and outcoming response CODE
    • pages that were generated or served
  • 2 - full logs are enabled - prints out:
    • incoming request METHOD, URL and outcoming response CODE
    • pages that were generated or served
    • incoming request headers
    • response time

Usage

Start and stop server like this:

// Start node testing server
nodeTestingServer.start();

// Stop node testing server
nodeTestingServer.stop();

If you will configure the /test.html server page as described in Importing and configuring section above, and send a GET request to http://localhost:3001/test.html, then the server will return html page with:

<ul class="items">
    <li>First</li>
    <li>Second</li>
    <li>Third</li>
    <li>Fourth</li>
    <li>Fifth</li>
    <li>Sixth</li>
    <li>Seventh</li>
    <li>Eighth</li>
    <li>Ninth</li>
    <li>Tenth</li>
</ul>

There are also 2 default pre-configured pages that you can hit:

  1. Sending GET request to http://localhost:3001/ will return:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Node testing server - main page</title>
</head>
<body>
    <h1 class="title-main">Main page of node testing server</h1>
    <p>This page was constructed for testing purposes.</p>
    <ul>More info about <strong>node-testing-server</strong>:
        <li><a href="https://github.com/Marketionist/node-testing-server">on Github</a></li>
        <li><a href="https://www.npmjs.com/package/node-testing-server">on npm</a></li>
    </ul>
</body>
</html>

Note: if you want to serve your own page from http://localhost:3001/ - just create it in public/index.html in your root folder - otherwise it will be served from node_modules/node-testing-server/public/index.html

  1. Sending POST request to http://localhost:3001/post with {"test1":1,"test2":"Test text"} in the body will return a string with request headers and body:
`Incoming request headers: {"content-type":"application/json","connection":"close","content-length":"31","host":"localhost:3001"}
Incoming request body: {"test1":1,"test2":"Test text"}`

You can see live examples of node-testing-server usage in page-content-tests.js, in Protractor tests and in TestCafe tests

Thanks

If this package was helpful to you, please give it a ★ Star on GitHub