end to end testing
Testing End to End test 유닛 테스트보다 넓은 범위를 테스트 전체 서비스의 복사본이나 인스턴스 생성 package.json 의 script를 보면 "test:e2e"가 있음. src 폴더 내의 파일 실행 X 서버를 끄고 터미널에서 npm run test:e2e를 입력해보자. 새로운 E2E 테스트 만들기 test 폴더에 auth.e2e-spec.ts 파일을 만들고 app.e2e-spec.ts의 내용을 복사 붙여넣자. 이 후 조금의 수정을 가한다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 // auth.e2e-spec.ts import { Test, TestingModule } from '@nestjs/testing'; import { INestApplication } from '@nestjs/common'; import * as request from 'supertest'; import { AppModule } from './../src/app.module'; describe('Authentication System', () => { let app: INestApplication; beforeEach(async () => { const moduleFixture: TestingModule = await Test.createTestingModule({ imports: [AppModule], }).compile(); app = moduleFixture.createNestApplication(); await app.init(); }); it('handles a signup request', () => { // 알아보기 쉬운 주석 return request(app.getHttpServer()) .post('/auth/signup') // signup 경로 .send({ email: 'asgkege@akl.com', password: 'qownstn' }) // 무작위 body .expect(201) .then((res) => { // response id, email로 올 것 const { id, email } = res.body; expect(id).toBeDefined(); expect(email).toEqual(email); }); }); }); 터미널에서 npm run test:e2e를 실행하면 문제가 발생한다. 이유를 알아보자. ...