-
Notifications
You must be signed in to change notification settings - Fork 6
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
test-fe: Playwright 설정 #715
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
221fef5
Create draft PR for #714
github-actions[bot] bcee992
feat: playwright 설정 및 custom reporter 추가
llqqssttyy 3e60e85
chore: jest가 playwright 테스트 무시하도록 설정
llqqssttyy e100bdd
chore: slack 메세지 수정
llqqssttyy 6ba45d3
chore: 띄어쓰기
llqqssttyy 97f7ae5
Merge remote-tracking branch 'origin/fe/develop' into fe-714-E2E_01
llqqssttyy a994880
chore: package-lock.json 업데이트
llqqssttyy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { test, expect } from '@playwright/test'; | ||
|
||
test('has title', async ({ page }) => { | ||
await page.goto('https://playwright.dev/'); | ||
|
||
// Expect a title "to contain" a substring. | ||
await expect(page).toHaveTitle(/Playwright/); | ||
}); | ||
|
||
test('get started link', async ({ page }) => { | ||
await page.goto('https://playwright.dev/'); | ||
|
||
// Click the get started link. | ||
await page.getByRole('link', { name: 'Get started' }).click(); | ||
|
||
// Expects page to have a heading with the name of Installation. | ||
await expect(page.getByRole('heading', { name: 'Installation' })).toBeVisible(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,319 @@ | ||
/* eslint-disable class-methods-use-this */ | ||
import type { Reporter, FullConfig, Suite, TestCase, TestResult, FullResult } from '@playwright/test/reporter'; | ||
|
||
const getSlackMessage = ({ | ||
all, | ||
passed, | ||
failed, | ||
skipped, | ||
duration, | ||
result, | ||
}: { | ||
all: string; | ||
passed: string; | ||
failed: string; | ||
skipped: string; | ||
duration: string; | ||
result: string; | ||
}) => ({ | ||
blocks: [ | ||
{ | ||
type: 'header', | ||
text: { | ||
type: 'plain_text', | ||
text: '🏃 테스트 실행이 시작되었습니다: ', | ||
emoji: true, | ||
}, | ||
}, | ||
{ | ||
type: 'rich_text', | ||
elements: [ | ||
{ | ||
type: 'rich_text_section', | ||
elements: [], | ||
}, | ||
{ | ||
type: 'rich_text_list', | ||
style: 'bullet', | ||
elements: [ | ||
{ | ||
type: 'rich_text_section', | ||
elements: [ | ||
{ | ||
type: 'text', | ||
text: '실행 시각: ', | ||
}, | ||
{ | ||
type: 'text', | ||
text: `${new Date().toLocaleDateString('ko-KR', { | ||
year: 'numeric', | ||
month: 'long', | ||
day: 'numeric', | ||
hour: 'numeric', | ||
minute: 'numeric', | ||
second: 'numeric', | ||
hour12: true, | ||
})}`, | ||
}, | ||
], | ||
}, | ||
{ | ||
type: 'rich_text_section', | ||
elements: [ | ||
{ | ||
type: 'text', | ||
text: '테스트 케이스 수: ', | ||
}, | ||
{ | ||
type: 'text', | ||
text: all, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
{ | ||
type: 'divider', | ||
}, | ||
{ | ||
type: 'rich_text', | ||
elements: [ | ||
{ | ||
type: 'rich_text_section', | ||
elements: [ | ||
{ | ||
type: 'text', | ||
text: 'SUMMARY', | ||
style: { | ||
bold: true, | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
{ | ||
type: 'rich_text', | ||
elements: [ | ||
{ | ||
type: 'rich_text_list', | ||
style: 'bullet', | ||
indent: 0, | ||
border: 0, | ||
elements: [ | ||
{ | ||
type: 'rich_text_section', | ||
elements: [ | ||
{ | ||
type: 'emoji', | ||
name: 'hourglass', | ||
unicode: '231b', | ||
style: { | ||
bold: true, | ||
}, | ||
}, | ||
{ | ||
type: 'text', | ||
text: ' 테스트 실행 시간: ', | ||
style: { | ||
bold: true, | ||
}, | ||
}, | ||
{ | ||
type: 'text', | ||
text: duration, | ||
}, | ||
], | ||
}, | ||
{ | ||
type: 'rich_text_section', | ||
elements: [ | ||
{ | ||
type: 'emoji', | ||
name: 'package', | ||
unicode: '1f4e6', | ||
style: { | ||
bold: true, | ||
}, | ||
}, | ||
{ | ||
type: 'text', | ||
text: ' 테스트 결과: ', | ||
style: { | ||
bold: true, | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
{ | ||
type: 'rich_text_list', | ||
style: 'bullet', | ||
indent: 1, | ||
border: 0, | ||
elements: [ | ||
{ | ||
type: 'rich_text_section', | ||
elements: [ | ||
{ | ||
type: 'emoji', | ||
name: 'white_check_mark', | ||
unicode: '2705', | ||
}, | ||
{ | ||
type: 'text', | ||
text: ' 성공: ', | ||
}, | ||
{ | ||
type: 'text', | ||
text: passed, | ||
}, | ||
], | ||
}, | ||
{ | ||
type: 'rich_text_section', | ||
elements: [ | ||
{ | ||
type: 'emoji', | ||
name: 'x', | ||
unicode: '274c', | ||
}, | ||
{ | ||
type: 'text', | ||
text: ' 실패: ', | ||
}, | ||
{ | ||
type: 'text', | ||
text: failed, | ||
}, | ||
], | ||
}, | ||
{ | ||
type: 'rich_text_section', | ||
elements: [ | ||
{ | ||
type: 'emoji', | ||
name: 'fast_forward', | ||
unicode: '23e9', | ||
}, | ||
{ | ||
type: 'text', | ||
text: ' 건너뜀: ', | ||
}, | ||
{ | ||
type: 'text', | ||
text: skipped, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
{ | ||
type: 'divider', | ||
}, | ||
{ | ||
type: 'rich_text', | ||
elements: [ | ||
{ | ||
type: 'rich_text_section', | ||
elements: [ | ||
{ | ||
type: 'text', | ||
text: result, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
], | ||
}); | ||
|
||
class MyReporter implements Reporter { | ||
all = 0; | ||
|
||
passed = 0; | ||
|
||
failed = 0; | ||
|
||
skipped = 0; | ||
|
||
failsMessage = ''; | ||
|
||
onBegin(_: FullConfig, suite: Suite) { | ||
this.all = suite.allTests().length; | ||
} | ||
|
||
onTestEnd(test: TestCase, result: TestResult) { | ||
switch (result.status) { | ||
case 'failed': | ||
case 'timedOut': | ||
this.addFailMessage(`❌ 테스트 실패: ${test.title}\n>${result.error?.message}`); | ||
this.failed += 1; | ||
break; | ||
case 'skipped': | ||
this.addFailMessage(`⚠️ 테스트 건너뜀: ${test.title}`); | ||
this.skipped += 1; | ||
break; | ||
case 'passed': | ||
this.passed += 1; | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
async onEnd(result: FullResult) { | ||
const blockKit = await this.getBlockKit(result); | ||
const webhookUrl = await process.env.SLACK_WEBHOOK_URL; | ||
|
||
if (!webhookUrl) { | ||
console.error('SLACK_WEBHOOK_URL 환경 변수가 설정되지 않았습니다.'); | ||
return; | ||
} | ||
|
||
try { | ||
const response = await fetch(webhookUrl, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify(blockKit), | ||
}); | ||
|
||
if (!response.ok) { | ||
console.error('Slack 메시지 전송 실패:', response.statusText); | ||
} else { | ||
console.log('Slack 메시지 전송 성공'); | ||
} | ||
} catch (error) { | ||
console.error('Slack 메시지 전송 중 에러 발생:', error); | ||
} | ||
} | ||
|
||
private addFailMessage(message: string) { | ||
this.failsMessage += `\n${message}`; | ||
} | ||
|
||
private async getBlockKit(result: FullResult) { | ||
const { duration } = result; | ||
const minutes = Math.floor(duration / 6000); | ||
const seconds = ((duration % 60000) / 1000).toFixed(0); | ||
|
||
const resultBlockKit = getSlackMessage({ | ||
all: `${this.all}`, | ||
passed: `${this.passed}개`, | ||
failed: `${this.failed}개`, | ||
skipped: `${this.skipped}개`, | ||
duration: `${minutes}분 ${seconds}초`, | ||
result: `${this.failsMessage ? `테스트 실패 ❌\n${this.failsMessage}` : '👍 모든 테스트가 성공적으로 통과했습니다!'}`, | ||
}); | ||
|
||
return resultBlockKit; | ||
} | ||
} | ||
export default MyReporter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
슬랙 연동 아주 좋습니다 👍