@netlify/netlitest-helper

This is a test helper library built around the jest test runner and written in Typescript. The library provides helper methods to make writing tests as simple as possible, and to automatically inject variables for the various components necessary to make requests.

Usage no npm install needed!

<script type="module">
  import netlifyNetlitestHelper from 'https://cdn.skypack.dev/@netlify/netlitest-helper';
</script>

README

Netlitest-Helper

This is a test helper library built around the jest test runner and written in Typescript. The library provides helper methods to make writing tests as simple as possible, and to automatically inject variables for the various components necessary to make requests.

Available Methods

testBuilder

This is a generic method that accepts a javascript object with the following shape:

interface testOptions {
  component: string;
  method?: string;
  path: string;
  payload?: object;
  status?: number;
  snapshotResponsePayload?: boolean;
  snapshotResponseHeaders?: boolean;
  maxResponseTimeMS?: number;
  expectedHeadersValues?: object;
  name?: string;
}

Local Development

Below is a list of commands you will probably find useful.

npm start or yarn start

Runs the project in development/watch mode. netlitest-helper will be rebuilt upon changes. TSDX has a special logger for you convenience. Error messages are pretty printed and formatted for compatibility VS Code's Problems tab.

npm run build or yarn build

Bundles the package to the dist folder. The package is optimized and bundled with Rollup into multiple formats (CommonJS, UMD, and ES Module).

npm test or yarn test

Runs the test watcher (Jest) in an interactive mode. By default, runs tests related to files changed since the last commit.