Karma Start, Karma Init, npm test not exiting? - macos

Is it normal behavior for karma start, karma init, npm test to not exit after running? I want to run additional commands but I have to open another window to do it.

I believe you should try below config parameter for Karma..
singleRun
Type: Boolean
Default: false
CLI: --single-run, --no-single-run
Description: Continuous Integration mode.
If true, Karma will start and capture all configured browsers, run tests and then exit with an exit code of 0 or 1 depending on whether all tests passed or any tests failed.
Source - http://karma-runner.github.io/1.0/config/configuration-file.html

Related

Can not deploy my contract on ganache-cli using ETH mainnet fork

I used ganache-cli in combination with my Infura key to fork ETH mainnet so I could use the Uniswap router in my development environment:
ganache-cli --fork https://mainnet.infura.io/v3/<mykeyhere>
This starts my local ganache blockchain without any errors. However when I deploy my contract with truffle:
truffle(development)> deploy
I keep getting the following error:
Compiling your contracts...
===========================
✓ Fetching solc version list from solc-bin. Attempt #1
✓ Fetching solc version list from solc-bin. Attempt #1
> Compiling ./contracts/Migrations.sol
> Compiling ./contracts/MollyCoin.sol
> Artifacts written to /home/dogperson/Code/MollyCoin/build/contracts
> Compiled successfully using:
- solc: 0.6.12+commit.27d51765.Emscripten.clang
UnhandledRejections detected
Promise {
<rejected> CodedError: Given input "NaN" is not a number.
at /home/dogperson/.nvm/versions/node/v12.22.9/lib/node_modules/truffle/node_modules/ganache/dist/node/webpack:/Ganache/chains/ethereum/ethereum/lib/src/forking/handlers/base-handler.js:174:23
at process.promise (internal/process/task_queues.js:97:5)
at ProviderHandler.queueRequest (/home/dogperson/.nvm/versions/node/v12.22.9/lib/node_modules/truffle/node_modules/ganache/dist/node/webpack:/Ganache/chains/ethereum/ethereum/lib/src/forking/handlers/base-handler.js:178:36)
at ProviderHandler.request (/home/dogperson/.nvm/versions/node/v12.22.9/lib/node_modules/truffle/node_modules/ganache/dist/node/webpack:/Ganache/chains/ethereum/ethereum/lib/src/forking/handlers/provider-handler.js:58:9)
at earliestBlock (/home/dogperson/.nvm/versions/node/v12.22.9/lib/node_modules/truffle/node_modules/ganache/dist/node/webpack:/Ganache/chains/ethereum/ethereum/lib/src/forking/persistent-cache/helpers.js:149:5)
at previousClosestAncestor (/home/dogperson/.nvm/versions/node/v12.22.9/lib/node_modules/truffle/node_modules/ganache/dist/node/webpack:/Ganache/chains/ethereum/ethereum/lib/src/forking/persistent-cache/helpers.js:77:19)
at PersistentCache.cache [as initialize] (/home/dogperson/.nvm/versions/node/v12.22.9/lib/node_modules/truffle/node_modules/ganache/dist/node/webpack:/Ganache/chains/ethereum/ethereum/lib/src/forking/persistent-cache/persistent-cache.js:142:47)
at Fork.cache [as initCache] (/home/dogperson/.nvm/versions/node/v12.22.9/lib/node_modules/truffle/node_modules/ganache/dist/node/webpack:/Ganache/chains/ethereum/ethereum/lib/src/forking/fork.js:209:21)
at Fork.fallback [as initialize] (/home/dogperson/.nvm/versions/node/v12.22.9/lib/node_modules/truffle/node_modules/ganache/dist/node/webpack:/Ganache/chains/ethereum/ethereum/lib/src/forking/fork.js:206:13)
at Blockchain.async [as initialize] (/home/dogperson/.nvm/versions/node/v12.22.9/lib/node_modules/truffle/node_modules/ganache/dist/node/webpack:/Ganache/chains/ethereum/ethereum/lib/src/blockchain.js:629:22)
at EthereumProvider.async [as initialize] (/home/dogperson/.nvm/versions/node/v12.22.9/lib/node_modules/truffle/node_modules/ganache/dist/node/webpack:/Ganache/chains/ethereum/ethereum/lib/src/provider.js:195:5)
at Connector.connect (/home/dogperson/.nvm/versions/node/v12.22.9/lib/node_modules/truffle/node_modules/ganache/dist/node/webpack:/Ganache/chains/ethereum/ethereum/lib/src/connector.js:49:5) {
code: -32000
}
} CodedError: Given input "NaN" is not a number.
at /home/dogperson/.nvm/versions/node/v12.22.9/lib/node_modules/truffle/node_modules/ganache/dist/node/webpack:/Ganache/chains/ethereum/ethereum/lib/src/forking/handlers/base-handler.js:174:23
at process.promise (internal/process/task_queues.js:97:5)
at ProviderHandler.queueRequest (/home/dogperson/.nvm/versions/node/v12.22.9/lib/node_modules/truffle/node_modules/ganache/dist/node/webpack:/Ganache/chains/ethereum/ethereum/lib/src/forking/handlers/base-handler.js:178:36)
at ProviderHandler.request (/home/dogperson/.nvm/versions/node/v12.22.9/lib/node_modules/truffle/node_modules/ganache/dist/node/webpack:/Ganache/chains/ethereum/ethereum/lib/src/forking/handlers/provider-handler.js:58:9)
at earliestBlock (/home/dogperson/.nvm/versions/node/v12.22.9/lib/node_modules/truffle/node_modules/ganache/dist/node/webpack:/Ganache/chains/ethereum/ethereum/lib/src/forking/persistent-cache/helpers.js
The contract deploys just fine if I run ganache-cli without --fork. Also if I connect Remix to my forked ganache-cli through Metamask, I am also able to deploy and interact with the contract just fine, which makes me believe that the issue might be with truffle.
Extra info:
Truffle version: 5.5.13
Truffle config file
I tried to do the same thing as you and encountered the same error.
After some research I believe the issue is that ganache is read-only when used to fork mainnet (or any testnet). You can't make any transactions. Only calls.
I was able to achieve the objective by using Hardhat instead of ganache.
First I installed hardhat and initialized the sample project:
https://hardhat.org/guides/project-setup.html
Then I ran hardhat with:
npx hardhat node --fork "https://mainnet.infura.io/v3/<ACCOUNT>"
Then I ran "truffle console" in a separate terminal window, with the following lines in truffle-config.js:
const HDWalletProvider = require('#truffle/hdwallet-provider');
const mnemonic = "test test test test test test test test test test test junk";
module.exports = {
networks: {
development: {
host: "127.0.0.1",
port: 8545,
network_id: "*",
provider: () => new HDWalletProvider(mnemonic, "http://127.0.0.1:8545"),
}
}
}
The mnemonic I used is "test test test test test test test test test test test junk" because that is Hardhat's default mnemonic and I was not immediately able to figure out how to configure Hardhat with a different mnemonic.
Before running the truffle console, remember to install the hdwalletprovider npm package in your truffle directory: https://www.npmjs.com/package/#truffle/hdwallet-provider
At this point I have a running truffle console connected to local hardhat process which is connected to infura. I can make transactions to deploy and interact with contracts.
Hope this helps, and good luck.

Test run in cypress headless gives error cy.click()

I've a test cases written in cucumber and cypress. The test case run successfully through cypress Test runner, but fails while running through headless mode using the command.
node_modules\.bin\cypress run --spec **/*.features
CypressError: Timed out retrying: `cy.click()` failed because this element is not visible:
Questions:
what is the possible reason to have this element not visible error?
How can i handle the wait in headless mode?
The fix is :
Fix all your issues displayed on the console w.r.t xpaths, sync or
any such.

Running only failed test cases in Cypress

While running Cypress scripts, some of the cases are getting failed. I want to run only those failed cases to run again.
How can I run only failed test cases in Cypress?
As long as its not integrated directly in Cypess, you can use a npm package like cypress-run
npm install cypress-run --save
Then edit then run command in the package.json and replace the command
cypress run by for example cypress-run --retries 4, this will retry the failed tests 4 times
Cypress has released version 5.0 which has support for retries, see https://docs.cypress.io/guides/guides/test-retries.html for more information
Just add this line in your cypress.json file.
{
"retries":2
}
It will retry your failed Test case for twice.

Failed test in protractor stops the execution for rest test cases

I am running the protractor Suite (spec file having multiple test cases), If any test case fails, protractor does not continue with the next test case execution and all the rest of test cases also fail.
EXPECTED BEHAVIOR:
Upon failure on any test case, protractor should continue with next test case execution.
I used "Protractor-Fail-Fast" Npm package to stop the rest test case execution if any test case fail. But ideally I am not looking for the same.
But this will not help me!
Just for reference: In Visual Studio MS test, If I created ordered test (same as Spec file in protractor having multiple test cases) and then set test setting like "continue on failure", ordered test execution will continue even if some test case failed.
I am looking for a similar test setting or any solution for protractor.
If you dont't want to stop all tests run just stop using Protractor-Fail-Fast library? Protractor tests run till the end by default even if some of the tests are failed.
set ignoreUncaughtExceptions: true in config file as following:
/**
* If set, Protractor will ignore uncaught exceptions instead of exiting
* without an error code. The exceptions will still be logged as warnings.
*/
ignoreUncaughtExceptions?: boolean;
you can get above description from here
export.config = {
...
ignoreUncaughtExceptions: true
}

TravisCI passes despite tests failing, Gulp setup with tests on Jasmine + Frisby

I'm using the gulp-jasmine-node plugin to run my Jasmine/Frisby.js tests like so:
gulp.task('runJasmine', function() {
return gulp.src(['test/*spec.js'])
.pipe(jasmineNode({
timeout: 10000
}));
});
gulp.task('test', ['runJasmine']);
Running gulp test locally I get the following (snippet only):
2) Frisby Test: Get API root
[ GET http://localhost:8080/api ]
Message:
Error: Header 'content-type' not present in HTTP response
Stacktrace:
Error: Header 'content-type' not present in HTTP response
at null.<anonymous>
...
Finished in 0.042 seconds
1 test, 2 assertions, 2 failures, 0 skipped
My .travis.yml:
language: node_js
node_js:
- "0.12"
- "4.2.4"
- "5.3.0"
before_script:
- npm install -g gulp
script: gulp test
And the corresponding raw CI output on Travis (end snippet only):
Finished in 0.054 seconds
[31m1 test, 2 assertions, 2 failures, 0 skipped
[0m travis_time:end:00bb9734:start=1455472901504935117,finish=1455472903105906383,duration=1600971266
[0K [32;1mThe command "gulp test" exited with 0.[0m
Done. Your build exited with 0.
I'm not sure why the build is passing despite failures - is there a certain configuration in Travis when using gulp, depending on test tool used? Is it due to the process exiting with code 0, and if so, do I need to modify my gulp command to exit the process on failure (not ideal as would interrupt other tasks in the runner).
Can't seem to find this problem or identical setup pre-addressed. Please help! Also, this is my first Stack Overflow Q, so hopefully I've provided all info needed. Thanks :)
This answer is not related to jasmin/frisby. But still might help other people looking on the gulp exiting with 0 on failing tests and having travis ci pass.
Here's my gulp test
gulp.task('test', function () {
mochify('./src/js/__tests__/**/*.js', {
extension: ['.jsx', '.js'],
node: true,
path: ['./src/js/'],
watch: false,
})
.transform(babelify)
.transform(envify({
_: 'purge',
NODE_ENV: 'production',
}))
.on('error', function(){
// Exits gulp with error
process.exit(1);
}).bundle()
});
The part which I figured out was that you can manually exit gulp with an exit code non 0 via process.exit(1); and then travis will fail.

Resources