If the code is HTML-related, it should take selectors or objects as input and concern itself solely with those. This makes for much easier testing and reuse. And of course: Write the tests first.
When the module is done you write a controller for the page that plugs the needed plugins to the page elements. This should fail gracefully if the needed elements are not present.
We highly suggest you create
python/nav/web/static/js/require_config.dev.js and enable
Django debug in
etc/nav.conf when developing.
Make sure to put this in your RequireJS configuration file:
require.urlArgs = "bust=" + (new Date()).getTime();
This makes sure you’re not using cached resources in your browser when developing, something many browsers love to do! See the RequireJS documentation on using urlArgs for details.
python/nav/web/static/js/require_config.dev.js is in the global Git ignore
python/nav/web/static/js/test/* for examples on how to write tests using Karma with
python/nav/web/static/js/ under NAV’s SCM root.
python/nav/web/static/js/) there should normally
only be global configuration files for RequireJS, jshint, etc.
python/nav/web/static/js |-- extras/ |-- geomap/ |-- libs/ |-- resources/ |-- src/ `-- test/
python/nav/web/static/js/require_config.*.jsif it is not an AMD library.
contains resources that should be available under the Karma testing environment.
python/nav/web/static/js/resources/libs/text.jsis such a module which is required to be available in such an environment to run tests with templates that get loaded using the AMD pattern.
contains the source code to NAV modules which use RequireJS for dependency handling.
is the Netmap Backbone application.