feat: add simple Express app with /hello endpoint and tests
This commit is contained in:
24
tests/e2e/e2e.test.js
Normal file
24
tests/e2e/e2e.test.js
Normal 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');
|
||||
});
|
||||
});
|
||||
10
tests/integration/app.test.js
Normal file
10
tests/integration/app.test.js
Normal 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');
|
||||
});
|
||||
});
|
||||
7
tests/unit/greeting.test.js
Normal file
7
tests/unit/greeting.test.js
Normal file
@@ -0,0 +1,7 @@
|
||||
const { getGreeting } = require('../../src/greeting');
|
||||
|
||||
describe('getGreeting', () => {
|
||||
it('returns the hello world message', () => {
|
||||
expect(getGreeting()).toBe('Hello world');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user