2016-09-26 3 views
2

Cucumber.js를 사용하여 새로운 e2e 테스트 슈트를 만들고 있는데, 스텝 파일에 TypeScript를 사용하고 싶습니다. 새로운 단계를 만들고 WebStorm에서 새 단계 파일을 생성하도록 Alt+Enter을 누르면 JavaScript 파일을 만드는 옵션 만 제공됩니다. enter image description hereWebStorm을 사용하여 JavaScript 대신 TypeScript에서 오이 단계 정의 파일을 만들려면 어떻게해야합니까?

누구나 TypeScript에서 새 단계 파일을 만들 수있는 방법을 알고 있습니까?

답변

2

Webstorm은 "TypeScript"파일 유형에 대해 마법사를 제공하지 않는 것 같으므로 수동으로 단계 정의 파일을 작성할 수 있습니다.

Simple Math Example에 대한 가능한 TS 단계 정의 파일은 다음과 같습니다

import * as cucumber from "cucumber"; 

module.exports = function() { 
    // Assign this to a typed variable so we have type-safe access 
    let sd: cucumber.StepDefinitions = this; 

    // The common variable is simply kept in function scope here 
    let variable: number = 0; 

    sd.Given(/^a variable set to (\d+)$/, (value: string) => { 
     variable = parseInt(value); 
    }); 

    sd.When(/^I increment the variable by (\d+)$/, (value: string) => { 
     variable += parseInt(value); 
    }); 

    sd.Then(/^the variable should contain (\d+)$/, (value: string) => { 
     if (variable != parseInt(value)) 
      throw new Error('Variable should contain '+value 
          + ' but it contains ' + variable + '.'); 
    }); 
}; 

는 예를 들어,이 내용을 넣어 features/step_definitions/mathSteps.ts와 같은 파일에 the example의 피쳐 코드를 붙여 넣습니다. features/math.feature를 사용하면 실행중인 예제가 있어야합니다.

+0

'Webstorm이 파일 형식 "TypeScript"섹션에 마법사를 제공하지 않는 것만으로이 대답을 선택합니다. 그게 제가 알고 싶어하는 것입니다. 감사! –

+0

나는 오이를 통해 무엇이든 접근 할 수 없었다. 단계 정의. 오류 : 'StepDefinitions'이'typeof path /to/my/cucumber/@types/index.ts '유형에 없습니다. – user2954463