mourningdove/views/dev/tests.tt
2026-05-24 01:03:05 +00:00

75 lines
1.8 KiB
Text

[%# tests.tt
Run JS unit tests
Authors:
Afuna <coder.dw@afunamatata.com>
Copyright (c) 2015 by Dreamwidth Studios, LLC.
This program is free software; you may redistribute it and/or modify it under
the same terms as Perl itself. For a copy of the license, please reference
'perldoc perlartistic' or 'perldoc perlgpl'.
%]
[% testname = testname | html %]
[%- includes = includes.merge( [
"js/tests/qunit.js",
"stc/tests/qunit.css",
"js/tests/sinon.js",
"js/tests/sinon-qunit.js" ] ) -%]
[%- IF testlib == "jquery";
dw.need_res( { group => "jquery" }, includes );
CALL dw.active_resource_group( "jquery" );
ELSIF testlib == "old";
dw.need_res( includes );
ELSE;
dw.need_res( { group => "nolib" }, includes );
CALL dw.active_resource_group( "nolib" );
END
-%]
[%- sections.head = BLOCK %]
<!-- test definition -->
<script type="text/javascript">
var lib = "[% testlib %]";
if ( lib && ! location.search ) {
QUnit.config.filters = [ "*" ];
if ( lib ) {
QUnit.config.filters.push( lib );
}
}
[% IF testlib == "jquery" %]
$(document).ready(function(){
[%- tests -%]
});
[% ELSIF testlib == "old" %]
LiveJournal.register_hook("page_load", function(){
[%- tests -%]
});
[% ELSE %]
window.onload = function() {
[%- tests -%]
}
[% END %]
</script>
[% END %]
[%- IF tests -%]
<h1 id="qunit-header">[% testname %]</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<!-- for any html required by the test -->
<div id="qunit-fixture">
[% testhtml %]
</div>
[% ELSE %]
<h1 id="qunit-header">No tests for [% testname %]</h1>
<ol id="notests"></ol>
[%- END -%]