How to run jQuery self tests
This is addition to official Running the Unit Tests topic.
Say you have rewritten half of jquery (for good reasons) and want to test it. jquery uses its own QUnit tool.
Build stable jquery
For demonstration of QUnit let's clone stable branch of jquery
$ git clone -b 1.11-stable https://github.com/jquery/jquery.git
$ cd jquery
Build it
$ npm install
$ grunt
$ ll dist
PHP server
Althrough we already installed node
for builds, we need PHP server for tests. PHP? to test javascript library? Strange.
Anyway, you just configure HTTP server to serve root directory of jquery (not test
directory) and QUnit should be available at http://localhost/test
.
Lightweight servers
First I tried simple CGI server uwsgi
but seems it doesn't work well with QUnit. Then I tried lighttpd
but some tests were still failed.
I configured lighttpd
this way
- Installed lighttpd and php. On Debian it is
lighttpd
andphp5-cgi
packages. Enabled fastcgi-php
# lighttpd-enable-mod fastcgi fastcgi-php
Added directory with local copy of jQuery repo to lighttpd. Simple and dirty way was to change
server.document-root
.- Changed
server.port
from 80 to 8081. Restarted lighttpd.
# service lighttpd restart
Test page became available at http://localhost:8081/test/index.html
, but whole bunch of tests were failed.
Apache
Apache works good with QUnit:
Tests completed in 64047 milliseconds.
6089 assertions of 6092 passed, 3 failed.
One test is related to stylesheets was failed, as far as i understood one stylesheet was introduced by Chrome, not by document and this confused the test.
Two tests are related to focus/blur. May be it's time to update my Chromium?]
I tested in FF also:
Tests completed in 54904 milliseconds.
6086 assertions of 6086 passed, 0 failed.
Faster and no tests failed.
Midori:
Tests completed in 93135 milliseconds.
6060 assertions of 6060 passed, 0 failed.
Interesintg]
Cheers.
shitpoet@gmail.com