I am including my non-exported function (let's say A) to the Jest unit tests with the 'rewire' function. When I run the coverage test, the A function is not included to the coverage test. Is there any way to include rewired files to the coverage test?
Is there any configurations which should be provided to the babel.config.json?
{
"presets": ["#babel/preset-env"],
"plugins": ["babel-plugin-rewire"]
}
Related
When I create a new Mocha test file I am presented with the expected green gutter icons (▶ and ▶▶) to run each test or the suite. When I select "Run [test name]" I expect it to create a Mocha debug configuration and run it. Instead, IntelliJ creates a NodeJS run configuration, which understandably explodes in a shower of bit-flavored WTF.
If I manually create a configuration for the whole file, everything works as expected, including individual tests afterward. I am hoping that there is a setting somewhere that I have overlooked, something like "Settings -> ... -> Default Debug Configuration".
Does anyone know how I can make IntelliJ default to Mocha when a unit test is executed?
The logic used for determining what test runner is available for a given test file is based on dependencies declarations in package.json nearest to current file. Do you have 'mocha' listed as a dependency/dev dependency in your package.json? How many package.json files do you have in your project?
Note that, if Mocha is not installed locally/included in package.json, you can create a Mocha run configuration with "All in directory" selected and specify a directory where your spec files are located. In this case, clicking the gutter button in a test file inside this directory will suggest to run test with Mocha.
Note also that if you have created Node.js Run configuration with "JavaScript file" set to your mocha test file, IDEA will suggest using this configuration instead of Mocha when clicking on your tests, because explicitly created run configurations associated with current file have priority over the ones auto-generated from context. Deleting the configuration should solve the issue.
I am using JacocoTestReport for code coverage and it doesn't cover Power mock code coverage.
I know Jacoco and Powermockito don't go well together but wondering if there is a workaround in gradle.
I am using the below jacoco in gradle
dependencies {
jacocoTestReport 'org.jacoco:org.jacoco.ant:0.7.2.201409121644'
}
I'm downloading the google maps API v3 via a script tag, and I'm adding the dependency to my modules with the following (relevant) package.json configuration:
"browserify-shim": {
"google": "global:google"
}
And I can add the dependency in my files with the following:
var google = require('google');
When I run my code in the browser, it works fine.
The problem is, when I run my tests with Jest, it tells me that it can't find the 'google' module:
Error: /src/app/assets/javascripts/__tests__/helpers-test.js: Cannot find module 'google' from '/src/app/assets/javascripts/__tests__'
Note:
This dependency is being required in the file that I'm testing, not the test itself. I find this confusing since I thought that Jest mocks all dependencies unless it is specified otherwise, but from what I can see, it first needs to correctly satisfy the dependencies before mocking.
Any ideas of what am I missing or what approach should I take?
You'll need to alias 'google' properly in your package.json, see here.
The Karma coverage documentation mentions a bad configuration example:
In this example also JASMINE and JASMINE_ADAPTER get included but they shouldn't as these file are only for the test setup used and not for your program.
However, on the files documentation page, they mention that you should include JASMINE and JASMINE_FRAMEWORK in the files array.
I would like to use Karma with Jasmine. And I would like to try out the code coverage.
So how do I set this up?
I'm writing a crate which consists of multiple modules spread across multiple files. These modules are interdependent, i.e. some of the modules use other modules inside this crate.
Is it possible to run tests in such modules separately from other modules in the crate? Running rust test some_module.rs does not work if some_module.rs contains references to other modules in this crate. Running rust test my_crate.rc does work, but it runs tests from all of crate modules, which is not what I want.
It is possible to run a subset of the tests:
> rustc --test my_crate.rc
> ./my_crate some_module
... test output ...
This will run any function for which the full path contains some_module. There is a fairly detailed help page for unit testing on the wiki, including this use case.
Note that rust test doesn't support this (yet!), so you have to compile the test runner and invoke it by hand (or, write a Makefile/script to do it).