Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cypress를 이용한 e2e test 도입 #821

Merged
merged 5 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions frontend/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineConfig } from 'cypress';

export default defineConfig({
experimentalStudio: true,

e2e: {
setupNodeEvents(on, config) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이건 필수적인 설정인지 궁금해요~

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 부분을 통해서 싸이프레스를 사용할 때 이벤트리스너를 붙일 수 있다고 합니다!
기본 설정으로 만들어진 부분인데, 추후 어떻게 사용할 지 몰라서 남겨두었습니다

gpt: 이 설정 객체는 엔드 투 엔드 테스트 (E2E)에 관련된 구성을 포함합니다. setupNodeEvents 함수를 포함하고 있는데, 여기에서 노드 이벤트 리스너를 설정할 수 있습니다. E2E 테스트를 실행하는 동안 특정 노드 이벤트에 대한 리스너를 추가하거나 수정할 수 있습니다.

// implement node event listeners here
},
},
});
13 changes: 13 additions & 0 deletions frontend/cypress.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { mount } from 'cypress/react';

// Augment the Cypress namespace to include type definitions for
// your custom command.
// Alternatively, can be defined in cypress/support/component.d.ts
// with a <reference path="./component" /> at the top of your spec.
declare global {
namespace Cypress {
interface Chainable {
mount: typeof mount;
}
}
}
5 changes: 5 additions & 0 deletions frontend/cypress/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": [
"plugin:cypress/recommended"
]
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

맨 끝 개행 한번 해주실 수 있나여? EOL이여

80 changes: 80 additions & 0 deletions frontend/cypress/e2e/guestFeatureTest.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
const visitUrl = 'http://localhost:3000/';

describe('guestFeatureTest', () => {
it('visitSite', () => {
cy.visit(visitUrl);
});

/* ==== Test Created with Cypress Studio ==== */
it('controlPostListFilteringOrSorting', function () {
/* ==== Generated with Cypress Studio ==== */
cy.visit('http://localhost:3000/');
cy.get(':nth-child(1) > .sc-gVpkOZ > .sc-fXmShK').click();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

음 저희가 styeld-compoents 여서 클래스명만 가지고는 어떤 컴포넌트인지 이해하기 쉽지 않은데, 혹시 주석 추가해주실 수 있나요? (아니면 it의 테스트 이름을 한글로 적어주실 수 있을지....?)

cy.get('.sc-gyMiQo > :nth-child(1)').click();
cy.get(':nth-child(2) > .sc-gVpkOZ > .sc-fXmShK').click();
cy.get('.sc-gyMiQo > :nth-child(1)').click();
//list 확인 필요
/* ==== End Cypress Studio ==== */
});

/* ==== Test Created with Cypress Studio ==== */
it('lookRankingAndGoPopularPost', function () {
/* ==== Generated with Cypress Studio ==== */
cy.visit('http://localhost:3000/');
cy.get('.sc-fWKGHs > .gHxHbZ > img').click();
cy.get('.cbweqh').click();
cy.get(':nth-child(1) > :nth-child(3) > a').click();
/* ==== End Cypress Studio ==== */
});

/* ==== Test Created with Cypress Studio ==== */
it('lookNoticeListAndNoticeDetail', function () {
/* ==== Generated with Cypress Studio ==== */
cy.visit('http://localhost:3000/');
cy.get('.sc-hmrlCG > .sc-iJSKBe > .sc-giQjdv > span').click();
//list 확인 필요
cy.get(':nth-child(1) > .sc-fGwJSW > .sc-hmftdN').click();
/* ==== End Cypress Studio ==== */
});

/* ==== Test Created with Cypress Studio ==== */
it('showToastForGuest', function () {
/* ==== Generated with Cypress Studio ==== */
cy.visit('http://localhost:3000/');
cy.get('.sc-fWKGHs > .sc-gSIKdN > .sc-iNyIUv > img').click();
cy.get('.sc-bdDrbm').should('exist').should('contain', '로그인 후 이용');
/* ==== End Cypress Studio ==== */
/* ==== Generated with Cypress Studio ==== */
cy.get(
'.sc-hmrlCG > .sc-iJSKBe > .sc-bYgGll > .sc-dILiZe > .sc-fKwBvW > .sc-dYlqv > .sc-hCcNSO > :nth-child(1) > .sc-fFCYnF > img'
).click();
cy.get('.sc-bdDrbm').should('exist').should('contain', '로그인 후 이용');
/* ==== End Cypress Studio ==== */
});

/* ==== Test Created with Cypress Studio ==== */
it('scrollTopScreen', function () {
/* ==== Generated with Cypress Studio ==== */
cy.visit('http://localhost:3000/');
cy.scrollTo('bottom');
cy.scrollTo('bottom');
cy.scrollTo('bottom');
cy.get('.sc-eEFsNM').click();
cy.get('html, body').should($el => {
expect($el.scrollTop()).to.equal(0);
});
/* ==== End Cypress Studio ==== */
});

/* ==== Test Created with Cypress Studio ==== */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 이 주석 필요한건가요??

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사람이 직접 작성한게 아니고 스튜디오를 사용해서 만들다보니까 특정 요소가 있는지 없는지, 정렬되었는지 넣는 건 어렵더라구요.
아직은 실제 api를 사용해서 코드에 입력하지는 않았는데 추후 mock으로 데이터를 대체하면 해당 부분을 넣으려고 합니다.

그래서 스튜디오로 작성한건 나중에 다시 한번 살펴보려고 넣었습니다.
그리고 그 외에도 사람이 직접 작성한거랑 스튜디오에서 작성한건 구분되는 게 좋을 것 같아서요!

it('searchAKeyword', function () {
/* ==== Generated with Cypress Studio ==== */
cy.visit('http://localhost:3000/');
cy.get('.sc-jePPIV').click();
cy.get('.sc-eIYifI').clear();
cy.get('.sc-eIYifI').type('a');
cy.get('.sc-otYyL > img').click();
//list
/* ==== End Cypress Studio ==== */
});
});
5 changes: 5 additions & 0 deletions frontend/cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "[email protected]",
"body": "Fixtures are a great way to mock data for responses to routes"
}
37 changes: 37 additions & 0 deletions frontend/cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/// <reference types="cypress" />
// ***********************************************
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

다 주석 처리되어 있는데 아예 불필요한 파일인가요??

Copy link
Collaborator

@Gilpop8663 Gilpop8663 Oct 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

제가 옛날에 삭제했을 때 아마도 작동이 안되었던 걸로 기억하네용

// This example commands.ts shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
//
// declare global {
// namespace Cypress {
// interface Chainable {
// login(email: string, password: string): Chainable<void>
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
// }
// }
// }
20 changes: 20 additions & 0 deletions frontend/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/e2e.ts is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands';

// Alternatively you can use CommonJS syntax:
// require('./commands')
8 changes: 8 additions & 0 deletions frontend/cypress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"target": "es5",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저희 src/tsconfig.json 의 target이 "es2021" 인데 통일하는거 어떠신가요?
image

"lib": ["es5", "dom"],
"types": ["cypress", "node"]
},
"include": ["**/*.ts"]
}
Loading
Loading