1- import supertest from 'supertest' ;
21import fastify from 'fastify' ;
32import _ 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} ) ;
0 commit comments