timjroberts / cucumber-js-tsflow

Provides 'specflow' like bindings for Cucumber.js in TypeScript 1.7+.
MIT License
133 stars 34 forks source link

Combining this with ts-node #14

Closed wmeints closed 7 years ago

wmeints commented 8 years ago

Hi, I'm looking into using this library in combination with ts-node and protractor. I configured my protractor so that it uses cucumber and sets the ts-node as the compiler for the step definitions

exports.config = {
    baseUrl: 'http://localhost:9640',

    // Specify the patterns for test files 
    // to include in the test run
    specs: [
        'features/**/*.feature'
    ],

    // Use this to exclude files from the test run.
    // In this case it's empty since we want all files
    // that are mentioned in the specs.
    exclude: [],

    // Use cucumber for the tests
    framework: 'custom',
    frameworkPath: require.resolve('protractor-cucumber-framework'),

    cucumberOpts: {
        format: 'summary',
        require: ['features/step_definitions/**/*.ts'],
        compiler: 'ts:ts-node/register'
    },

    // These capabilities tell protractor about the browser
    // it should use for the tests. In this case chrome.
    capabilities: {
        'browserName': 'chrome',
        'chromeOptions': {

        }
    },

    // This setting tells protractor to wait for all apps 
    // to load on the page instead of just the first.
    useAllAngular2AppRoots: true
}

I am wondering whether this is supported at all. Or do you need to compile the step definitions first for them to work properly with cucumber?

alexwizp commented 8 years ago

What about?

beforeLaunch: function() { require('ts-node').register(); },

timjroberts commented 7 years ago

I have no experience at all with protractor. When cucumberjs is run from the command line it requires all the .js files in the working folder, or from whatever you have specified via the -r option.

Maybe you could call bootstrap the ts-node side of things by supplying an index.js file to the -r option, which then does a call to require("ts-node").register(); to set things up.

wmeints commented 7 years ago

I found a working solution for the issues I had with this. It turns out you can register a different compiler in the cucumberOpts. Combine that with this package and you got yourself typescript based tests.

I Wrote a blogpost about it if anyone's interested: http://fizzylogic.nl/2016/10/14/How-to-write-ATDD-tests-with-cucumber-js-protractor-and-typescript/