I have following script in my package.json file which I execute in my cmd by npm run protractor:
"scripts": {
"postinstall": "bower install",
"pretest": "npm install",
"test": "karma start test/karma.conf.js",
"test-single-run": "karma start test/karma.conf.js --single-run",
"preupdate-webdriver": "npm install",
"update-webdriver": "webdriver-manager update",
"preprotractor": "npm run update-webdriver && node setUp.js",
"protractor": "protractor test/protractor-conf.js",
"postprotractor": "node tearDown.js",
}
If all my e2e test pass, npm runs the entire script - also my tearDown.js. However, in the event of a failure in my protractor tests ("protractor": "protractor test/protractor-conf.js"), npm does not continue to execute my postprotractor file(I need tearDown.js as it closes my backend).
Is there any solution of making npm run the entire script?
You should run your setup script and teardown script as part of protractor in beforeLaunch and afterLaunch, not npm.
If for some reason you absolutely do not want to run it as part of protractor you would have to change the protractor exitCode to '0', either in afterLaunch (example) or by wrapping a script around your protractor run script. However, I highly advise against doing this because then you're just masking errors.
Related
Now It doesn't run on my ubuntu machine. When I run the npm start command it says missing script start. Is there any method to run the downloaded project?
In your package.json file, check scripts property:
"scripts": {
"clean": "rimraf build/*",
"copy-assets": "ts-node src/tools/copyAssets",
"tsc": " tsc",
"build": "npm-run-all clean tsc copy-assets",
"dev": "nodemon --watch src -e ts,ejs,css --exec npm run dev:start",
"dev:start": "npm-run-all build start",
},
Looks like start script does not exist. Instead run the appropriate one from the scripts section.
I want to run one npm install on the project root to install both server and client packages.
My project structure is:
project
│ package.json
| node express files...
└───client
│ package.json
| react app files...
And also, create one script that runs npm run dev on the root folder and npm start on the client folder.
I tried to use concurrently, and it does work for running the apps, but for installing, I get a weird infinite loop that keeps installing in the root folder:
terminal screenshot
And I guess if concurrently is not globally installed, it wouldn't work anyway for the first installation.
package.json scripts in the root folder:
"scripts": {
"test": "jest",
"start": "node index.js",
"build": "cd client && npm run build",
"install-client": "cd client && npm install",
"heroku-postbuild": "npm run install-client && npm run build",
"dev-client": "cd client && npm start",
"dev": "nodemon index.js",
"install": "concurrently \"npm install\" \"npm run install-client\"",
"dev-both": "concurrently \"npm run dev\" \"npm run client-dev\""
},
Any ideas how for a fix or an alternative way to do this?
To avoid infinite loop, try this :
"both-install": "concurrently \"npm install\" \"npm run install-client\"",
to install client try this:
"install-client": "cd ../client && npm install",
Working on an Electron app with React. Right now, to get things started, I run the typical npm start command which runs the react-scripts start script.
This starts the dev server. Once the dev server is started, I open a second terminal window and run a script to start electron npm run start-electron which opens my React app in the Electron window.
This works as expected, but I was curious if there was a way to create a script that would:
Start the dev server
Wait for dev server to be started
Then start electron
I tried setting up a sequential script in package.json but it only starts up the dev server. For example npm run start && npm run start-electron.
This isn't make or break. The two terminal option works fine, just didn't know if this was possible.
Yes it is possible, I use concurrently to do it within my projects
npm i concurrently
and add a new script, let's call it dev for example, then in your scripts:
"dev": "concurrently \"npm run start\" \"npm run start-electron\""
All that remains to do now is npm run dev
I have the exact same situation, and below script work for me (remember to install wait-on)
"scripts": {
"start-reactjs": "PORT=25610 react-scripts start",
"start-electron": "wait-on http://localhost:25610 && electron .",
"start": "npm run start-electron & npm run start-reactjs"
}
you can create a script in the root directory with extension .sh
it could contain all operations for you
npm start
npm run start-electron
The second approach you could create a custom script in package.json
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"customStart":"npm run start && npm run start-electron"
},
to run this script
npm run customStart
You could try start-server-and-test npm module. It has different purpose, but it could work for your scenario.
From documentation:
This command is meant to be used with NPM script commands. If you have
a "start server", and "test" script names for example, you can start
the server, wait for a url to respond, then run tests. When the test
process exits, the server is shut down.
"scripts": {
"start-server": "npm start",
"test": "mocha e2e-spec.js",
"ci": "start-server-and-test start-server http://localhost:8080 test"
}
}
To execute all tests simply run npm run ci.
Another alternative could be concurrently combined with wait-on as #Slim said
From documentation:
wait-on will wait for period of time for a file to stop growing before
triggering availability which is good for monitoring files that are
being built. Likewise wait-on will wait for period of time for other
resources to remain available before triggering success.
I solved it by using concurrently
npm i concurrently
In my package.json
"build": "concurrently \"npm run build-react\" && npm run build-jsx",
I'm using it to build an Adobe extension using react, and I need to bundle my extendscript after the react-scripts build, which would otherwise delete my .jsxbin
I have my package.json as below. I would like to trigger a bamboo build through npm scripts which should trigger npm install and then it should trigger npm run bamboo.
I am trying to make the build fail if my testcases fail.kindly help in how to configure in bamboo to achieve the same
"scripts": {
"dev": "webpack",
"prod": "webpack -p",
"start": "webpack-dev-server --open",
"build": "npm run clean-dist && npm run dev && npm run start",
"pbuild": "npm run clean-dist && npm run prod && npm run start",
"clean-dist": "rimraf ./dist && mkdir dist",
"lint": "esw webpack.config.js app",
"lint:watch": "npm run lint -- --watch",
"test": "karma start --reporters html",
"pro": "protractor protractor.config.js",
"bamboo": "npm run clean-dist && npm run dev && npm run test"
}
In bamboo plan configuration:
1. Add new task
2. Select 'npm' type
3. Select Node.js executable - version of your nodeJs, installed on the server
4. Command: run test
This will run your 'test' script from package json
The head of my pulled down development branch is: b81ff687b28d41a897d2f527ffb79ef28c89b7a2
There doesn't appear to be a gulp file
As far as I can tell, QuillJS has never used gulp. The 0.20 branch has a Gruntfile, but it's been removed by the 1.0 branch.
Instead of grunt or gulp, Quill uses npm scripts for its build tasks. You can see them defined in the "scripts" section of the package.json file.
"scripts": {
"build": "webpack --config _develop/webpack.config.js --devtool hidden-source-map",
"start": "npm run build; foreman start -f _develop/procfile",
"test": "npm run build; karma start _develop/karma.config.js",
"test:coverage": "webpack --config _develop/webpack.coverage.js; karma start _develop/karma.config.js --reporters coverage",
"travis": "karma start _develop/karma.config.js --reporters dots,saucelabs"
}
These can be run by the command npm run [name of script], e.g. npm run build. (npm test exists as its own command which is essentially an alias for npm run test; though it handles errors a bit differently)