I abuse the heck out of npm scripts. They aren't just for build, serve, and test!
For instance, as a SQA, I need to have packages like Jasmine and Protractor, and then use Protractor to kick off my tests and maintain my selenium package.
So in my package.json, I include in scripts:
"scripts":{// snip"update-webdriver":"node node_modules/protractor/node_modules/webdriver-manager/bin/webdriver-manager update","preprotractor":"npm run update-webdriver","protractor":"node node_modules/protractor/bin/protractor path/to/conf/file",// snip}
So what happens when I run npm run protractor is:
I get the latest selenium jar and chromedriver (and other drivers I don't care about like gecko but whatever)
The local installation of protractor kicks off a test run with the default suite.
Things this buys me:
Every single guide on protractor starts with npm i -g protractor. NO. Bad. I don't want every onboarding to be a laundry list of global packages to install. Just use project dev-dependencies and scripts that alias the unweildy bin paths. Now everyone's computers can be happy cookie cutters without needing local aliasing and global installs.
Since scripts has a concept of pre and post runs, I can ensure everyone actually keeps chromedriver up to date with Chrome without having to keep tabs on that. It just works
I can still override or include settings at runtime like npm run protractor -- --suite=api rather than always using the default.
I'm half tempted to put in a postprotractor for running npm run eslint -- --fix e2e-tests/** but I might hear complaints if I do that...
But I do this set up on every project I'm on to keep things nice and tidy.
Worth noting that you don't need to write node node_modules/.bin/protractor config - you can just use protractor config and npm will figure out the rest for you :)
I abuse the heck out of npm scripts. They aren't just for build, serve, and test!
For instance, as a SQA, I need to have packages like Jasmine and Protractor, and then use Protractor to kick off my tests and maintain my selenium package.
So in my package.json, I include in
scripts
:So what happens when I run
npm run protractor
is:Things this buys me:
npm i -g protractor
. NO. Bad. I don't want every onboarding to be a laundry list of global packages to install. Just use project dev-dependencies and scripts that alias the unweildy bin paths. Now everyone's computers can be happy cookie cutters without needing local aliasing and global installs.scripts
has a concept ofpre
andpost
runs, I can ensure everyone actually keeps chromedriver up to date with Chrome without having to keep tabs on that. It just worksnpm run protractor -- --suite=api
rather than always using the default.I'm half tempted to put in a
postprotractor
for runningnpm run eslint -- --fix e2e-tests/**
but I might hear complaints if I do that...But I do this set up on every project I'm on to keep things nice and tidy.
Worth noting that you don't need to write
node node_modules/.bin/protractor config
- you can just useprotractor config
and npm will figure out the rest for you :)Nifty! I'll try to remember that next time.