Login Register

Please, don't use _testCommon.js!

This is important, so please read on ...

A long time ago, I proposed a patch to Dojo, adding in a little gem of JavaScript to each and every test case in Dijit: _testCommon.js ... it was magic. It loaded whichever theme we chose safely, and set a class name on the body tag, just as dijit themeing requires. It also allowed us to test pseudo-a11y mode, and genuine right-to-left mode for each of the widgets at our whim. This kind of testing is important to Dijit, and as seen by the "matrix", is extensive. We have to test at a _minimum_ each of the "tundra" tests in all of dijit's supported browsers: Internet Explorer 6 + 7, FireFox 2 (and FF3 coming), Safari 3 (ideally both MacOS and Windows variants, as they differ some), as well as fun testing on "technically unsupported" browsers like the WebKit in the iPhone, Opera 9 (which Dijit mostly works with, just not guaranteed) ... It's a huge matrix. _testCommon.js helped with that some, but did something entirely anti-Dojo: magic.

This is my plea: grep your html. If you are inadvertently loading in _testCommon.js via a script tag, remove it. It is 2k of JavaScript entirely unnecessary in any production environment, or any website whatsoever. We use it as a test mechanism, though it introduces magic that causes a lot of confusion, especially among new
users of Dojo. So go. grep your html. If you have a reference to _testCommon.js, remove it. I'll wait.

If something broke, you've come back. Taking the "magic" away from our test-matrix exposes the downside of me having introduced testCommon in the first place. Again with the "there is no Dojo magic here", _testCommon.js breaks two (or more) fundamental Dijit paradigms:

you need a class="themeName" somewhere!

The default Dijit theme is called "tundra" ... It is done entirely based on CSS, and uses a selector ".tundra" to prefix all the class definitions. _testCommon.js was adding the appropriate class name to the body tag, the most top level node available. You can technically utilize CSS inheritance / cascading, and simply put a class="themeName" around your widget dom, but some things that are direct descendant of body (Dialog, Tooltip, Popups) need the class on the body.

the safest way:

<body class="tundra"><!-- my page --></body>

you need to load the theme.css!

each theme available has a folder in dijit/themes/ based on the theme name. To load the "tundra" theme, you need the file dijit/themes/tundra/tundra.css ... There is an opportunity for optimization there, but currently the only supported theme mechanism is to pull in the theme "rollup" of all the available components. _testCommon.js was using document.write (of all things) to include the link tags necessary to load the theme files. This is "magic", and also left our test cases without any useful CSS being loaded. This "magic" also probably introduced a race condition in several widgets who relied on the CSS being loaded in order to size properly. It is our recommendation you load theme theme css file before loading dojo.js to limit risk of hitting this race condition.

the recommended way:

<head>
        <link rel="stylesheet" href="js/dijit/themes/tundra/tundra.css" />
        <script src="js/dojo/dojo.js" type="text/javascript"></script>
</head>
<body class="tundra"><!-- your markup --></body>

People use our tests to learn, to copy, to start. Most of our tests are copies of previous tests, modified for some new widget. Having this "magic" _testCommon.js in each and every page propagated throughout all of dijit, some of dojox, and into user pages (I'm no exception to this copy/pasting) ... The Above "skeleton" page is all that is needed to use Dijit. Add another script tag for all your dojo.requires(), and flood the body with markup -- you are on your way.

All this said, _testCommon.js is _still_ in every test file! Ignore it, don't use it, remove it from your pages still ... We still use it to test Nihilo and Soria themes, as well as do the automated magic to set Right-to-Left mode and pseudo-a11y mode. It is still very important for us to test all these modes, and we like having the helper. Though now _testCommon.js does nothing magic until you force it, and the default theme and configuration is reflected throughout all the dijit and dojox tests.

I hope this clarifies some stuff for everyone.