2014-10-20 3 views
0

nodejs에서 구문 분석 할 수 있도록 XML 파일을 다운로드하려고합니다. 다음은 모카를 통해 작성한 테스트입니다. 테스트는 통과하지만 아무 것도 콘솔에 표시되지 않습니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?nodejs 반환 XML이 없습니다

it('Get XML data', function() { 
var options = { 
     hostname: 'stona-app01.us.work.net', 
     port: 1213, 
     path: '/solrLive/STONA-STOUS-product-search-idx-en_US/select/?version=2.2&start=2&rows=2&qf=SKU&fl=*&indent=on&onlineFlag=1', 
     method: 'POST' 
    }; 

    var req = http.request(options, function(res) { 
     console.log('STATUS: ' + res.statusCode); 
     console.log('HEADERS: ' + JSON.stringify(res.headers)); 
     res.setEncoding('utf8'); 
     res.on('data', function (chunk) { 
     console.log('BODY: ' + chunk); 
     }); 
    }); 

    req.on('error', function(e) { 
     console.log('problem with request: ' + e.message); 
    }); 
}); 

코드의 URL에 도달 할 수 없으므로 테스트 할 수 없습니다.

답변

0

귀하의 테스트는 비동기, 그래서 당신은 당신의 테스트가 완료 될 때 done 매개 변수를 사용하고 호출하는 테스트를 정의해야합니다

it('Get XML data', function (done) { 
    var options = { 
     hostname: 'stona-app01.us.work.net', 
     port: 1213, 
     path: '/solrLive/STONA-STOUS-product-search-idx-en_US/select/?version=2.2&start=2&rows=2&qf=SKU&fl=*&indent=on&onlineFlag=1', 
     method: 'POST' 
    }; 

    var req = http.request(options, function(res) { 
     console.log('STATUS: ' + res.statusCode); 
     console.log('HEADERS: ' + JSON.stringify(res.headers)); 
     res.setEncoding('utf8'); 
     res.on('data', function (chunk) { 
     console.log('BODY: ' + chunk); 
     done(); // We're done! 
     }); 
    }); 

    req.on('error', function(e) { 
     console.log('problem with request: ' + e.message); 
     done(e); // Pass the error to Mocha. 
    }); 
}); 
+0

문제가 해결되지 않은 위의 코드를 추가. 여기 내 콘솔은 ➜ 새로운 시대-자동화 자식 (마스터) ✗ 모카 테스트/unittests 테스트 모든 사용자 정의 함수 ✓ 생성 이메일 주소 ✓ 받기 XML 데이터 2 통과 (7MS) ➜ 새로운 -age-automation git : (master) ✗ – jrock2004

+0

xml이고 실제로 .xml 파일을 호출하지 않는 페이지에 대한 링크 일 수 있습니까? – jrock2004