Skip to content

KubeRocketCI/template-node-autotests-empty

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

Node.js Autotest Project Template (KubeRocketCI)

This repository is a template for creating Node.js API autotest components as part of the KubeRocketCI platform solution.

Project Overview

  • Designed for API contract and integration testing using Jest and SuperTest.
  • Intended for use in CI/CD deploy pipelines and local development.
  • Template includes: README.md, .gitignore, Makefile.

Quick Start

  1. Add your tests to the test/ directory. For example, create test/hello.test.js:

    // API contract test for /api/hello endpoint
    const request = require('supertest');
    const baseURL = 'https://restful-api-run0-team0-backend-dev.development.krci-dev.cloudmentor.academy';
    
    describe('/api/hello API', () => {
      describe('GET /api/hello', () => {
        it('should return 200 and a string', async () => {
          const res = await request(baseURL).get('/api/hello');
          expect(res.statusCode).toBe(200);
          expect(typeof res.body === 'string' || typeof res.text === 'string').toBe(true);
        });
      });
    });
    
    // Assumptions:
    // - No authentication or parameters required for /api/hello as per the OpenAPI spec.
  2. Create a package.json and add your dependencies (e.g., SuperTest, Jest) if not already present. You can generate it with:

    npm init -y
    npm install --save-dev supertest jest

    Example package.json (minimal working example):

    {
      "name": "nodejs-autotests",
      "version": "1.0.0",
      "scripts": {
        "test": "jest"
      },
      "devDependencies": {
        "jest": "^29.0.0",
        "supertest": "^6.3.3"
      }
    }
  3. Install dependencies:

    npm install
  4. Run tests locally:

    npm test

CI/CD Usage

  • In CI/CD pipelines, the Makefile will call these npm commands. If your test workflow requires different commands, update the Makefile accordingly to match your test setup.
  • The make commands are used in deploy pipelines (see Makefile).
  • make e2e will install dependencies and run all tests.

Recommendations

  • Use SuperTest for HTTP API testing.
  • Organize tests by endpoint/resource.
  • Keep tests clear, maintainable, and aligned with your OpenAPI spec.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published