how should i fix jest integration test errors causing due to timeout? - npm

I'm getting inconsistent results when every I run npm test
Sometimes all test pass and most of the time one or the other test fails due to this error:
Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.
at node_modules/jest-jasmine2/build/queue_runner.js:68:21
at Timeout.callback [as _onTimeout] (node_modules/jsdom/lib/jsdom/browser/Window.js:678:19)
I have noticed when ever test files name is printed twice or thrice some test fails.
I'm using WSL to run the tests and I have configured jestjs like this:
"scripts": {
"test": "jest --watchAll --verbose --coverage"
},
"jest": {
"testURL": "http://localhost/"
},
how should I configure jest so the tests run properly or fix this inconsistent behavior?

Related

How to pass argument into NPM script without double dashes

//package.json
"scripts": {
"run-tests": "node scripts/run-tests.js"
}
When I run my test suite using npm run run-tests --env=integration --variant=alpha, I get undefined argument values:
//run-tests.js
console.log(argv.env) //undefined
console.log(argv.variant) //undefined
However, when I run my test suite with two dashes (--) npm run run-tests -- --env=integration --variant=alpha, I get my argument values:
//run-tests.js
console.log(argv.env) //integration
console.log(argv.variant) //alpha
Can I somehow get my argument values in run-test.js without using --?
Based on the discussion in this pull request, I believe the answer to your question is no :(
However, a workaround is to specify your arguments in the package.json file in the scripts block. This is preferred in a CI/CD context, as you want less coupling with your CI/CD provider.
In package.json
"scripts": {
"test:int:a": "node scripts/run-tests.js --env=integration --variant=alpha",
"test:int:b": "node scripts/run-tests.js --env=integration --variant=bravo"
}
Then on command-line:
npm run test:int:a
If you are going more for a command-line tool, I suggest looking into creating a
CLI tool with node.js, such as this example.

How to set timeout while doing vue-cli unit test

I am performing vue unit through below command
vue-cli-service test:unit
Now the problem is some unit test case need the response from the server, and usually they take much time to execute.
So i want to know how to manually set the timeout for vue-cli unit tests
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure
"done()" is called; if returning a Promise, ensure it resolves.
Try as below
vue-cli-service test:unit --timeout, -t timeout threshold in milliseconds

How to customize botium mocha timeout

I am trying to connect to directline using the following setup:
botium_directline.json:
{
"botium": {
"Capabilities": {
"PROJECTNAME": "botium-sample1",
"CONTAINERMODE": "directline3",
"DIRECTLINE3_SECRET": "<BOTIUM_SECRET>",
"DIRECTLINE3_WEBSOCKET": true
},
"Sources": {},
"Envs": {
"NODE_TLS_REJECT_UNAUTHORIZED": 0
}
}
}
Folder structure:
If I run:
botium-cli emulator browser --convos ./spec/convos --config ./botium_directline.json
I am able to "communicate with the bot" within the new conversation.
If I wanna run the tests I prepared I get the following timeouts:
botium-cli run --convos ./spec/convos/ --config ./botium_directline.json
user # /Users/username/workspace/testing/botium
~~ npm test
> botium#1.0.0 test /Users/username/workspace/testing/botium
> botium-cli run --convos ./spec/convos/ --config ./botium_directline.json
Botium Test-Suite
1) Test One
2) Test Two
0 passing (4s)
2 failing
1) Botium Test-Suite
Test One:
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
2) Botium Test-Suite
Test Two:
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
The error is similar to a standard mocha timeout error, but I do not know where to put a .js file to increase the timeout in a beforeEach.
I attempted to add both BOTIUM_TIMEOUT or a TIMEOUT properties into the botium_directline.json but this did not do anything.
Any ideas how to increase the timeout?
Botium automated tests have default timeout of 60000 milliseconds, but you can customize it by passing the --timeout flag at the end of your CLI command.
To do that, just add the flag --timeout followed by the time in milliseconds you'd like to set it up for. For instance, for 100000 milliseconds, your command should be like this: botium-cli emulator browser --convos ./spec/convos --config ./botium_directline.json --timeout 100000
The "BOTIUM_TIMEOUT" environment variable is the correct choice, or you can use the "--timeout" command line switch for botium-cli. This is only available since some days, there was a bug involved which has been fixed. Please get the build 0.0.34 of the botium-cli:
npm install botium-cli#0.0.34

e2e tests fail on server with selenium

I'm about to create an application full js based on vuejs. Following https://github.com/vuejs-templates/webpack, I have started a project:
$ vue init webpack my-project && cd my-project && yarn install
When I run unittest yarn run unit everything goes well, but when I run yarn run e2e which runs nightwatch.js, I get this error:
> Starting dev server...
Starting to optimize CSS...
> Listening at http://localhost:8889
Starting selenium server... started - PID: 23451
started - PID: 23451
[Test] Test Suite
=====================
Running: default e2e tests
[client :: capabilities] Test Suite
=======================================
Error retrieving a new session from the selenium server
Connection refused! Is selenium server started?
{ Error: socket hang up
at createHangUpError (_http_client.js:344:15)
at Socket.socketOnEnd (_http_client.js:436:23)
at emitNone (events.js:110:20)
at Socket.emit (events.js:207:7)
at endReadableNT (_stream_readable.js:1047:12)
at _combinedTickCallback (internal/process/next_tick.js:102:11)
at process._tickCallback (internal/process/next_tick.js:161:9) code: 'ECONNRESET' }
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
The selenium server is started on the fly when the e2e tests start and is shutdown when they finish. I'm sure because when I stop nightwatch.js before it fails I see :
$ ps aux | grep -i selenium
java -Dwebdriver.chrome.driver=node_modules/chromedriver/lib/chromedriver/chromedriver -jar node_modules/selenium-server/lib/runner/selenium-server-standalone-2.53.1.jar -port 4444
So the real error based on the output I get is mostlikely Error retrieving a new session from the selenium server. How do I fix this?
package.json
"chromedriver": "^2.27.2",
"cross-spawn": "^5.0.1",
"nightwatch": "^0.9.12",
"selenium-server": "^2.53.1",
test/e2e/nightwatch.conf.js
require('babel-register')
var config = require('../../config')
// http://nightwatchjs.org/gettingstarted#settings-file
module.exports = {
src_folders: ['test/e2e/specs'],
output_folder: 'test/e2e/reports',
custom_assertions_path: ['test/e2e/custom-assertions'],
selenium: {
start_process: true,
server_path: require('selenium-server').path,
host: '127.0.0.1',
port: 4444,
cli_args: {
'webdriver.chrome.driver': require('chromedriver').path
}
},
I recently started a Vue.js project with Webpack template. Your problem sounds familiar, but surprisingly, I forgot how I solved it...
The only difference I can see between your package.json and mine is the selenium-server version (^3.0.1). You should also check your Node version because Nightwatch is based on it. I remember that I had to update Node and npm for some reason (I do not use Yarn).
This is my environment (and it is working fine):
Node.js (v8.1.3)
npm (5.0.3)
Did you run node nightwatch.config.js, or node {whatever your nightwatch config file is called}. This will install Selenium and ChromeDriver correctly.

NPM Concurrently not running mocha test

I am using the npm package concurrently to run multiple processes needed for a test.
When I run mocha alone like this:
./node_modules/mocha/bin/mocha --harmony ./tests/
it works fine. But when I try to use it with concurrently like this:
./node_modules/concurrently/src/main.js "./node_modules/mocha/bin/mocha --harmony ./tests/"
I get an error like this:
throw new Error("must provide pattern")
[0] ^
[0] Error: must provide pattern
[0] at new Glob (/Users/my-project/node_modules/mocha/node_modules/glob/glob.js:121:11)
It worked by adding the mocha part as a script in package.json
"scripts": {
"mocha": "./node_modules/mocha/bin/mocha --harmony ./tests/"
},
and then this:
./node_modules/concurrently/src/main.js "npm run mocha"