1.1.16 • Published 8 months ago

@natlibfi/fixugen-http-server v1.1.16

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

Generate unit tests for HTTP servers with fixugen

NPM Version Node Version

Generates unit tests with fixugen and chai-http. Starts a HTTP server which is tested with generic HTTP request and response expectations.

Uses fixugen's useMetadataFile so your fixture directories must contain metadata.json file.

Usage

import generateTests from '@natlibfi/fixugen-http-server';
import startApp from './app';

generateTests({
  callback: () => startApp(),
  path: [__dirname, '..', '..', 'test-fixtures', 'app']
});

Configuration

An array property requests must be present in metadata.json file. It supports the following properties:

  • status: HTTP status code (Number). Mandatory.
  • method: HTTP method in lowercase. Mandatory.
  • path: URL path. Defaults to /
  • requestHeaders: An object representing requests headers.
  • responseHeaders: An object representing response headers.

This configuration is also passed to the callback as the property requests.

Request and response payloads

The fixture directory for each unit test can have request- and response payload fixtures which must match the following filename pattern: /^request[0-9]+ /^response[0-9]+

Formatting the response

Pass a callback to the exported function to format response headers and payload:

generateTests({
  formatResponse,
  callback: () => startApp(),
  path: [__dirname, '..', '..', 'test-fixtures', 'app']
});

function formatResponse(headers, payload) {
  const newHeaders = doSomethingWithHeaders();
  return { payload, headers: newHeaders };
}

Where [0-9]+ denotes the index number of the fixture (Requests and responses are mocked in that order).

License and copyright

Copyright (c) 2020, 2022-2024 University Of Helsinki (The National Library Of Finland)

This project's source code is licensed under the terms of MIT or any later version.

1.1.16-alpha.1

8 months ago

1.1.15-alpha.1

9 months ago

1.1.16

8 months ago

1.1.15

9 months ago

1.1.14-alpha.1

10 months ago

1.1.13-alpha.1

10 months ago

1.1.12

12 months ago

1.1.14

10 months ago

1.1.13

10 months ago

1.1.12-alpha.1

12 months ago

1.1.11

1 year ago

1.1.11-alpha.1

1 year ago

1.1.10

1 year ago

1.1.10-alpha.3

1 year ago

1.1.10-alpha.2

1 year ago

1.1.9-alpha.1

1 year ago

1.1.9

1 year ago

1.1.8-alpha.1

2 years ago

1.1.8

2 years ago

1.1.7

2 years ago

1.1.7-alpha.1

2 years ago

1.1.6

2 years ago

1.1.6-alpha.1

2 years ago

1.1.4-alpha.1

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.2

2 years ago

1.1.2-alpha.3

2 years ago

1.1.2-alpha.1

2 years ago

1.1.2-alpha.2

2 years ago

1.1.1

2 years ago

1.1.0-alpha.1

2 years ago

1.1.0

2 years ago

1.0.5

3 years ago

1.0.5-alpha.1

3 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago