git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Testing JavaScript code in gitweb.

From
jaseem abid <jaseemabid@gmail.com>
Date
May 19, 2012, 21:44 UTC
Message-ID
<CAH-tXsDif9YOrkEcj7AdRfn6gvLx4mj4+SKCB4GzyW6QJpx=9A@mail.gmail.com>
Hi,

Over the last few days, I explored ways to test the JavaScript code in gitweb, and this is what I came up with.

Tests can be split into 2 major categories.
- Tests in the console.
	Pros
		- Can stick to the existing TAP, t/95xx testing pattern.
		- Easier integration with the existing test system.
	Cons
		- Will need a run time environment for JavaScript. Major ones are
node.js[1], spidermonkey and Rhino. All add *huge* dependencies to
git.
		- [IMP] The code is ultimately going to be run in a browser. Its
best to test in the same environment.
			From [2]:
				> JS test suites generally run in the browser because knowing that
your  tests pass in some sane command-line compiler tells you nothing
about  how it will be mangled by IE (or in rare cases, other
browsers).
- Tests in the browser.
	Pros
		- Test in the same environment where the code is going to be run.
Andrew mentioned this [2]
		- Ideal way to test in all those browsers out there across platforms
and versions effectively.  Can host the test page publicly with
gitweb, so that people can test it quickly in their won browsers and
report bugs.
		- No new dependencies.
		- Great libraries available.
	Cons
		- Wont go with the existing system.
			There are no tests for JavaScript now[3] . This would definitely
make it only better.  The perl code can be tested in the existing
manner and the JavaScript code can run in browser with no issues.
			Jakub mentioned this wont be a problem [4]
			
- Here are a few frameworks I considered for the task.
- Jasmine.
	BDD style testing. Current priority #1.
	Runs in the browser. Benefits mentioned above.
	Powerful and feature rich. A good tool for the task.
- node-tap [5]
	Needs node.js as previously mentioned.  This is the one that is
officially recommenced[6].
- JSdev
- TestSwarm
- JSTestDriver
- sinon.js
	Rejected by Jakub as not suitable after discussions[4].
-Qunit
	Priority #2. Runs in the browser.

I would prefer BDD style Jasmine for testing. The argument against it was that It cant be run from terminal (node.js). That will add a new dependency and hence cant be done. And as Andrew mentioned earlier, I think its better to run JavaScript tests in a real browser itself, because that's where it ultimately needs to run. He also mentioned that TDD would be a nice way to go [7]. I guess BDD will be ok in the context. Jakub almost agreed with browsers after the previous discussion thread[8].

I would love to hear from all about testing JavaScript code in the browser with Jasmine.

More on testing frameworks[9]

1 : http://nodejs.org 2 : http://git.661346.n2.nabble.com/GSOC-Contributing-to-git-tp7420040p7423349.html 3 : http://git.661346.n2.nabble.com/GSOC-Contributing-to-git-tp7420040p7420271.html 4 : http://git.661346.n2.nabble.com/GSOC-Contributing-to-git-tp7420040p7423442.html 5 : https://github.com/twada/qunit-tap 6 : http://testanything.org/wiki/index.php/TAP_Consumers 7 : http://colabti.org/irclogger/irclogger_log/git-devel?date=2012-05-13#l57 8 : http://git.661346.n2.nabble.com/GSOC-Contributing-to-git-tp7420040p7432237.html 9 : http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks#JavaScript

-- 
Jaseem Abid
http://jaseemabid.github.com
Next: Andrew Sayers
Message 1 of 4 in “Testing JavaScript code in gitweb.”
  1. jaseem abidMay 19, 2012
  2. Andrew SayersMay 20, 2012
  3. chaitanya nallaMay 20, 2012
  4. KevinMay 22, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.