Skip to content

Running Javascript Tests

jodosha edited this page Sep 14, 2010 · 5 revisions

How to use
====
From the adva_cms root:

rake test:js rake test:js PLUGINS=adva_calendar,adva_assets rake test:js BROWSERS=safari,firefox

How to setup
==
Each plugin should have the following structure:

adva_calendar/

  1. public/
    javascripts/
    admin/
    calendar.js
    calendar.js

  2. test/

  3. javascript/
    fixtures/
    admin/
    calendar_fixtures.html
    calendar_fixtures.html
    functional/
    admin/
    calendar_test.js
    calendar_test.js
    unit/
    admin/
    calendar_test.js
    calendar_test.js

As you can see you have to reflect the public/javascripts structure under unit or functional.
NOTICE: functional tests aren’t related to Webrat integration tests.

Behind the scenes
======
What really happen when we start the Rake task?

  1. The system detect the plugins to test and the browsers, accoding to the PLUGINS and BROWSERS env vars.
  2. For each plugin:
    1. Temp dirs are created:
      1. adva_calendar/javascript/tmp
      2. adva_calendar/javascript/tmp/unit
      3. adva_calendar/javascript/tmp/functional
    2. Each test case will be compiled with a template, merged with relative html fixtures and copied under the proper temp path:
      adva_calendar/javascript/unit/calendar_test.js => adva_calendar/javascript/tmp/unit/calendar_test.html
    3. public, assets and tmp folders are mounted on the test webserver
      1. adva_calendar/public => /adva_calendar
      2. adva_calendar/test/javascript/assets => /adva_calendar/assets
      3. adva_calendar/test/javascript/tmp => /adva_calendar/test
    4. Each file which match <plugin_root>/test/javascript/assets/**/*_controller.rb is mounted as controller
      1. adva_calendar/test/javascript/assets/upload_controller.rb => /adva_calendar/controllers/upload
  3. The adva_cms/test/javascript/assets is mounted as / (root path) on the test webserver
  4. For each browser selected tests will be run
  5. Clean up of all the tmp folders