2014-04-23 3 views
3

mocha-phantomjs을 사용하여 테스트를 실행 중입니다.mocha-phatomJS로 리소스 처리를 구성하는 방법은 무엇입니까? 리소스 파일로드 오류 :

단위 테스트를 실행하는 동안 http 서버가 실행되지 않아 내 리소스가 절대 URL (예 : /static/images/face.png)을 통해 제공되지 않고 출력이 다음과 같이 표시됩니다.

% node_modules/mocha-phantomjs/bin/mocha-phantomjs test/runner/runner.html 

    test app.Main 
    ✓ should show a command line 


    1 test complete (79 ms) 

Error loading resource file:///static/images/face.png (203). Details: Error opening /static/images/face.png: No such file or directory 

내 시험 :

describe "test app.Main", -> 
    beforeEach -> 
    @app = App.Main() 
    React.renderComponent @app, root[0] 

    afterEach -> React.unmountComponentAtNode root[0] 

    it "should show a command line", -> 
    @cmdForm = root.find("div.header-block").first().find('form') 

    expect(@cmdForm.length).to.equal 1 
    expect(@cmdForm.find('div.select2-container ul.select2-choices').length).equal 1 

시험은 성공하지만, 그 동안 나는이 추한 오류 메시지가 있습니다. phantomJS (또는 mocha?)가 해당 리소스로드를 무시하도록 구성하거나이 오류 메시지를 표시하지 않는 방법은 무엇입니까?

답변

-1

window.onError(function() {... 처리기를 사용하여 오류를 포착 (먹을 수 있음) 할 수 있습니다.

+0

이것은 예외 (테스트 통과)는 아니지만 phantomJS의 오류 로그입니다. –

0

에게 loadImages=false 전혀 로딩 이미지 phantomjs 방지 설정 @reubano 즉하여 대답을하지 않도록해야하고, 따라서 @ 로버트 - zaremba 찾고 있었던 것입니다. 그러나 코드가 누락 된 파일에 어떻게 반응하는지 단위 테스트해야하는 경우 파일을 실제로로드해야합니다. 이 경우, 누락 된 파일에 대한 테스트가 테스트 스위트의 일부이기 때문에 오류 메시지가 귀찮아합니다.

다행히도 mocha-phantomjs에는 --ignore-resource-errors 플래그가 있습니다. 그것은 당신의 구세주입니다. 파일은 계속로드되지만 성가신 오류는 사라집니다.

phantomjs를 직접 사용하는 경우 해결책은 page.onResourceErrordescribed here입니다.