Skip to content

Commit 67b2e4f

Browse files
committed
fix tests
Signed-off-by: Kirill Mokevnin <[email protected]>
1 parent 343bc74 commit 67b2e4f

File tree

8 files changed

+34
-358
lines changed

8 files changed

+34
-358
lines changed

__tests__/error.test.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import supertest from 'supertest';
21
import fastify from 'fastify';
32

43
import init from '../server/plugin.js';
@@ -9,19 +8,15 @@ describe('app', () => {
98
beforeAll(async () => {
109
app = fastify();
1110
await init(app);
12-
await app.ready();
1311
});
1412

1513
it('error page', async () => {
16-
const res = await supertest(app.server)
17-
.get('/error')
18-
.expect(500);
14+
const res = await app.inject({
15+
method: 'GET',
16+
url: '/error',
17+
});
1918

20-
expect(res.text).toMatch('Внимание, тут что-то не так!');
21-
expect(res.text).toMatch('Oops! Something went wrong!');
22-
});
23-
24-
afterAll(() => {
25-
app.close();
19+
expect(res.body).toMatch('Внимание, тут что-то не так!');
20+
expect(res.body).toMatch('Oops! Something went wrong!');
2621
});
2722
});

__tests__/index.test.js

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import supertest from 'supertest';
21
import fastify from 'fastify';
32
import _ from 'lodash';
43

@@ -10,34 +9,34 @@ describe('app', () => {
109
beforeAll(async () => {
1110
app = fastify();
1211
await init(app);
13-
await app.ready();
14-
});
15-
16-
beforeEach(() => {
17-
_.unset(process.env, 'SERVER_MESSAGE');
1812
});
1913

2014
it('main page without environment variable SERVER_MESSAGE', async () => {
21-
const res = await supertest(app.server)
22-
.get('/')
23-
.expect(200);
24-
25-
expect(res.text).toMatch('Привет от Хекслета!');
26-
expect(res.text).toMatch('Приложение запущено, но сообщение сервера не установлено!');
15+
_.unset(process.env, 'SERVER_MESSAGE');
16+
const res = await app.inject({
17+
method: 'GET',
18+
url: '/',
19+
});
20+
21+
expect(res.statusCode).toBe(200);
22+
expect(res.body).toMatch('Привет от Хекслета!');
23+
expect(res.body).toMatch('Приложение запущено, но сообщение сервера не установлено!');
2724
});
2825

2926
it('main page with environment variable SERVER_MESSAGE', async () => {
3027
process.env.SERVER_MESSAGE = 'Hexlet Awesome Server';
3128

32-
const res = await supertest(app.server)
33-
.get('/')
34-
.expect(200);
35-
36-
expect(res.text).toMatch('Привет от Хекслета!');
37-
expect(res.text).toMatch(`Приложение запущено и передает сообщение: ${process.env.SERVER_MESSAGE}`);
38-
});
29+
const res = await app.inject({
30+
method: 'GET',
31+
url: '/',
32+
});
3933

40-
afterAll(() => {
41-
app.close();
34+
expect(res.statusCode).toBe(200);
35+
expect(res.body).toMatch('Привет от Хекслета!');
36+
expect(res.body).toMatch(`Приложение запущено и передает сообщение: ${process.env.SERVER_MESSAGE}`);
4237
});
38+
//
39+
// after all(() => {
40+
// app.close();
41+
// });
4342
});

bin/start.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
set -e
44

5-
COMMAND="fastify start server/plugin.js -a 0.0.0.0 -l info"
5+
COMMAND="fastify start server/plugin.js -a 0.0.0.0 -l info | pino-pretty -S"
66

77
echo $COMMAND
8-
exec $COMMAND
8+
eval $COMMAND

docker-compose.override.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ version: "3"
22

33
services:
44
app:
5-
build: .
65
volumes:
76
- .:/app
87
ports:

docker-compose.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ version: "3"
22

33
services:
44
app:
5-
image: hexletcomponents/devops-example-app:test
5+
build: .
6+
image: hexletcomponents/devops-example-app
67

78
caddy:
89
build:

0 commit comments

Comments
 (0)