Test Driven JavaScript Development with Django vs Node.js - javascript

I have a web project coded 80% in JavaScript and 20% in Django without a single unit testing as I rushed for Minimum Marketing Features. Now that the project is getting funded, I decided to invest some time to introduce TDD. I had a great deal of inspiration from this KickStarter-funded tutorial.
http://www.letscodejavascript.com/
The author uses Node.js, Jake, Lint, Nodeunit, and Karma to simplify the whole integration process. The server/client tests in all major browsers is done in a single command and I was really hooked to this idea, but it requires switching to Node.js.
I've searched for TDD in Django and ran into this tutorial that makes use of Selenium.
http://www.tdd-django-tutorial.com/
However this TDD was primarily based on unit testing in server. Here are the questions.
Can multiple client JavaScript testing be done in Django/Python?
I assume the answer is no since js files are nothing more than static library in Django. Correct me if I'm wrong.
Is it worth using Node.js just for the sake of TDD Javascript?
My logic was either you use Python or Node.js for the server, but since tools like Karma and Buster.js requires Node.js, I was wondering whether setting up the Node.js alongside Django just for multiple client testing is plausible choice when considering lower cost of maintenance.
Thank you :D

You can take a look at using selenium in your django test suite. Django's official docs cover this in moderate detail
To answer your question about Node.js - I would say that it's probably not worth the complexity to add node.js SOLELY for the purpose of running unit tests. Also, since your javascript is likely built to run in a browser, it's less likely that things will break down if you use a tool like selenium (which runs the code in an actual browser, providing a python scripting interface).

Related

Local unit testing on app engine with Node.js

We're starting a new app on Google App Engine with node.js. We also decided to go with Cloud Datastore.
I've found that in the other available languages you can do local unit testing:
https://cloud.google.com/appengine/docs/java/tools/localunittesting
I haven't found anything available for node.js. Do you know if there's something like the above link? If there's not, we're probably going to change to Java or Go.
Thanks!
EDIT: I've just found this
https://cloud.google.com/datastore/docs/tools/datastore-emulator
Has anyone tried and knows if this could solve my problems?
The difference between what you're looking at is about App Engine Standard vs App Engine Flexible (formerly known as Managed VMs). NodeJS is only supported on App Engine Flexible.
App Engine Standard has some advantages (faster deployer times, ability to "scale to zero" so you pay nothing for idle apps), but it's much less flexible in that many libraries are not available in the runtimes and so you rely more heavily on App Engine APIs. To provide a way to test it locally, the local development server was provided.
Standard supports Python, Java, Go, and PHP. However, even with those languages, you still might choose Flexible if you want to do something like use Java 8, Python 3, or custom libraries like imagemagick.
App Engine Flexible is a pretty different product, although on the surface it looks similar since it has similar tooling and configuration, and they are both scalable platform-as-a-service products. But the concept is that you bring whatever environment you're familiar with it, and it runs it in a container (which is hidden from you. unless you use Custom runtimes to builds your own Docker runtime for it).
Since you're bringing your standard development environment to App Engine, the idea is you test your Node app the same way you would test any other Node app, and run it like you would run other local Node projects locally. There's not supposed to be too much special about the App Engine flexible environment, by design, so there's no need for a special local testing server.
However, if you're using Cloud Datastore, emulators are provided so you can run tests more quickly and without paying any money. So the emulator is definitely what you're looking for to do local unit tests. If you have any problems or issues with it, you should followup with more questions on Stack Overflow.
If you haven't seen already, there is a Getting Started with Node app that uses App Engine Flexible, and demonstrates a variety of tasks using Cloud Datastore, as well as MongoDB and CloudSQL (managed MySQL).
https://github.com/googlecloudplatform/nodejs-getting-started

jasmine-jquery vs selenium drivers (like Nightwatch.js) - when to choose each of those?

I would like to add integration tests to an (Backbone.js) application I am maintaining, and considering what strategy is preferable and upsides and downsides for each:
Running tests on the client side, with something like jasmine-jquery. Ideally I would like something like ember test helpers which allows writing simple synchronous looking code (while actually running async).
Running tests on the server side using selenium drivers, for example Nightwatch.js.
It is hard to tell which approach has more community and tooling around it, and which projects are more mature. Additionally, I am getting the feeling that running tests on the client side might allow better isolation of tests, while running on the server side, might create tests which run longer and heavier (also to maintain?) but allow to simulate more complex real-user scenarios
Any thoughts would be appreciated
If you care about browser compatibility, then you'll want to run end-to-end tests on different browsers on different platforms, possibly using a cloud-based cross-browser testing service such as SauceLabs, BrowserStack, TestingBot or CrossBrowserTesting.
Since you're using Backbone and are familiar with JavaScript, you might want to pick a JavaScript client for Selenium WebDriver. There are quite a few choices, with Intern leading the pack by far.

Continuous JavaScript Testing

Does anyone know of a good JavaScript testing tool which integrates automated testing with your Testing Framework of Choice. I am aware of TestSwarm (which is not automated testing) and Travis-CI (which isn't really available for closed-source projects).
Any other ones out there?
You can use Selenium:
Its test can either be generated by its IDE, or can be written in high level languages such as Java, PHP, etc.
Its can be instantiated from a Command-Line.
Its can be integrated with continuous-integration servers like Jenkins (In-build plugin).
The fact, that it can be instantiated from command-line (preferably written in java), makes it integrable by any CI Server
Two that I know of (although I'm not sure they are really meant for this purpose...) are Simple Test js and the MIT project Sikuli. Sikuli is great for making a cursor click on things and test out the user interactions. Neither one of these naturally will integrate well with your testing framework of choice but they will certainly allow you to write unit tests. Hopefully someone else will know of a better solution.

unit testing modular javascript

I am currently deriving a javascript framework pattern as an architecture for the client side development for an upcoming large scale application that I will developing.
I am looking to go with a module observer pattern in which each control I develop will have its own javascript file, holding no knoweldge of the other controls.
From designing this framework for my application, I am looking to integrate in a testing mechanism for my modules - a unit testing mechanism for javascript. I am not aware of any such frameworks or how I may set up such. Any suggestions?
As part of such testing, I will also need to mock up http requests.
The library I will be using in development is jquery.
The JQuery team has QUnit.
As for abstracting out AJAX, you should wrap it appropriately or just test the data manipulation methods.
Jasmine may be what you are looking for. It has built-in mock up support, and does not rely on any other frameworks.
They also have a separate module for faking AJAX responses.
The setup is simple. Just download the standalone version, write some testing suites, and view the SpecRunner.html in a browser.
Consider using JsTestDriver to run your JS tests. The main benefit it provides - it can run your tests on continuous integration environment, which is essential for unit testing practice.
Some additional features:
It can be used along with QUnit and other testing frameworks.
It can execute your tests in parallel across multiple browser.
It supports calculation code coverage.
List of mocking libraries you can find in another thread.
BoilerplateJS
is a reference architecture for large scale JavaScript product development. You can find the tests which are written using qunit, sinon and testr included under the tests folder.

Build automation and deployment for Javascript

i work at the digital department of a public broadcaster, together with two other frontend developers. We're currently looking into improving our Javascript workflow and build processes. Stuff like packaging, minifying, versioning, etcetera.
In an ideal scenario, we would have a global repository for all Javascript-related libraries (like jQuery) and stuff we build ourselves, that can be easily included in lots of projects and versioned.
All of our backend developers use Maven for this process with their Java code. I'm wondering if people have experience with Maven and Javascript, or maybe with other tools that might be good (or better) for the job. And in general if people have good resources about setting up workflow / build processes for frontend and javascript development.
We use Hudson (http://hudson-ci.org/) to continuously build/integrate our Python (Django via zc.buildout), R and several other types of projects. Whenever someone checks in code to the central VCS, a build is triggered and the test suite(s) will run. The build and test status is shown on a central screen in the office.
Hudson not only builds and tests, but also checks for coding style and syntax errors using pep8 and pyflakes, amongst others. Javascript is only checked with jslint at this point, but we may unit-test that in the future using something like xpcshell (more info).
** edit **
Go straight for Jawr, keeping rest in answer for alternatives
** edit **
First of all there's Ruby's rake which in theory can be used through jruby and in theory can be configured and run in the POM.
There's also Jake, but not sure if the latest Rhino supports CommonJS.
Whilst writing this awnser, I just came across Jawr which looks really interresting and there seems to be maven support/plugins.
The last option you already know about is dynamic loading using for example RequireJS or LABJS.

Categories

Resources