Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
benchmark: Ensure same number of unit tests execute on the client and…
Browse files Browse the repository at this point in the history
… server side. [jddalton]
  • Loading branch information
jdalton committed Nov 13, 2011
1 parent 594a4f4 commit b4427c6
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 30 deletions.
27 changes: 18 additions & 9 deletions tests/index.html
Expand Up @@ -30,13 +30,21 @@
}());
</script>
<script src="../vendor/qunit/qunit/qunit.js"></script>
<script>var Benchmark2;</script>
<script>var Benchmark2, platform;</script>
<script src="../benchmark.js"></script>
<script src="../vendor/requirejs/require.js"></script>
</head>
<body>
<h1 id="qunit-header">Benchmark.js Test Suite</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<script>
if (/[?&]norequire=true(?:&|$)/.test(location.search)) {
require = define = null;
document.write('<script src="tests.js"><\/script>');
document.write('<script src="../vendor/platform.js/platform.js"><\/script>');
}
else {
require({
Expand All @@ -47,16 +55,17 @@
['src/benchmark'], function(Benchmark) {
Benchmark2 = Benchmark;
require(['tests.js']);
document.getElementById('qunit-userAgent').innerHTML = Benchmark2.platform;
});
}
if (!/[?&]nojava=true(?:&|$)/.test(location.search)) {
document.write('<applet code="nano" archive="../nano.jar"></applet>');
}
window.onload = function() {
setTimeout(function() {
document.getElementById('qunit-userAgent').innerHTML = platform || Benchmark.platform;
}, 15);
};
</script>
</head>
<body>
<h1 id="qunit-header">Benchmark.js Test Suite</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<applet code="nano" archive="../nano.jar"></applet>
</body>
</html>
52 changes: 31 additions & 21 deletions tests/tests.js
Expand Up @@ -17,28 +17,35 @@

/*--------------------------------------------------------------------------*/

// in-browser tests
if (window.document) {
// must explicitly use `QUnit.module` instead of `module()`
// in case we are in a CLI environment
QUnit.module('Benchmark');
// must explicitly use `QUnit.module` instead of `module()`
// in case we are in a CLI environment
QUnit.module('Benchmark');

test('Benchmark.platform', function() {
test('Benchmark.platform', function() {
if (window.document) {
equal(navigator.userAgent, String(Benchmark.platform), 'default value');
});
} else {
ok(true, 'test skipped');
}
});

if (window.require) {
test('require("benchmark")', function() {
equal((Benchmark2 || {}).version, Benchmark2.version, 'require("benchmark")');
});
test('require("benchmark")', function() {
if (window.document && window.require) {
equal((Benchmark2 || {}).version, Benchmark2.version, 'require("benchmark")');
} else {
ok(true, 'test skipped');
}
});

test('require("platform")', function() {
var bench = Benchmark2 || {},
platform = bench.platform || {};
equal(typeof platform.name, 'string', 'auto required');
});
test('require("platform")', function() {
if (window.document && window.require) {
var bench = Benchmark2 || {},
platform = bench.platform || {};
equal(typeof platform.name, 'string', 'auto required');
} else {
ok(true, 'test skipped');
}
}
});

/*--------------------------------------------------------------------------*/

Expand Down Expand Up @@ -160,8 +167,8 @@
deepEqual(values, ['a', 'c'], 'sparse check');
});

if (window.document && document.evaluate) {
test('xpath snapshot', function() {
test('xpath snapshot', function() {
if (window.document && document.evaluate) {
var o = document.evaluate('//html', document, null, 7, null),
values = [];

Expand All @@ -170,8 +177,11 @@
});

deepEqual(values, [document.documentElement], 'basic');
});
}
}
else {
ok(true, 'test skipped');
}
});

/*--------------------------------------------------------------------------*/

Expand Down

0 comments on commit b4427c6

Please sign in to comment.