Skip to content

Commit df1011f

Browse files
committed
Cleanup test/test.js and use package configs for AMD setup in test/index.html.
1 parent fba9220 commit df1011f

File tree

2 files changed

+57
-25
lines changed

2 files changed

+57
-25
lines changed

test/index.html

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,40 @@
1919
);
2020
</script>
2121
<script>
22-
var platform2;
22+
var platformModule;
2323

24-
if (window.require) {
24+
(function() {
25+
if (!window.require) {
26+
return;
27+
}
2528
QUnit.config.autostart = false;
2629

27-
// load Platform.js as a module
28-
require({
29-
'baseUrl': '../vendor/requirejs/',
30+
requirejs.config({
31+
'baseUrl': './',
3032
'urlArgs': 't=' + (+new Date),
31-
'paths': {
32-
'platform': '../../platform'
33-
}
34-
},
35-
['platform'], function(platform) {
36-
platform2 = platform;
37-
require(['test.js'], function() {
33+
'waitSeconds': 0,
34+
'packages': [
35+
{
36+
'name': 'platform',
37+
'location': '..',
38+
'main': 'platform'
39+
},
40+
{
41+
'name': 'test',
42+
'location': '.',
43+
'main': 'test'
44+
}
45+
]
46+
});
47+
48+
// load platform as a module
49+
require(['platform'], function(platform) {
50+
platformModule = platform;
51+
require(['test'], function() {
3852
QUnit.start();
3953
});
4054
});
41-
}
55+
}());
4256

4357
// set a more readable browser name
4458
window.onload = function() {

test/test.js

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,49 @@
1-
;(function(root) {
2-
'use strict';
1+
;(function() {
2+
3+
/** Used as a safe reference for `undefined` in pre ES5 environments */
4+
var undefined;
5+
6+
/** Used as a reference to the global object */
7+
var root = typeof global == 'object' && global || this;
8+
9+
/** Method and object shortcuts */
10+
var phantom = root.phantom,
11+
amd = root.define && define.amd,
12+
document = !phantom && root.document,
13+
hasOwnProperty = Object.prototype.hasOwnProperty,
14+
noop = function() {};
15+
16+
/** Detect if running in Java */
17+
var isJava = !document && !!root.java;
318

419
/** Use a single "load" function */
5-
var load = typeof require == 'function' ? require : root.load;
20+
var load = (typeof require == 'function' && !amd)
21+
? require
22+
: (isJava && root.load) || noop;
623

724
/** The unit testing framework */
825
var QUnit = (function() {
9-
var noop = Function.prototype;
1026
return root.QUnit || (
1127
root.addEventListener || (root.addEventListener = noop),
1228
root.setTimeout || (root.setTimeout = noop),
1329
root.QUnit = load('../vendor/qunit/qunit/qunit.js') || root.QUnit,
14-
(load('../vendor/qunit-extras/qunit-extras.js') || { 'runInContext': noop }).runInContext(root),
1530
addEventListener === noop && delete root.addEventListener,
1631
root.QUnit
1732
);
1833
}());
1934

35+
/** Load and install QUnit Extras */
36+
var qa = load('../vendor/qunit-extras/qunit-extras.js');
37+
if (qa) {
38+
qa.runInContext(root);
39+
}
40+
2041
/** The `platform` object to check */
2142
var platform = root.platform || (root.platform =
2243
load('../platform.js') ||
2344
root.platform
2445
);
2546

26-
/** Shortcut used to check for own properties of objects */
27-
var hasOwnProperty = Object.prototype.hasOwnProperty;
28-
2947
/*--------------------------------------------------------------------------*/
3048

3149
/**
@@ -1890,8 +1908,8 @@
18901908
});
18911909

18921910
test('supports loading Platform.js as a module', function() {
1893-
if (root.define && define.amd) {
1894-
equal((platform2 || {}).description, platform.description);
1911+
if (amd) {
1912+
equal((platformModule || {}).description, platform.description);
18951913
} else {
18961914
ok(true, 'test skipped');
18971915
}
@@ -2022,8 +2040,8 @@
20222040

20232041
/*--------------------------------------------------------------------------*/
20242042

2025-
if (!root.document || root.phantom) {
2043+
if (!document) {
20262044
QUnit.config.noglobals = true;
20272045
QUnit.start();
20282046
}
2029-
}(typeof global == 'object' && global || this));
2047+
}.call(this));

0 commit comments

Comments
 (0)