Javascript Testing

103 views
Skip to first unread message

Sean Bleier

unread,
Jun 17, 2011, 2:24:21 PM6/17/11
to django-d...@googlegroups.com
Hello everyone,

A couple months ago I started work on a django branch [1] (with the help of @jezdez) that introduces a framework for writing javascript unit tests using QUnit[2].  I started with QUnit because Django already included jQuery in the admin and seemed like a natural extension, but it would be nice to hear opinions from people that know more about javascript testing than I.

Since I haven't touch it in a couple months, I thought I would share it with django-developers to get some more eyes on it and discuss any missing features or implementation details. It also be nice if Idan or any other designery person could look it over and give some UI/UX advice.

Just to give a overview, the javascript testing framework is initiated by first collecting static media and then starting a special runserver:

    ./manage.py collectstatic
    ./manage.py jstest

This starts a runserver that collects and serves everything you need to run the javascript tests found within an installed app. More detail can be found in these preliminary docs[3], though they need to be moved into their proper place within the docs directory.

I'm hoping we can figure out a way forward so that we can start writing tests for the admin and elsewhere.

Cheers,

--Sean


Luke Plant

unread,
Jun 18, 2011, 9:34:59 AM6/18/11
to django-d...@googlegroups.com
Hi Sean,

> A couple months ago I started work on a django branch [1] (with the help
> of @jezdez) that introduces a framework for writing javascript unit
> tests using QUnit[2]. I started with QUnit because Django already
> included jQuery in the admin and seemed like a natural extension, but it
> would be nice to hear opinions from people that know more about
> javascript testing than I.
>
> Since I haven't touch it in a couple months, I thought I would share it
> with django-developers to get some more eyes on it and discuss any
> missing features or implementation details. It also be nice if Idan or
> any other designery person could look it over and give some UI/UX advice.
>
> Just to give a overview, the javascript testing framework is initiated
> by first collecting static media and then starting a special runserver:
>
> ./manage.py collectstatic
> ./manage.py jstest
>
> This starts a runserver that collects and serves everything you need to
> run the javascript tests found within an installed app. More detail can
> be found in these preliminary docs[3], though they need to be moved into
> their proper place within the docs directory.
>
> I'm hoping we can figure out a way forward so that we can start writing
> tests for the admin and elsewhere.

This looks like it could be really interesting or useful, but at the
moment I can't quite see my way to working out how to use it. I'd really
like to be able to:

1) apply a patch (or two) to my copy of Django
2) run an example test that proves something useful about the admin's
javascript (for instance - or some other example app that is provided).

Remember, most of us (certainly me) probably don't know the first thing
about QUnit, and don't know if it is going to be useful for testing.

Regards,

Luke

--
LORENZ'S LAW OF MECHANICAL REPAIR:
After your hands become coated with grease, your nose will begin to
itch.

Luke Plant || http://lukeplant.me.uk/

Julien Phalip

unread,
Jun 18, 2011, 8:15:47 PM6/18/11
to Django developers
Hi Sean,
> [3]https://github.com/sebleier/django/blob/qunit/django/test/javascript/...

Thanks a lot for working on this. Django is in dire need of a solid
javascript test framework.

I've actually been looking at this branch a few weeks ago and it's
looking very promising! I had a few remarks and questions.

Do you have any specific plans for testing the admin *interface*? My
main concern is that to properly test complex interactions (e.g.
dynamically adding or removing admin inlines), you would need to have
a DOM based on the up-to-date admin templates and on some test data.
Is it envisaged to plug the QUnit test platform in with a running
instance of Django that would supply admin pages on the fly, or
perhaps to introduce a management command that would generate HTML
files using the up-to-date admin codebase?

Also, one curse of javascript is that it doesn't always behave quite
the same on all browsers. It would be absolutely awesome if the
process of testing on multiple platforms and browsers could be
automated in a CI environment. The Mozilla guys have done some work in
that area: https://github.com/kumar303/jstestnet -- I haven't tried it
myself yet. Do you think this could be looked into for Django itself?

Then, as currently in your branch, QUnit tests are expected to be put
in a "tests/javascript/" folder. Does it mean that the same folder
structure can be used to run other types of JS test runners? If not,
would it be best to use a more explicit structure and require that
tests be put in, for example, "tests/qunit/", in order to leave the
room for other JS test runners to be supported in the future?

Finally, a ticket has recently been created in Trac for this:
https://code.djangoproject.com/ticket/16193 -- 'mbraak' posted a patch
with a few simple tests for the admin JS. It'd be great to see how
both your works integrate.

Thanks again, this is awesome!

Julien

Justin Holmes

unread,
Jun 18, 2011, 9:17:10 PM6/18/11
to django-d...@googlegroups.com
A javascript testing framework is most desirable. Thanks for your
work so far - what can we do?

> --
> You received this message because you are subscribed to the Google Groups "Django developers" group.
> To post to this group, send email to django-d...@googlegroups.com.
> To unsubscribe from this group, send email to django-develop...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.
>
>

--
Justin Holmes

Head Instructor, SlashRoot Collective
SlashRoot: Coffee House and Tech Dojo
60 Main Street
New Paltz, NY 12561
845.633.8330

Sean Bleier

unread,
Jun 20, 2011, 2:31:33 PM6/20/11
to django-d...@googlegroups.com
Hi Luke,

This looks like it could be really interesting or useful, but at the
moment I can't quite see my way to working out how to use it. I'd really
like to be able to:

1) apply a patch (or two) to my copy of Django

Would you like me to attach a patch to a ticket? I could attach it to https://code.djangoproject.com/ticket/16193 or open a new ticket using a more generic description of a javascript testing framework.
 
2) run an example test that proves something useful about the admin's
javascript (for instance - or some other example app that is provided).


I recently added tests for URLify.js from the admin, that may give you a better practical sense of how to test the admin. https://github.com/sebleier/django/commit/3a358cc3a4c2fa9a1fda0d58c46309c9f7956d6a


Thanks,

--Sean
Reply all
Reply to author
Forward
0 new messages