feat: add simple Express app with /hello endpoint and tests

This commit is contained in:
coaxial
2025-10-23 15:14:23 +02:00
committed by coaxial (aider)
parent 928c1afacd
commit 8bf16b0ac2
5 changed files with 63 additions and 0 deletions

24
tests/e2e/e2e.test.js Normal file
View File

@@ -0,0 +1,24 @@
const axios = require('axios');
const app = require('../../src/server');
let server;
let baseURL;
beforeAll(done => {
server = app.listen(0, () => {
const { port } = server.address();
baseURL = `http://127.0.0.1:${port}`;
done();
});
});
afterAll(done => {
server.close(done);
});
describe('E2E GET /hello', () => {
it('responds with Hello world', async () => {
const res = await axios.get(`${baseURL}/hello`);
expect(res.status).toBe(200);
expect(res.data).toBe('Hello world');
});
});

View File

@@ -0,0 +1,10 @@
const request = require('supertest');
const app = require('../../src/server');
describe('GET /hello', () => {
it('should return Hello world', async () => {
const res = await request(app).get('/hello');
expect(res.statusCode).toBe(200);
expect(res.text).toBe('Hello world');
});
});

View File

@@ -0,0 +1,7 @@
const { getGreeting } = require('../../src/greeting');
describe('getGreeting', () => {
it('returns the hello world message', () => {
expect(getGreeting()).toBe('Hello world');
});
});