Configure react-scripts test/react-testing-library to be used for integration & unit tests - reactjs

I'm using react testing library to write both integration and unit tests. From what I've read, when I run yarn test, the testing framework looks for any file with the.test.tsx extension and runs the tests in those files.
I have two directories for tests, unitTests and integrationTests and I'm wondering if there's a way to only run the tests in the unit test directory and then only run the tests in the integration test directory for CI? Should I consider using a different test runner for unit tests and react testing library for unit tests, or is there a way to configure react testing library to only run files in one directory? I know I can set up a pattern via the test runner in the terminal, but am not sure how transfer that to the scripts section of my package.json Thanks in advance.

Related

Jest reference not found when running JS test using Chutzpah

I want to integrate my Jest unit tests to TFS CI, so that during build it shows the Jest unit Test results in Build output of TFS. I used a extension Chutzpah. Below are references for it :
https://visualstudiogallery.msdn.microsoft.com/f8741f04-bae4-4900-81c7-7c9bfb9ed1fe
https://blogs.msdn.microsoft.com/visualstudioalm/2012/03/01/visual-studio-11-beta-unit-testing-plugins-list/
I followed https://blogs.msdn.microsoft.com/matt-harrington/2014/10/27/javascript-unit-testing-using-the-chutzpah-test-runner-in-visual-studio/ to set up chutzpah but my test are failing to discover Jest reference.
We are using Jest preprocessor as Babel-preset-jest, babel-preset-es2015, babel-preset-es2015. I tried adding those reference to test.js file. But still it failes with message Error: ReferenceError: Can't find variable: jest.
Can someone help with exactly what references needs to be added for React js application to discover Jest unit tests in chutzpah. Or any reference to any react js application where such scenario is done.
Currently when executing Jest test using NPM Test it runs correctly, but I want it to be discovered in VS test explorer
This is because Chutzpah doesn't support Jest. Based on the documentation it currently only supports QUnit, Jasmine and Mocha.
I'm not familiar with Chutzpah but you'll need to implement a new framework definition that will include Jest in the test execution environment.

How to run a single test file with Karma/Jasmine?

I'm using Karma and Jasmine for testing my Angular JS code. I managed to run all the tests in my project using Karma, but if I try to run just a single file I'm getting the following error: ReferenceError: describe is not defined. Is it possible to run just a single test file and if yes then how?
P.S. I'm using Intellij IDEA.
Although it's not ideal, you can replace describe (and it) with fdescribe (and fit) so only those tests will be executed
On the other hand, xdescribe / xit excludes the tests from your suite
If you use Gulp, you can combine gulp-karma & yargs to pass in a pattern as argument.
source: https://stackoverflow.com/a/27696472/1782659
If you are like me and you've inherited a suite of tests that are controlled by a task runner (e.g. gulp) and you are getting failures but are unsure which file is actually failing you can sanity check an individual file by running jasmine directly against it:
1.) Make sure you have jasmine installed (it may not be if wrapped inside your task runner configuration)
npm install jasmine
2.) Run jasmine against file:
./node_modules/.bin/jasmine /path/to/my/spec/file.js
or
./node_modules/jasmine/bin/jasmine.js /path/to/my/spec/file.js

Packaging Smoke tests as an (additional) executable jar in Gradle build

We have a gradle build creating a SpringBoot web application. The SpringBoot app is tested with a variety of tests including a suite of WebDriver 'journey' tests. We run a subset of these journey tests as 'smoke' tests on different environments.
To make this as simple as possible we want to create an executable FatJar (or similar) consisting of a Main class, the smoke tests and testing dependencies. This artifact should be created in addition to the main application jar and can then be run against an arbitrary environment from the command line.
What's the best way of achieving this? Sub-projects don't seem to fit because we want to package the 'test' output from a single project. The spring-boot gradle plugin seems to be (rightly) geared to producing a single application artifact, is there a way to MacGyver it to create another executable jar with the smoke tests? Is this just crazy talk?

Is there an example of AngularJS app generated by Yeoman with e2e tests and $httpBackend?

Is there somewhere an example of AngularJS app generated by yo angular generator that has e2e tests with $httpBackend from ngMockE2E module? Preferably with single and continuous versions for CI and development.
It looks like using $httpBackend requires one to create a new app that depends on the original app module and ngMockE2E module and requires new index.html file that loads this new app.
If tests use a different app, does it mean that I should modify configuration to store files generated for tests somewhere else than files generated by grunt server command (.tmp), or will these files be exactly the same? I'd like to be able to have grunt server running for development while running e2e tests in the background with PhantomJS.
Has anyone created a task that automatically generates modified index-e2e.html file based on index.html? This way it would be always up to date and it could also be used with watch to automatically regenerate it whenever original index.html file changes.
You should notice that angular is depreacting e2e in favor of the protractor framework.. Also notice that e2e (and protractor also) is quite slow. so running continuously in the background like we do with unittesting isn't recommended. That said, for your question - No you don't need a different app, index file etc. (unless you need coverage data from e2e, in that case you'll need to instrument the js files, and that would require a different index.html, that can be created in grunt task with sed). what you do need is a different karma.conf.js file, a different grunt karma task ro reference it, including ng-scenario in the files section of the karma.conf. and running some kind of grunt testServer task that would run a test server, which isn't the same as the dev grunt server. You can run both with foreman or something similiar (as explained in this SO [question]. (How can I automate both E2E and unit tests with Yeoman & AngularJS?) and answer). If this is what you are looking for - you can find a karma.conf.js example for both e2e an unit in this PR. and again, don't invest heavily into the current e2e framework. better working the the new and shiny protractor

Runnig JSUnit tests without a test suite

Is there a way to run JSUnit tests without specifying test suite file.
I want to run all the tests in a particular package so that one does not have to remember to add any new test to the existing suite.
I believe both Eclipse and Maven will do this for you.

Resources