Skip to content

Commit b6593ca

Browse files
committed
Adding JsTestDriver
1 parent a1d253b commit b6593ca

5 files changed

Lines changed: 289 additions & 0 deletions

File tree

jsTestDriver.conf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
server: http://localhost:4224
2+
3+
load:
4+
- test/lib/qunit.js
5+
- test/lib/equiv.js
6+
- test/lib/QUnitAdapter.js
7+
- stacktrace.js
8+
- test/CapturedExceptions.js
9+
10+
test:
11+
- test/TestStacktrace.js
12+
13+
plugin:
14+
- name: "coverage"
15+
jar: "test/lib/plugins/coverage.jar"
16+
module: "com.google.jstestdriver.coverage.CoverageModule"
17+
args: useCoberturaFormat
18+
19+
timeout: 90

test/lib/JsTestDriver-1.3.3d.jar

4.09 MB
Binary file not shown.

test/lib/QUnitAdapter.js

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
QUnitAdapter
3+
Version: 1.1.0
4+
5+
Run qunit tests using JS Test Driver
6+
7+
This provides almost the same api as qunit.
8+
9+
Tests must run sychronously, which means no use of stop and start methods.
10+
You can use jsUnit Clock object to deal with timeouts and intervals:
11+
http://googletesting.blogspot.com/2007/03/javascript-simulating-time-in-jsunit.html
12+
13+
The qunit #main DOM element is not included. If you need to do any DOM manipulation
14+
you need to set it up and tear it down in each test.
15+
16+
*/
17+
(function() {
18+
19+
if(!(window.equiv)) {
20+
throw new Error("QUnitAdapter.js - Unable to find equiv function. Ensure you have added equiv.js to the load section of your jsTestDriver.conf");
21+
}
22+
23+
var QUnitTestCase;
24+
25+
window.module = function(name, lifecycle) {
26+
QUnitTestCase = TestCase(name);
27+
QUnitTestCase.prototype.lifecycle = lifecycle || {};
28+
};
29+
30+
window.test = function(name, expected, test) {
31+
QUnitTestCase.prototype['test ' + name] = function() {
32+
if(this.lifecycle.setup) {
33+
this.lifecycle.setup();
34+
}
35+
if(expected.constructor === Number) {
36+
expectAsserts(expected);
37+
} else {
38+
test = expected;
39+
}
40+
test.call(this.lifecycle);
41+
42+
if(this.lifecycle.teardown) {
43+
this.lifecycle.teardown();
44+
}
45+
};
46+
};
47+
48+
window.expect = function(count) {
49+
expectAsserts(count);
50+
};
51+
52+
window.ok = function(actual, msg) {
53+
assertTrue(msg ? msg : '', !!actual);
54+
};
55+
56+
window.equals = function(a, b, msg) {
57+
assertEquals(msg ? msg : '', b, a);
58+
};
59+
60+
window.start = window.stop = function() {
61+
fail('start and stop methods are not available when using JS Test Driver.\n' +
62+
'Use jsUnit Clock object to deal with timeouts and intervals:\n' +
63+
'http://googletesting.blogspot.com/2007/03/javascript-simulating-time-in-jsunit.html.');
64+
};
65+
66+
window.same = function(a, b, msg) {
67+
assertTrue(msg ? msg : '', window.equiv(b, a));
68+
};
69+
70+
window.reset = function() {
71+
fail('reset method is not available when using JS Test Driver');
72+
};
73+
74+
window.isLocal = function() {
75+
return false;
76+
};
77+
78+
window.QUnit = {
79+
equiv: window.equiv,
80+
ok: window.ok
81+
};
82+
83+
module('Default Module');
84+
85+
})();

test/lib/equiv.js

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
2+
// Tests for equality any JavaScript type and structure without unexpected results.
3+
// Discussions and reference: http://philrathe.com/articles/equiv
4+
// Test suites: http://philrathe.com/tests/equiv
5+
// Author: Philippe RathŽ <prathe@gmail.com>
6+
window.equiv = function () {
7+
8+
var innerEquiv; // the real equiv function
9+
var callers = []; // stack to decide between skip/abort functions
10+
11+
// Determine what is o.
12+
function hoozit(o) {
13+
if (typeof o === "string") {
14+
return "string";
15+
16+
} else if (typeof o === "boolean") {
17+
return "boolean";
18+
19+
} else if (typeof o === "number") {
20+
21+
if (isNaN(o)) {
22+
return "nan";
23+
} else {
24+
return "number";
25+
}
26+
27+
} else if (typeof o === "undefined") {
28+
return "undefined";
29+
30+
// consider: typeof null === object
31+
} else if (o === null) {
32+
return "null";
33+
34+
// consider: typeof [] === object
35+
} else if (o instanceof Array) {
36+
return "array";
37+
38+
// consider: typeof new Date() === object
39+
} else if (o instanceof Date) {
40+
return "date";
41+
42+
// consider: /./ instanceof Object;
43+
// /./ instanceof RegExp;
44+
// typeof /./ === "function"; // => false in IE and Opera,
45+
// true in FF and Safari
46+
} else if (o instanceof RegExp) {
47+
return "regexp";
48+
49+
} else if (typeof o === "object") {
50+
return "object";
51+
52+
} else if (o instanceof Function) {
53+
return "function";
54+
}
55+
}
56+
57+
// Call the o related callback with the given arguments.
58+
function bindCallbacks(o, callbacks, args) {
59+
var prop = hoozit(o);
60+
if (prop) {
61+
if (hoozit(callbacks[prop]) === "function") {
62+
return callbacks[prop].apply(callbacks, args);
63+
} else {
64+
return callbacks[prop]; // or undefined
65+
}
66+
}
67+
}
68+
69+
var callbacks = function () {
70+
71+
// for string, boolean, number and null
72+
function useStrictEquality(b, a) {
73+
return a === b;
74+
}
75+
76+
return {
77+
"string": useStrictEquality,
78+
"boolean": useStrictEquality,
79+
"number": useStrictEquality,
80+
"null": useStrictEquality,
81+
"undefined": useStrictEquality,
82+
83+
"nan": function (b) {
84+
return isNaN(b);
85+
},
86+
87+
"date": function (b, a) {
88+
return hoozit(b) === "date" && a.valueOf() === b.valueOf();
89+
},
90+
91+
"regexp": function (b, a) {
92+
return hoozit(b) === "regexp" &&
93+
a.source === b.source && // the regex itself
94+
a.global === b.global && // and its modifers (gmi) ...
95+
a.ignoreCase === b.ignoreCase &&
96+
a.multiline === b.multiline;
97+
},
98+
99+
// - skip when the property is a method of an instance (OOP)
100+
// - abort otherwise,
101+
// initial === would have catch identical references anyway
102+
"function": function () {
103+
var caller = callers[callers.length - 1];
104+
return caller !== Object &&
105+
typeof caller !== "undefined";
106+
},
107+
108+
"array": function (b, a) {
109+
var i;
110+
var len;
111+
112+
// b could be an object literal here
113+
if ( ! (hoozit(b) === "array")) {
114+
return false;
115+
}
116+
117+
len = a.length;
118+
if (len !== b.length) { // safe and faster
119+
return false;
120+
}
121+
for (i = 0; i < len; i++) {
122+
if( ! innerEquiv(a[i], b[i])) {
123+
return false;
124+
}
125+
}
126+
return true;
127+
},
128+
129+
"object": function (b, a) {
130+
var i;
131+
var eq = true; // unless we can proove it
132+
var aProperties = [], bProperties = []; // collection of strings
133+
134+
// comparing constructors is more strict than using instanceof
135+
if ( a.constructor !== b.constructor) {
136+
return false;
137+
}
138+
139+
// stack constructor before traversing properties
140+
callers.push(a.constructor);
141+
142+
for (i in a) { // be strict: don't ensures hasOwnProperty and go deep
143+
144+
aProperties.push(i); // collect a's properties
145+
146+
if ( ! innerEquiv(a[i], b[i])) {
147+
eq = false;
148+
}
149+
}
150+
151+
callers.pop(); // unstack, we are done
152+
153+
for (i in b) {
154+
bProperties.push(i); // collect b's properties
155+
}
156+
157+
// Ensures identical properties name
158+
return eq && innerEquiv(aProperties.sort(), bProperties.sort());
159+
}
160+
};
161+
}();
162+
163+
innerEquiv = function () { // can take multiple arguments
164+
var args = Array.prototype.slice.apply(arguments);
165+
if (args.length < 2) {
166+
return true; // end transition
167+
}
168+
169+
return (function (a, b) {
170+
if (a === b) {
171+
return true; // catch the most you can
172+
173+
} else if (typeof a !== typeof b || a === null || b === null || typeof a === "undefined" || typeof b === "undefined") {
174+
return false; // don't lose time with error prone cases
175+
176+
} else {
177+
return bindCallbacks(a, callbacks, [b, a]);
178+
}
179+
180+
// apply transition with (1..n) arguments
181+
})(args[0], args[1]) && arguments.callee.apply(this, args.splice(1, args.length -1));
182+
};
183+
184+
return innerEquiv;
185+
}(); // equiv

test/lib/plugins/coverage.jar

2.13 MB
Binary file not shown.

0 commit comments

Comments
 (0)