Protractor JS pre-processors - node.js

I am aware that there is the option within Karma to use pre-processors however, in Protractor I can't see the same sort of thing. I am currently using the onPrepare option but I am wondering if it is possible / currently if there is a way to have the a npm module to always run prior (basically the same as the onPrepare) but by the config and not having to do any require etc.

Try using something like scripts in your package.json:
"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",
}
By saying 'npm run protractor' in your cmd, both scripts in pre-(setUp.js) and postprotractor (tearDown.js) will be run before and after your e2e tests.

Related

Can not run Nodemon in node project build with Typescript (In Windows)

Node project is built with Typescript and there are three script in package.json file but when I run it shows ...
If i run this project in ubuntu it works fine but not in windows
Image of output terminal
but after this nodemon is not start to run project.
Script in Package.json
"start": "tsc --watch & nodemon dist/index.js",
"lint": "tslint -c tslint.json 'src/**/*.ts' --fix",
"build": "tsc"
Help me to solve this, Thank you in advance :)
You seem to be missing an & character between tsc --watch and nodemon dist/index.js. A single & is not a valid and operator:
"start": "tsc --watch && nodemon dist/index.js",
Update It looks like the issue is on Windows. Commonly this issue is solved by using a library such as concurrently or cross-env to execute commands in a similar way on Windows. After you've installed concurrently:
"start": "concurrently \"tsc --watch\" \"nodemon dist/index.js\"",
Hopefully that helps!

Heroku not running the postinstall or heroku-postbuild commands:

I'm trying to deploy an app that makes use of the MRE SDK to Heroku. As of this writing, the SDK itself is broken, and attempting to run an npm run build will result in an error.
A work around is to copy a modified animation.d.ts file over to the resulting node_modules folder, after the install (specifically ./node_modules/#microsoft/mixed-reality-extension-sdk/built/animation/).
I keep this file in a folder called v0.16_mre_fix.
Without this, the build will fail. So I added this to my package.json file.
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"clean": "tsc --build --clean",
"heroku-postbuild": "cp -i ./v0.16_mre_fix/*.ts ./node_modules/#microsoft/mixed-reality-extension-sdk/built/animation/",
"build": "tslint -p ./tsconfig.json src/**/*.ts && tsc --build",
"lint": "tslint -p ./tsconfig.json src/**/*.ts",
"start": "node .",
"debug": "node --nolazy --inspect-brk=9229 ."
},
According to heroku here, heroku-postbuild will be run after installing dependencies. This, however, did not work.
So I tried changing it to heroku-prebuild and postinstall:. They didn't work either.
Am I missing something?
EDIT: I also tried
"heroku-prebuild": "echo This runs before Heroku installs your dependencies.",
but I didn't see any echo in the ensuing git push.

Npm start deletes new files from .nuxt

Whenever I run "npm start" it always deletes, and even "reset" files, that I add in my .nuxt folder. As in, when I add, as an example, a new component in the .nuxt > "components" folder, press CTRL + C in cmd to stop the server and then restart running "npm start", it always "resets" the .nuxt folder to its initial/install state. Why is this happening?
I am using "FeathersJS" for backend and "NuxtJS" for frontend.
package.json:
"scripts": {
"test": "npm run eslint && npm run mocha",
"eslint": "eslint src/. test/. --config .eslintrc.js",
"build": "nuxt build",
"dev": "SET DEBUG=nuxt:* && nodemon --watch src/ --watch config/ src/index.js",
"prestart": "npm run build",
"start": "SET NODE_ENV=production && nodemon src/",
"mocha": "mocha test/ --recursive"
},
You shouldn't even add or delete anything from .nuxt. It is files generated by .nuxt. You should modify your sources only, not a generated files.
I have found my own solution now. The solution can be found here, for future reference: https://github.com/fexell/FeathersJS-NuxtJS

Using Nodemon or something similar to listen for changes, first build, then start?

Using Nodemon or something similar to listen for changes, first build, then start? Is it possible?
"scripts": {
"build": "npm run build:dll && webpack --progress",
"start": "node app.js",
}
Make sure nodemon is installed (npm install -g nodemon or npm install --save-dev nodemon) and then just change your package.json to this:
"scripts": {
"build": "babel lib -d build --copy-files",
"start": "nodemon build/index.js"
}
EDIT:
Add a nodemon.json on the root of your project, in there insert your build script in the "events.restart" section as documented here: https://github.com/remy/nodemon/blob/master/doc/sample-nodemon.md
"events": {
"restart": "your build script here"
}
And finally run with "npm run start". This run your app with nodemon and nodemon's configuration will execute your build very time you change your code (on restart)

node.js npm package commands are often broken on Windows - can this be fixed?

There's a big problem for node.js / npm users on Windows. The problem is that many package.json scripts contain commands that are platform specific.
On of the biggest specific problems is commands that set an environment variable and run a command, at the same time. This syntax is not compatible with Windows. There is an example below extracted from a package.json rife with the problem.
So the question is, how can I transform package.json scripts from being Unix compatible to being Windows compatible, in terms of setting environment variables?
I'm wondering if there is a general solution rather than the current manual solution which is to edit the package.json and change all the commands from Unix to Windows compatible.
A further problem of course being that on Windows, environment variables are set in a different way depending on whether you are using Powershell or cmd.
"scripts": {
"test": "NODE_ENV=test mocha --compilers js:babel/register --recursive --require ./test/setup.js $(find test -name '*.spec.js')",
"test-watch": "npm test -- --watch",
"test-e2e:crdv": "chromedriver",
"test-e2e": "NODE_ENV=test mocha --compilers js:babel/register --require ./test/setup.js --require co-mocha ./test/e2e.js",
"lint": "eslint .",
"hot-server": "node server.js",
"build": "NODE_ENV=production webpack --config webpack.config.production.js --progress --profile --colors",
"start": "electron .",
"start-hot": "HOT=1 NODE_ENV=development electron .",
"package": "NODE_ENV=production node package.js",
"package-all": "npm run package -- --all"
},

Resources