tesugen

1.1.3 • Public • Published

Tesugen

Version 1.1.3

Setup your API-testing framework easily.

Use tesugen to setup API-testing framework in Typescript whenever you need it.

Make sure that you are running latest stable NodeJS (>= 14.6.0 LTS) and npm (>=7.6.1) version.

Table of Contents

Installation & Usage


Navigate to desired directory and run:

npx tesugen

You will be asked to choose your package manager, test runner, name your project and you will be ready to go.

Project-setup: Jest as selected test runner


Project-setup: TestyTS as selected test runner


Structure: Jest


  • src
    • routes
      • testRoutes.ts - Initial routes setup (Endpoints which will be the target)
    • client.ts - Initial test client setup
    • setup.ts - Initial test controller setup
    • testAgent.ts - Superagent initial setup
  • test - test folder where you can organize your tests
  • validation - validateResponse function for aditional contract/integration testing
  • .env - local environment file
  • .gitignore
  • index.ts
  • jest.config.js - Initial Jest config file (Generated only if the selected runner is Jest)

Create desired npm scripts to run specific tests:

"scripts": {
    "test": "jest ./test/functional/example",
    "test:basic": "jest ./test/basic/example"
  },

If you run jest in project root, Jest will by default look for all files with *.test.ts and run them if possible. To have everything running smoothly, testEnvironment and preset in jest.config.jest should be set by default:

preset: 'ts-jest',
testEnvironment: 'node',

Test reports will be generated in ./html-report in HTML format via Jest-html-reporters. Reporter can be configured in jest.config.js file. Jest supports multiple reporters. You can even create own custom reporter.

Structure: TestyTS


  • src
    • routes
      • testRoutes.ts - Initial routes setup (Endpoints which will be the target)
    • client.ts - Initial test client setup
  • test - test folder where you can organize your tests
  • validation - validateResponse function for aditional contract/integration testing
  • .env - local environment file
  • .gitignore

Create desired npm scripts to run specific tests:

"scripts": {
    "test": "testyts",
    "test:basic": "testyts ./test/basic/example"
  },

Test client


Test client can be configured and reused with no limitations. For testing multiple services, feel free to configure TestController to have multiple TestClient properties for every desired service.

Test client has four basic example methods for four HTTP methods: GET, POST, PUT and DELETE.

Class validator


Function located in ./validation/responseValidation.ts can be used for extended contract/integration testing. Make sure to create proper models according to desired response from your project documentation. To speed this process up, use any JSON to TS generator online to quickly convert JSON to TS interfaces/classes. Example: json2ts. Follow Class-validator documentation. Your tests will look like this:

expect(validateResponse(ProfileExampleResponse).toBeTruthy();

Base URL


is stored in your local .env file. This is also highly conigurable, you can adjust this to your project needs. Test credentials can also be stored in local .env file and be used for authorized endpoints. Supertest Agent supports setting headers:

supertest.agent(String(process.env.BASE_URL)).set({'Authorization':`${bearerToken}`}); 

Dotenv file example


BASE_URL=https://www.aaa.ccc

License


Package Sidebar

Install

npm i tesugen

Weekly Downloads

2

Version

1.1.3

License

MIT

Unpacked Size

23.5 kB

Total Files

23

Last publish

Collaborators

  • mladenr