This repository is a template for creating Node.js API autotest components as part of the KubeRocketCI platform solution.
- 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.
-
Add your tests to the
test/directory. For example, createtest/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.
-
Create a
package.jsonand 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" } } -
Install dependencies:
npm install
-
Run tests locally:
npm test
- 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
makecommands are used in deploy pipelines (seeMakefile). make e2ewill install dependencies and run all tests.
- Use SuperTest for HTTP API testing.
- Organize tests by endpoint/resource.
- Keep tests clear, maintainable, and aligned with your OpenAPI spec.