Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow passing arguments to test script (issue #88) #103

Closed
wants to merge 2 commits into from

Conversation

rgeraldporter
Copy link

As per issue #88

Background: Recently the npm repo cucumber-nightwatch was deprecated in favour of nightwatch-api, whose example for how to use CucumberJs with Nightwatch involves using start-server-and-test. What the example does not account for that cucumber-nightwatch supported though was passing arguments to Cucumber for tags, targeting feature files, etc.

This limitation was due to the passing-arguments feature not yet implemented in start-server-and-test. I'm currently working on a project where we need to update nightwatch to a version that the old cucumber-nightwatch does not support, so I needed something that works and took on this issue.

Their example: https://github.com/mucsi96/nightwatch-api/tree/master/examples/cucumber
I opened an issue on their end as well: mucsi96/nightwatch-api#24

I've tried my best to copy the style of the repo, hopefully it is up to par!

Usage:

Assuming:

{
    "test": "start-server-and-test test:setup http-get://localhost:4444 test:run",
    "test:run": "my-test-runner",
    "test:setup": "my-server-setup",
}
npm run test -- --tag mytag

would pass -- --tag mytag to the test:run script, which would run my-test-runner --tag mytag.

I've kept in the convention of -- as a requirement for this to run correctly as it seems to be how passing arguments to other scripts is typically handled. There's other ways to do this as well, but this is what better matched what we had previously.

Thanks for this repo!

bin/start.js Outdated
start = args[0]
url = utils.normalizeUrl(args[1])
test = args[2]
test = args[3] ? [args[2]].concat(['--']).concat(args.slice(3)) : [args[2]]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is hard to read and requires its own helper function I feel for clarity

@bahmutov
Copy link
Owner

it would be so so nice to have an "end-to-end" test script to confirm that this is working as expected

@rgeraldporter
Copy link
Author

@bahmutov I've made updates based on your suggestions. Let me know if you need anything else.

@pratyush23
Copy link

@rgeraldporter That was very useful. May I know when this PR will be merged so that I can update start-server-and-test dependency in my nightwatch-api framework and allow it to accept arguments

@bahmutov
Copy link
Owner

bahmutov commented Dec 7, 2018

@rgeraldporter can you update the code to fix the npm run demo and other tests?

$ npm run demo
> [email protected] demo /home/travis/build/bahmutov/start-server-and-test
> node bin/start.js http://127.0.0.1:9000
starting server using command "npm run start"
and when url "http://127.0.0.1:9000" is responding
/home/travis/build/bahmutov/start-server-and-test/bin/start.js:36
console.log(`running tests using command "${test.join(' ')}"`)
                                                 ^
TypeError: test.join is not a function
    at Object.<anonymous> (/home/travis/build/bahmutov/start-server-and-test/bin/start.js:36:50)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)

in https://travis-ci.org/bahmutov/start-server-and-test/builds/432655532

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants