Angular cli, overwrite the command that gets run by 'ng e2e'? - node.js

I'm trying run Angular's e2e tests against an instance of the application ON A DIFFERENT SERVER than my local machine.
So to be clear, I'm not testing my local code.
I just need to run protractor without the angular build steps because it's a waste of time since the code I'm testing is on another server. Unfortunately, the angular.json file throws an error if i excessively modify/remove the following line:
"builder": "#angular-devkit/build-angular:protractor",
I already have a solution for this, but it's long winded and I'd like to be able to not change how my teammates are running tests from their shells:
node node_modules/protractor/bin/protractor e2e/protractor.conf.js
I have two thoughts:
Write npm script which runs this command (what i'll likely end up doing)
Find out how to overwrite what ng e2e does. If I can run the more complicated command here, it'll save productivity and feedback time.
I'm on Angular V7.
Is overwriting ng e2e so that it executes node node_modules/protractor/bin/protractor e2e/protractor.conf.js instead possible?

Yup. I would do #1. That makes sense to update your package.json
"scripts": {
"protractor": "protractor e2e/protractor.conf.js"
}
and then just run npm run protractor. The e2e command is also downloading chromedriver, the selenium jar file, and maybe geckodriver? with webdriver-manager. If you want that as a pre-step:
"scripts": {
"protractor": "protractor e2e/protractor.conf.js",
// just download chromedriver and the selenium jar
"preprotractor": "webdriver-manager update --gecko false"
}
It also starts your angular application. If you need to do that, I would just call ng serve and run it in a background process. I hope that helps.

Related

npm-run-all failing when running a "tsc-watch" command in parallel

I am trying to use npm-run-all to manage running two servers at the same time. For one of the servers, I am trying to run it in a watch mode using tsc-watch.
The command looks like such:
"start": "tsc-watch --onSuccess \"node dist/server.js\""
npm-run-all starts up both of the servers successfully. tsc-watch also watches the Typescript file for changes and automatically recompiles it successfully.
However, when tsc-watch recompiles the Typescript file and restarts the server, it seems like npm-run-all stops working properly. Specifically, if I try to kill both of the servers by pressing CTRL + C in the terminal (OSX), it will only kill the server that tsc-watch recompiled while the other server remains running.
I'm thinking that there must be a way to fix this. Anyone have some tips for me?
Found an answer. I think this is just a bug with npm-run-all. Using concurrently instead doesn't experience this issue (kills both servers when hitting CTRL-C).

Run E2E tests in IDE or command line

I'm using Stencil.js to create a web component library and I'm heavily relying on E2E tests. As they're rather slow it becomes more and more cumbersome to run the entire test suite (using the Stencil.js CLI) while developing new components.
However, I'm not able to run single tests in my IDE (IntelliJ IDEA) or via command line. It works perfectly fine for unit tests though.
My Jest config looks like this:
module.exports = {
"roots": [
"<rootDir>/src"
],
"preset": "#stencil/core/testing"
}
When I try to run tests in a single file (jest --config jest.config.js --testPathPattern src/components/button/button.e2e.ts$)
it fails, because
newE2EPage() is only available from E2E tests, and ran with the --e2e cmd line flag.
newE2EPage() comes with Stencil.js and I don't know what Stencil.js's CLI does in the background. Furthermore, I cloned the Stencil.js repository, just to see if it is working with their E2E tests (https://github.com/ionic-team/stencil/tree/master/test/end-to-end) but it doesn't work either.
Any idea how I can configure Jest so that it's able to run Stencil.js-E2E tests from the command line?
The --e2e flag is used for the npm script in the package.json. To start e2e tests, you can add this in your package.json:
"scripts": {
"test:e2e": "stencil test --e2e"
}
And run npm run test:e2e. For a specific file, you add it at the end like this:
npm run test:e2e src/components/button/button.e2e.ts
For more info, see the StencilJS doc: https://stenciljs.com/docs/end-to-end-testing
i have the same problem. IntelliJ and 'Run' single 'it' didnt work.
newE2EPage() is only available from E2E tests, and ran with the --e2e cmd line flag.
when i run 'npm run test' everything will work fine. the difference is that npm run stencil before and only jest dont work.
here is the stencil jest dir https://github.com/ionic-team/stencil/tree/master/src/testing/jest aswell a config.
i found in here https://stenciljs.com/docs/testing-overview a VS-CODE run jest code but no Intellij setup.
im on the run to get the path of the current file to run stencil via npm and the path the e2e file. but i cant find the correct variable for the run config.
i hope we got this solved soon.
cheers
I am not a VS Code user, but in contrast to IntelliJ there is a launch.json for VSC to run single tests: https://github.com/ionic-team/stencil-site/pull/480

How to run a 'watch' script along with a 'start' script in my node.js project

I'm writing an app that is composed of microservices (I use micro).
I really like es6, so I use Babel to make the development process easier. The problem that I have is that I need a script that would compile my es6 code and restarted the 'server'; I don't know how to achieve this.
Right now I have the following script in my package.json:
"scripts": {
"start": "yarn run build && micro",
"build": "./node_modules/.bin/babel src --out-dir lib"
},
When I run yarn start my es6 code compiles successfully and micro starts the server. However, if I make changes to my code, I'll have to manually stop the server and run yarn start again.
I've tried to change my build script
"build": "./node_modules/.bin/babel src --watch --out-dir lib"
But in this case the micro command does not get executed as the build script just watches for changes and blocks anything else from execution. My goal is to have a script that would watch for changes and restart the server if a change occurred (compiling the code beforehand) like in Meteor.
One option is using ParallelShell module to run shell commands in parallel. You can find an example of how to use it here
The simplest solution would be to yarn run build & micro (note the single & and not &&).
As mentioned by others, parallelshell is another good hack (probably more robust than &).

`npm test` never exits

I use mocha to run my unit tests, and often use npm test in order to run it. My package.json contains these script definitions:
"pretest": "NODE_ENV=test node migrate all",
"test": "DEBUG= NODE_ENV=test mocha --recursive",
If I run either one of these commands directly in my shell (i.e. not going through npm) they execute fine (790 tests takes about 2m to run, the migration script is done in under 1s). The processes also exit cleanly.
If, however, I run these via npm test, everything runs in exactly the same way but the process doesn't exit (I have to manually cancel it with ^c).
I can't work out how to debug exactly what is going on here in order to work out why the process isn't exiting.
It's worth noting that if I test a subdirectory (npm test ./test/queue) which does not interact at all with the database, then the process exits fine. These tests do, however, interact with an AMQP broker so there is some activity over sockets. This suggests to me that the database connection is causing the problem. I am using knex to connect to a postgres9.6 server. This also suggests that the pretest script is not the problem. If I try to run a suite of tests which do interact with the database, the process never exits (so presumably the open sockets are preventing it from doing so, but why this should only happen in the case of npm test rather than direct execution is beyond me).
Extra info:
node version: 8.7.0
mocha version: 4.0.1
npm version: 5.6.0
knex version: 0.14.0
I am using async/await in my codebase
I was mistaken in thinking this to be an npm problem. Rather, when I was running mocha in my shell it was using the globally installed mocha, which is of a different version to the locally installed one. Running with this version causes the same hanging issue.
This change in behaviour appears to be coming from this issue, which is described thus in the changelog:
By default, Mocha will no longer force the process to exit once all tests complete. This means any test code (or code under test) which would normally prevent node from exiting will do so when run in Mocha. Supply the --exit flag to revert to pre-v4.0.0 behavior (#ScottFreeCode, #boneskull)

How to run tests with gruntJS

So, how do I run the test suite in gruntjs? I thought it should be pretty simple and straight-forward but well, for me it wasn't :)
Since gruntjs should be able to run tests I thought that I could just run "grunt test", but that for some reason requires the server to run. I tried starting it in another process with "grunt server watch" but then again the "grunt test" fails.
How is grunt supposed to work?
'grunt test' is a task that starts server too when required. It starts a test runner, for example karma and karma runs the tests in browser environment.
The trick is to run karma and provide configuration items in karma.conf.js
A sample gruntfile on gruntjs website shows how to make qUnit work with grunt.

Resources