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

Feat/example page test #366

Merged
merged 19 commits into from
Mar 30, 2020
Merged

Feat/example page test #366

merged 19 commits into from
Mar 30, 2020

Conversation

jinwoo-kim-nhn
Copy link
Contributor

@jinwoo-kim-nhn jinwoo-kim-nhn commented Mar 23, 2020

Please check if the PR fulfills these requirements

  • It's submitted to right branch according to our branching model
  • It's right issue type on title
  • When resolving a specific issue, it's referenced in the PR's title (e.g. fix #xxx[,#xxx], where "xxx" is the issue number)
  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes/features)
  • Docs have been added/updated (for bug fixes/features)
  • It does not introduce a breaking change or has description for the breaking change

Description

  1. (selenium-webdriver)로 예제페이지 테스트 하는코드 추가.
    • 예제페이지가 로드되면 window.errorLogs를 확인하여 에러가 있으면 로그를 찍고 테스트를 실패시킴
    • 예제페이지 목록은 tuidoc.config.json 을 확인하여 경로로부터 자동으로 가져오도록 함
  2. github actions 워크플로우에서 오전 7시마다 테스트하도록 함

package.json Outdated
@@ -59,11 +59,12 @@
"mkdirp": "^0.5.1",
"optimize-css-assets-webpack-plugin": "^5.0.3",
"safe-umd-webpack-plugin": "^4.0.0",
"selenium-webdriver": "^4.0.0-alpha.7",
Copy link
Member

Choose a reason for hiding this comment

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

selenium webdriver 버전도 같이 올라가야 하나요?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

selenium-webdriver 는 기존에 사용안하다가 새로 추가되는 모듈입니다.ㅎㅎ

exampleTest.js Outdated
const driver = getDriver(index);
const result = [];

for(let i = 0; i <= urls.length - 1; i++) {
Copy link
Member

Choose a reason for hiding this comment

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

for(let i = 0; i < urls.length; i += 1) {도 동일한 의미의 구문일 것 같습니다! 추가적인 연산이 들어간 것 같습니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

넵 그렇네요. 반영하겠습니다. 감사해요

exampleTest.js Outdated
Comment on lines 1 to 2
const BROWSERSTACK_USERNAME = process.env.BROWSERSTACK_USERNAME;
const BROWSERSTACK_ACCESS_KEY = process.env.BROWSERSTACK_ACCESS_KEY;
Copy link
Member

Choose a reason for hiding this comment

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

const { BROWSERSTACK_USERNAME, BROWSERSTACK_ACCESS_KEY } = process.env;

로 디스트럭처링 해서 작성할 수 있을 것 같습니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

넵 맞네요 ㅎㅎ 반영하겠습니다. 감사합니다.

exampleTest.js Outdated
Comment on lines 92 to 96
await driver.wait(function() {
return driver.executeScript('return document.readyState').then(function(readyState) {
return readyState === 'complete';
});
}, 20000);
Copy link
Member

Choose a reason for hiding this comment

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

await driver.wait(() => 
  driver.executeScript('return document.readyState').then(readyState => readyState === 'complete')
, 20000);

로 줄일 수 있겠네요!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

맞네요. 반영하겠습니다.

Copy link

Choose a reason for hiding this comment

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

20000은 어떤 의미인가요?정확한 기준이나 가이드가 있는건가요?

Copy link
Contributor Author

@jinwoo-kim-nhn jinwoo-kim-nhn Mar 25, 2020

Choose a reason for hiding this comment

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

조건문이 만족할때 까지 잠시 스레드를 멈춘다고 합니다. 20000 은 최대시간 20초를 말하고, 20초 전에라도 조건이 완료되면 계속 실행되기때문에 속도에는 큰 문제가 없을듯 합니다. 문서에 기본값에 대한 정확한 명시가 없어서 안전하게 20000ms로 임의로 넣었습니다. .

Copy link

@js87zz js87zz Mar 25, 2020

Choose a reason for hiding this comment

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

@jinwoo-kim-nhn
넵 감사합니다~! 저 숫자는 그럼 상수화시켜서 의미가 명확하면 더 좋을 것 같습니다!아니면 주석으로 간단한 설명이 있어도 좋을 것 같습니다.

exampleTest.js Outdated
/**
* Url test
*/
async function urlTest(urls) {
Copy link

@js87zz js87zz Mar 25, 2020

Choose a reason for hiding this comment

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

함수 이름이 urlTest라서 뭔가 url자체를 테스트하는 느낌인대요. test또는 testExamplePage는 어떨까요?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

넵 좋네요. 반영하겠습니다.

exampleTest.js Outdated
const config = require(path.resolve(process.cwd(), 'tuidoc.config.json'));
const filePath = (config.examples || {filePath: ''}).filePath;
return fs.readdirSync(filePath).reduce((urls, fileName) => {
if (fileName.match(/html$/)) {
Copy link

Choose a reason for hiding this comment

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

반환된 정보를 활용하지 않기때문에 이 경우는 정규식 test를 사용하는게 더 적합할 것 같습니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

넵 거기까진 생각하지 못했네요, 반영하겠습니다.

exampleTest.js Outdated
function getDriver(index) {
return new Builder()
.usingHttpAgent(HttpAgent)
.withCapabilities(Object.assign({}, capabilities[index], {build: `examplePageTest-${new Date().toLocaleDateString()}`}))
Copy link

@js87zz js87zz Mar 25, 2020

Choose a reason for hiding this comment

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

스프레드가 조금 더 보기 편하지않을까요?

{ ...capabilities[index], build: `examplePageTest-${new Date().toLocaleDateString()}` }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

넵 맞네요. 반영하겠습니다 감사합니다 ㅎㅎ

exampleTest.js Outdated
const parallelPendingTests = Object.keys(capabilities).map(index => testPlatform(index, urls));
const testResults = await Promise.all(parallelPendingTests);
const result = testResults.flat().reduce((errorList, errorInfo) => {
if (!errorInfo.errorLogs) {
Copy link

Choose a reason for hiding this comment

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

testPlatform 로직을 보면 errorLogs가 없으면 아무 에러가 안 난 상황일 것 같은데 처리해주는 이유가 있을까요?

Copy link
Contributor Author

@jinwoo-kim-nhn jinwoo-kim-nhn Mar 25, 2020

Choose a reason for hiding this comment

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

예제페이지에 errorLogs에 관한 코드스닙펫이 추가 안되어있을 경우나 페이지를 제대로 get 해오지 못할경우를 생각하여 처리하였습니다. 정상적인 페이지인 경우 배열이 리턴되기때문에 그렇고. 구두로 논의한대로 더 알아보기 쉽게 수정해보겠습니다.

exampleTest.js Outdated
* Url test
*/
async function urlTest(urls) {
const parallelPendingTests = Object.keys(capabilities).map(index => testPlatform(index, urls));
Copy link

Choose a reason for hiding this comment

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

여기서 index를 넘기지 않고 배열의 엘리먼트를 바로 넘기는게 낫지 않을까요?getDriver에서도 capabilities[index]index를 사용해서 따로 빼내지 않아도 될 것 같구요.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

네 이건 저도 인지하고 있었는데. 못고쳤네요 반영하겠습니다.!

exampleTest.js Outdated
async function urlTest(urls) {
const parallelPendingTests = Object.keys(capabilities).map(index => testPlatform(index, urls));
const testResults = await Promise.all(parallelPendingTests);
const result = testResults.flat().reduce((errorList, errorInfo) => {
Copy link

Choose a reason for hiding this comment

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

testResults의 내용이 error가 나지 않은 경우에도 정보가 담겨있는데 errorInfo보다는 다른 네이밍이 좋지 않을까요?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

넵 좀더 고민해서 고쳐보겠습니다 ㅎㅎ

exampleTest.js Outdated
Comment on lines 134 to 135
console.log(errorInfo.url);
console.log(errorInfo.browserName, errorInfo.browserVersion, errorInfo.errorLogs);
Copy link

@js87zz js87zz Mar 25, 2020

Choose a reason for hiding this comment

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

디스트럭쳐링으로 쓰면 좀 더 간결하게 줄일수 있을 것 같아요~!그리고 error log는 chalk 같은 라이브러리 사용해서 로그에 색깔이 구분되도록 할 수도 있을까요?그러면 더 눈에띄고 보기 좋을 것 같아서요.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

넵 디스트럭처링 반영하겠습니다. chalk는 최대한 디펜던시를 만들고 싶지 않아서.. 고려해보겠습니다.

Copy link

Choose a reason for hiding this comment

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

아 의존성 문제가 있군요. 우선은 고려안하는게 좋겠네요!ㅎㅎ


printErrorLog(result);

assert.equal(result.length, 0);
Copy link

@js87zz js87zz Mar 25, 2020

Choose a reason for hiding this comment

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

이 단언문은 에러가 있을 경우 단언에 실패하도록 추가된건가요?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

네 에러가 있으면 실패되도록 처리하기위해 사용했습니다.

Copy link

Choose a reason for hiding this comment

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

에러 객체를 throw 하는 건 어떨까요?그러면 위의 catch 하는 쪽에서도 메시지가 더 명시적으로 나오게 만들수 있을 것 같아서요.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

assert가 깨질경우 알아서 에러를 던지므로 따로 throw 문을 쓰지 않아도 상관없을꺼 같아요.

@jinwoo-kim-nhn jinwoo-kim-nhn merged commit 3b02631 into master Mar 30, 2020
HerlinMatos pushed a commit to EveryMundo/tui.image-editor that referenced this pull request Jul 2, 2020
* feat: example test

* feat: added action workflow

* push test

* restore

* test 2

* commit for fail test

* test 3

* test 4

* error test 5

* success test 1

* builder open close improvements

* fail Tests with improved speed.

* feat: make test target urls

* update workflow for exampletest

* some refactoring

* remove unnessary script

* apply codereview - 1

* apply codereview - 2

Co-authored-by: superlucky84 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants