chai-http not exiting after running tests - mocha.js

I ran into a problem where my mocha tests were not finishing after running with chai-http. Mocha just hangs after the tests and eventually runs into a timeout (at least on my CI).

Turns out, Mocha (4.0) changed their behavior regarding the termination of the tests. The best workaround I have found is to add the --exit flag to the npm script to revert to pre-4.0 behaviour.
...
"scripts": {
"start": "node server.js",
"test": "mocha --exit"
},
...

Related

How do I pass Cypress arguments to a NPM e2e build job?

How do I pass Cypress arguments to a NPM e2e build job?
I tried something like this but I cannot get variables to expand:
USERNAME=$EMAIL PASSWORD=$SECRET ng e2e --config-file=dev-cypress.config.ts
I also tried this:
ng e2e -- --USERNAME=$EMAIL --PASSWORD=$SECRET --CYPRESS_CONFIG_FILE=dev-cypress.config.ts
ng e2e --USERNAME=$EMAIL --PASSWORD=$SECRET --CYPRESS_CONFIG_FILE=dev-cypress.config.ts
And I tried this:
CYPRESS_CONFIG_FILE=dev-cypress.config.ts USERNAME=$EMAIL PASSWORD=$SECRET ng e2e
What am I missing? Whatever I try, the Cypress "effective configuration" does not expand the env variables correctly (at all)
Here is my build config in my angular.json config:
....
"e2e": {
"builder": "#cypress/schematic:cypress",
"options": {
"devServerTarget": "pas-ng-xdm:serve",
"watch": true,
"headless": false
},
"configurations": {
"production": {
"devServerTarget": "pas-ng-xdm:serve:production"
}
}
}
NOTE: Using a npx cypress command, that works for me:
"cypress:run:dev": "npx cypress run --config-file dev-cypress.config.ts --record
--key 0000000-e33c-4c88-9ead-1d0000000c --browser chrome --headless",
NOTE 2: When using the ng e2e, my only option is to allow it to load the default cypress.config.ts. Maybe that is ok: perhaps this is working as designed?

How to run lerna sequentially?

Goal
Wish to know how with Lerna to run packages in sequential mode.
Approach
This is learn.json with its packages declaration:
{
"npmClient": "npm",
"npmClientArgs": [
"--registry",
"https://npm.foo.com"
],
"command": {
"publish": {
"ignoreChanges": [
"**/.spec.*",
"**/*.md",
"**/tsconfig*.*"
],
"registry": "https://npm.foo.com"
}
},
"packages": [
"packages/commands/*",
"packages/specs/*",
"packages/support/*",
"packages/tasks/*",
"packages/tools/*"
],
"version": "independent"
}
And in package.json, the following is a sampling of its scripts making lerna run requests:
"audit": "lerna run audit --stream",
"build": "lerna run build --stream",
"clean": "lerna clean",
"postinstall": "lerna bootstrap",
"upgrade": "lerna run npm:upgrade --stream",
"test": "lerna run coverage --stream"
The goal is to modify the package.json script "test" so that lerna runs each of the packages' test sequentially over each of the packages and not in parallel.
And if possible, run tests in a specific order.
How should this "test" script be modified?:
"test": "lerna run test --stream"
lerna run does have a command option --parallel, however, I am experiencing that without this option set, execution is happening asynchronously (parallel):
--parallel Run script with unlimited concurrency, streaming prefixed output.
lerna run --concurrency 1
Global Options:
--concurrency How many processes to use when lerna parallelizes tasks. [number] [default: 10]

How to stop running a suite if previously executed suite fails in protractor?

I am using protractor with jasmine framework. I need solution to stop the execution of running the suite if previous suite fails.
I have three set of test suites as below:
1. Health check - Tests all the web services are returning 200 response.
2. Smoke test - Checks the basic features of front end are looking good.
3. Regression test - Tests all the features.
My requirement is, If health check test case fails then do not run smoke test cases.
This can be achieved through following two ways:
1. Jenkins
2. Using process.exit(1) in the script
But, these two are not fit to my need.
Is there any way to achieve my need through protractor or jasmine way?
You could achieve it using several scripts in package.json. For example:
...
"scripts": {
"health": "launch here only health",
"smoke": "launch here only smoke",
"regression": "launch here only regression",
"test": "npm run health && npm run smoke && npm run regression",
},
...
You will launch all tests using npm run test. If in some command appears error the others will not be execute.

Attaching a debugger to a parcel built app

I have my project setup as follows, within my package.json I have the follow:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "parcel ./public/index.html --open",
"build": "parcel build ./public/index.html NODE_ENV=production --no-source-maps --public-url ./public --out-dir ./dist",
"lint": "eslint --ext .js,.vue src --fix"
},
I can start my project by running: npm run:dev which starts as follows:
To debug the "dev" script, make sure the $NODE_DEBUG_OPTION string is specified as the first argument for the node command you'd like to debug.
For example:
"scripts": {
"start": "node $NODE_DEBUG_OPTION server.js"
}
> impcentral#1.0.0 dev /Users/william/imp/src/impCentral
> parcel ./public/index.html --open
Server running at http://localhost:63188 - configured port 1234 could not be used.
As you can tell it does not stop at my break points within WebStorm. I've tried passing in the $NODE_DEBUG_OPTION within the package.json but to no avail.
Any ideas folks, open to trying this in Visual Studio Code too.
You don't need running your NPM configuration in debugger unless you need debugging parcel itself. As your application, served by parcel, is run in browser, you have to use JavaScript Debug run configuration to debug it.
start your app by running npm run dev (either in WebStorm or in terminal)
create a JavaScript Debug run configuration with your server URL (http://localhost:1234, or http://localhost:63188 in your case):
select this configuration and press Debug

Have npm watch files in background to enable integration with Visual Studio Task Runner

I am trying to have npm watch for file changes in my client side code. I can have it work from the command line ok but I'd really like it to work from Visual Studio task runner.
my package.json looks something like this:
...
"watch": {
"compile": {
"patterns": [
"wwwroot"
],
"extensions": "ts"
}
},
"scripts": {
"prebuild": "copyfiles -f ./node_modules/d3/build/*.js ./wwwroot/lib/d3",
"compile": "tsc && browserify ./wwwroot/app/app.js -o ./wwwroot/bundle.js",
"build": "npm run compile",
"watch": "npm-watch"
},
...
So running npm run build then npm run watch from the command line has everything running as expected.
When I use the Task Runner however to bind my watch script to the After Build event like this:
it never 'exits' and, as such, the build never completes* and Visual Studio waits for me to kill the task before the application runs. Is there a way to have the script run in the background or some kind of 'detached' mode to enable Visual Studio to complete the build and run the application?
I tried using different watch tools but can't find any such option in any of them.
*Actually, I guess the build itself probably DOES complete but VisualStudio never runs the app and just hangs waiting on the script exiting.
Change the watch Bindings to Project Open. Then it will start watching after the project is opened.

Resources