I have some JavaScript unit tests that I need to run. We use a combination of mocha and chai for the tests. We are looking into possibly switching to Capacitor as a tool to convert web apps to mobile and electron projects. In order to get Capacitor working in our unit tests we have to run the tests using jsdom as Capacitor makes use of the window object. Now the unit tests are run through jsdom these parts of Capacitor are happy and our tests pass.
However we have one module that will require the use of Capacitor's Filesystem API. Filesystem has no web implementation so these tests now fail as we are using jsdom. The log states Filesystem does not have web implementation.. Is there any way I can get a combination of having window available in our unit tests while also allowing the use of Filesystem?
I was able to fix this. I used jsdom from the terminal and it didn't work. However using the JavaScript API I was able to get that test to pass.
Related
I want Jenkins to run JavaScript unit tests.
Although I came across different JavaScript unit test frameworks, like Jasmine or Tape, I cannot find any documentation on how to make them work and set-up their output to co-operate with Jenkins.
Can anyone point me to a documentation for Jasmine, Tape and other unit test frameworks, explaining on how to configure them properly to be triggered and evaluated by Jenkins?
There is nothing special to do with regards to Jenkins. You need to install the testing libraries as you normally would on the Jenkins executor nodes, and then you can use them as you normally use them from within your Jenkins job. Note that this may mean calling npm install from within your Jenkins job - this is pretty typical; you would do something similar whether you were using Python virtualenv, Ruby bundler, etc.
Until now, I've done all my testing with just Jasmine and jQuery to automate the browser. I am starting to explore Karma but it seems to be set up only for unit tests that involve loading HTML fragments as test fixtures and I find no way to load a whole web page. Am I missing something or is this simply the wrong tool for what I am trying to do?
From the karma FAQ's section:
Can I use Karma to do end to end testing?
Karma has primarily been designed for low level (unit) testing. If it's an AngularJS app, you can use Karma with the karma-ng-scenario plugin. However, we recommend Protractor for high-level testing.
Typically, loading a whole web page goes beyond the scope of single units of code: you need to spin up a browser, load the page and make your actions and assertions. End-to-end testing frameworks like Protractor, Nightwatch.js or Webdriver.io might be more suitable for this specific case.
You can do integration testing using the following toolchain:
Karma ➔ Mocha ➔ Mocha-CasperJS ➔ CasperJS.
Check out the mocha-casperjs package.
I'm building my app using backbone and react inside of a rails app. I saw that all the recommended test packages (jest, jasmine, etc) are all node based. From what I know, I can get node on my rails project but I'd prefer not to.
Is there a way to test with something like jest without node? Or is there another package that isn't based on node that works with react.
Many test frameworks have browser based test runners, if you're willing to give up command line based testing then you can do this. Jasmine and Mocha both allow this.
Node.js is the de facto platform for web development tools (Ruby being the second most popular). Consider adopting the dependency, or you'll be fighting an uphill battle.
I have got javascript tests running in visual studio using Resharper and Jasmine. It all works fine. Now however I want to run an integration test. After looking into this I just can't work out whether I should be using Karma or PhantomJs or both? And whether they link to resharper?
I then have to run all my tests on the continuous integration server using Team City. Doesn't seem like there is a clear logical way to architect front end testing from dev right through to the CI server.
For example do I really need to use Karma locally and on the CI server? I don't want to because it is not baked into visual studio and I will have to keep opening the command line and running my tests manually. This will annoy other developers and they won't bother running them I imagine. Help!
We are using Team City by the way....
Neither of these test runners are connected to Resharper in any form. I don't think there is a one and only "correct" way of running Jasmine tests in TeamCity currently - for all approaches I am aware of there is a bit of assembly required.
Personally I am using a combination of PhantomJS and the Jasmine TeamCity Reporter which works like this:
Get a list of unique test URLs from server - each of these test suites will use the Jasmine TeamCity Reporter to log results
for each test URL dynamically generate a test JS file to be used for phantom and write it to disk
use PhantomJS to run the JS file which now will load the test suite page and its test result will be written to console where they are picked up by TeamCity.
I've been writing JavaScript unit tests using Jasmine. However, those tests run inside a browser, not as part of MSTest.
I want my TFS Continuous Integration builds to break when a JavaScript unit test fails. I know there is a solution for this in Visual Studio 2012, but I'm on 2010 (and will be for a long time in the future probably).
Is there an easy way to integrate Jasmine based JavaScript unit tests with TFS Build?
The Chutzpah test runner enables you to run your QUnit and Jasmine JavaScript unit tests from the command line or Visual Studio.
Therefore you should be able to integrate it into your TFS build via the InvokeProcess activity.
I'd use nodejs + jasmine-node, but you can also look at http://phantomjs.org/ with a junit reporter. Jasmine-node provides a junit reporter with the --junitreport output. You might also look at the TFS Build Extensions (http://visualstudiogallery.msdn.microsoft.com/2d7c8577-54b8-47ce-82a5-8649f579dcb6/view/Discussions/) and the activities in there. It includes a xml transform for JUnit to TRX (test results xml) which can be pushed into TFS.