Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@egomobile/http-supertest

Package Overview
Dependencies
Maintainers
5
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@egomobile/http-supertest

Sets up common and powerful test event listener for @egomobile/http-server with supertest under the hood.

  • 0.7.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
decreased by-77.78%
Maintainers
5
Weekly downloads
 
Created
Source

npm PRs Welcome

@egomobile/http-supertest

Sets up common and powerful test event listener for @egomobile/http-server with supertest under the hood.

Table of contents

Install []

Execute the following command from your project folder, where your package.json file is stored:

npm install --save @egomobile/http-supertest

Usage []

Quick example []

import createServer from "@egomobile/http-server";
import { setupTestEventListener } from "@egomobile/http-supertest";

const app = createServer();

// s. https://github.com/egomobile/node-http-server/wiki/Testing
app.controllers();

// register `test` event: https://egomobile.github.io/node-http-server/interfaces/IHttpServer.html#on
setupTestEventListener({
  server: app,
});

await app.test();

Filters []

If you defined a lot of tests and want to skip some of them, you can use EGO_TEST_FILTER environment variable.

It can hold a non-empty value, that is a Filtrex expression.

If it returns a truthy value, the underlying test will be executed.

Beside shipped-in functions and constants, the module also provides the following enhancements:

Functions:

SignatureDescriptionExample
all(value, ...subStrings): boolChecks if all substrings are part of value.all("foo bar buzz", "bar", "buzz")
any(value, ...subStrings): boolChecks if at least one substring is part of value.any("foo bar buzz", "test", "bar")
endsWith(value, suffix): boolChecks if a string ends with a suffix.endsWith("Test string", " string")
float(value): number|falseConverts a string to a float.float("12.3") == 12.3
indexOf(value): numberReturns the zero-based index of a substring inside a string, and -1 if it is not found.indexOf("666.0", ".") == 3
int(value): number|falseConverts a string to an integer.int("10.0") == 10
isNaN(value, float = true): boolChecks if a value cannot be parsed as number.isNaN("is not a really number")
join(sep, ...values[]): boolHandles values as strings an join them with a separator.join("+", "a", "b", " c") == "a+b+ c"
norm(value): stringNormalizes a string for better comparison: creates lower case version, trims it and replace special characters like umlauts or whitespacenorm("  A tesT String: Ä    ö Ü ß ") == "a test string: ae oe ue ss"
log(value [, returnValue = false]): anyLogs a value.log(methodName) or methodName == "getAllUsers"
lower(value): stringConverts string to lower case chars.lower("ThIs Is A tEsTsTrInG") == "this is a test string"
regex(value, pattern [, flags = "i"]): boolTests a string for a regular expression.not regex(methodName, "^(ZZZ)(\\s)(-)")
str(value): stringConverts a value to a safe string.str(1) == "1"
startsWith(value, prefix): boolChecks if a string starts with a prefix.startsWith("Test string", "Test ")
trim(value): stringRemoves leading and ending whitespace characters from a string.trim(" Test String ") === "Test String"
trimEnd(value): stringRemoves ending whitespace characters from a string.trimEnd(" Test String ") === " Test String"
trimStart(value): stringRemoves leading whitespace characters from a string.trimStart(" Test String ") === "Test String "
upper(value): stringConverts string to upper case chars.upper("ThIs Is A tEsTsTrInG") == "THIS IS A TEST STRING"

Constants:

Name: typeDescriptionExample
context: stringThe context in what the test is executed.context == "controller"
countFailure: numberThe current number of failed tests.countFailure > 0
description: stringThe description of the test.any(description, "foo")
escapedQuery: stringThe escaped query string.a=foo%20bar&b=buzz
escapedRoute: stringThe escaped route of the endpoint.escapedRoute == "/foo%20bar/buzz"
file: stringThe full path of the file.file == "/path/to/endpoints/file/index.ts"
group: stringThe name of the current test group, which is usually the name of the controller class.group == "MyControllerClass
httpMethod: stringUpper case HTTP method.httpMethod in ("POST", "GET", "PATCH", "DELETE")
methodName: stringThe name of the controller method, that is executed by the test.methodName == "getAllUsers
parameters: stringThe JSON string of the object, with all URL parameters.parameters == "{\"user_id\":\"foo\"}"
query: stringThe JSON string of the object, with all query parameters.query == "{\"a\":\"foo\"}"
route: stringThe unescaped route of the endpoint.route == "/foo bar/buzz"

Credits []

The module makes use of:

Documentation []

The API documentation can be found here.

Keywords

FAQs

Package last updated on 26 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc