2017-11-20 8 views
0

Frisby와 함께 gauge-j를 사용하려고합니다. Frisby를 사용하여 블랙 박스 테스트로 API에 대한 기능 테스트를 수행합니다. 최근 Frisby를 Jest를 사용하는 2.0.8 버전으로 업그레이드하십시오. 모두 잘 했어. 이제 인간이 읽을 수있는 테스트 스펙/시나리오/단계를 추가하기 위해 Gauge-js를 맨 위에 추가하려고합니다.frisby.js/jest with Gauge를 사용하는 API 테스트

나는 윈도우 8.1 시스템에서 테스트 해요 :
- Frisby
- Gauge 0.9.4
- gauge-js 2.0.3

는 내가 측정-JS하는 종속성으로 Frisby를 추가 작동하려면. 이제 부분적으로 작동합니다.

/* globals gauge*/ 

"use strict"; 

var frisby = require('frisby'); 

// -------------------------- 
// Gauge step implementations 
// -------------------------- 

step("Get responds with <state>.", function (state, doneFn) { 

    frisby 
    .timeout(1500) 
    .get('http://localhost:8001/some/get/resource', { 
     headers: { 
     'Content-Type': 'application/json', 
     'Authorization': 'Basic QWERTYASDFEDEFTGHYFVCCFRJgyuku' 
     } 
    }) 

    // .expect('status', 200) 
    // .expect('header', 'Content-Type', 'application/json; charset=utf-8') 
    // .expect('json', state) 
    .done(doneFn).catch(error => { 
     console.log(error); 
    }); 
}); 

선이 오류가 발생할 주석 처리 주석 : 실제로 여기에 실제 시험 단계는 시험 단계를 실행하지만,

ReferenceError: expect is not defined 
    at incrementAssertionCount (C:\Users\<USER>\AppData\Roaming\gauge\plugins\js\2.0.3\node_modules\frisby\src\frisby\expects.js:14:20) 
    at FrisbySpec.status (C:\Users\<USER>\AppData\Roaming\gauge\plugins\js\2.0.3\node_modules\frisby\src\frisby\expects.js:23:5) 
    at FrisbySpec._addExpect.e (C:\Users\<USER>\AppData\Roaming\gauge\plugins\js\2.0.3\node_modules\frisby\src\frisby\spec.js:396:23) 
    at FrisbySpec._runExpects (C:\Users\<USER>\AppData\Roaming\gauge\plugins\js\2.0.3\node_modules\frisby\src\frisby\spec.js:288:24) 
    at _fetch.fetch.then.then (C:\Users\<USER>\AppData\Roaming\gauge\plugins\js\2.0.3\node_modules\frisby\src\frisby\spec.js:142:14) 
    at process._tickCallback (internal/process/next_tick.js:109:7) 

실패했습니다.

실제로 문제는로드 종속성과 관련이 있다고 생각하지만 내 js 지식은 약간 조각 났고 녹슬 었습니다. 어떤 도움을 주시면 감사하겠습니다.

+0

frisbyjs는 자바 스크립트 런타임으로'jasmine-node'를 필요로하는 반면 gauge-js는'node'를 사용합니다. FWIW, frisby와 함께 바닐라 게이지 -js 프로젝트에서 동일한 스택 추적을 얻습니다. –

+0

두 스택의 코드를 모두 뚫어 냈습니다. 내가 머리를 쓸 수없는 것은 누락 된 참조를 추가하는 방법입니다. – 0rangeBean

답변

0

. @duyker가 제안한 것을 구현하기 시작할 때. 나는 Frisby 코드가 Jasmine에 대한 의존성을 무시할 의도가 있다고 (마지막으로) 알았지 만, 거기에는 버그가있다. 그래서 fix for it을 제출합니다. 그리고 그것은 받아 들여졌습니다.

이제 문제가 해결되고 Frisby는 Jasmine이나 Jest 없이도 작업 할 수 있습니다.

0

.expect(...) 기능이 정의되지 않은 이유는 frisby가 jasmine이 테스트 러너이고 jassmine의 expect 기능을 사용할 수 있다고 기대하고 있기 때문입니다.

frisby에 포함 된 모든 함수 expect은 아래의 "incrementAssertionCount"함수를 실행합니다. if (_.isFunction(expect))expect을 찾을 수 없기 때문에 frisby가 제공 할 기본 예상 값을 제공 할 수 없습니다. 더 나은, 그래서 당신이하지 않아도 당신이 참조 할 수있는 외부 패키지를 확인합니다 (addExpectHandler 방법을 코드에 frisby에서 기능을 기대를 복사하고 호출하는 간단한 대안이 같은

function incrementAssertionCount() { 
    if (_.isFunction(expect)) { // FAILS HERE: 'expect' does not exist 
    // Jasmine 
    expect(true).toBe(true); 
    } 
} 

이 보인다 그것을 모든 프로젝트에 복사).

간단한 예

는 다음과 같습니다 : 나는 원래 문제에 더 나은 솔루션을 발견

var frisby = require("frisby"); 
var assert = require("assert"); 

function statusHandler(response, statusCode) { 
    assert.strictEqual(response.status, statusCode, `HTTP status ${statusCode} !== ${response.status}`); 
} 

beforeScenario(function() { 
    frisby.addExpectHandler('status', statusHandler); 
}); 

step("Call httpbin.org and get a teabot", function (done) { 
    frisby.get('http://httpbin.org/status/418') 
    .timeout(2000) 
    .expect('status', 418) 
    .catch(function (e) { 
     done(e); 
    }) 
    .done(done); 
}); 
+0

두 스택의 코드를 모두 파헤칩니다. 문제가 무엇인지 보았다. Kinda는 터널에 갇히고 참조 문제를 해결하는 방법을 찾으려고했습니다. Jasmine'expect' 호출은 호출 및보고 메커니즘이 완전히 다르므로 코드가 게이지에서 실행될 때 값을 추가하지 않으므로 실제로 올바른 이유는 없습니다. – 0rangeBean