Skip to content

Commit 19ba06d

Browse files
committed
Add test suite for jQuery 3
1 parent 0677f1d commit 19ba06d

11 files changed

+476
-65
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 1.12.1-0 / Unreleased
22

3-
*
3+
* [FEATURE] Test with jQuery 3
44

55
# 1.12.0 / 2016-05-18
66

demo/index-1-12.html

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
<title>jquery.ui-contextmenu.js - Demo (jQuery UI 1.12)</title>
66

77
<link href="//code.jquery.com/ui/1.12.0-rc.2/themes/base/jquery-ui.css" rel="stylesheet" />
8-
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
8+
9+
<!-- <script src="//code.jquery.com/jquery-1.11.3.min.js"></script> -->
10+
<script src="//code.jquery.com/jquery-1.12.4.min.js"></script>
11+
<!-- <script src="//code.jquery.com/jquery-3.0.0.min.js"></script> -->
12+
<!-- <script src="//code.jquery.com/jquery-migrate-3.0.0.min.js"></script> -->
13+
914
<script src="//code.jquery.com/ui/1.12.0-rc.2/jquery-ui.min.js"></script>
1015

1116
<!-- Optional custom library to enable 'taphold' events -->
@@ -231,21 +236,21 @@ <h3>Sample 2</h3>
231236
</div>
232237

233238
<ul id="options" style="display: none;">
234-
<li data-command="action1"><span class="ui-icon custom-icon-firefox"></span>Action 1</li>
235-
<li data-command="action2"><span class="ui-icon ui-icon-heart"></span>Action 2</li>
236-
<li data-command="action3" class="ui-state-disabled">Action 3</li>
239+
<li data-command="action1"><div><span class="ui-icon custom-icon-firefox"></span>Action 1</div></li>
240+
<li data-command="action2"><div><span class="ui-icon ui-icon-heart"></span>Action 2</div></li>
241+
<li data-command="action3" class="ui-state-disabled"><div>Action 3</div></li>
237242
<li>----</li>
238243
<li>Extra
239244
<ul>
240-
<li data-command="action4">sub4</li>
241-
<li data-command="action5">sub5</li>
245+
<li data-command="action4"><div>sub4</div></li>
246+
<li data-command="action5"><div>sub5</div></li>
242247
</ul>
243248
</li>
244249
</ul>
245250

246251
<ul id="options2" class="ui-helper-hidden">
247-
<li data-command="action2"><span class="ui-icon ui-icon-heart"></span>Action 2
248-
<li data-command="action3" class="ui-state-disabled">Action 3
252+
<li data-command="action2"><span class="ui-icon ui-icon-heart"></span>Action 2</li>
253+
<li data-command="action3" class="ui-state-disabled">Action 3</li>
249254
</ul>
250255

251256
<h3>Sample 3</h3>

demo/index.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
<title>jquery.ui-contextmenu.js - Demo</title>
66

77
<link href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet" />
8-
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
8+
9+
<!-- <script src="//code.jquery.com/jquery-1.11.3.min.js"></script> -->
10+
<script src="//code.jquery.com/jquery-1.12.4.min.js"></script>
11+
<!-- <script src="//code.jquery.com/jquery-3.0.0.min.js"></script> -->
12+
<!-- <script src="//code.jquery.com/jquery-migrate-3.0.0.min.js"></script> -->
13+
914
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
1015

1116
<!-- Optional custom library to enable 'taphold' events -->

lib/qunit-composite.css

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
.qunit-composite-suite {
2+
position: fixed;
3+
bottom: 0;
4+
left: 0;
5+
6+
margin: 0;
7+
padding: 0;
8+
border-width: 1px 0 0;
9+
height: 45%;
10+
width: 100%;
11+
12+
background: #fff;
13+
}
14+
15+
#qunit-testsuites {
16+
margin: 0;
17+
padding: 0.5em 1.0em;
18+
font-family: "Helvetica Neue Light","HelveticaNeue-Light","Helvetica Neue",Calibri,Helvetica,Arial,sans-serif;
19+
font-size: small;
20+
background-color: #d2e0e6;
21+
border-bottom: 1px solid #fff;
22+
}
23+
24+
#qunit-testsuites a {
25+
color: #00c;
26+
text-decoration: none;
27+
}
28+
29+
#qunit-testsuites a:hover {
30+
text-decoration: underline;
31+
}
32+
33+
#qunit-testsuites > li {
34+
display: inline-block;
35+
}
36+
37+
#qunit-testsuites > li:first-child::before {
38+
content: "Suites: ";
39+
}
40+
41+
#qunit-testsuites > li + li::before {
42+
content: "|\a0";
43+
}
44+
45+
#qunit-testsuites > li::after {
46+
content: "\a0";
47+
}

lib/qunit-composite.js

Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
/**
2+
* QUnit Composite
3+
*
4+
* https://github.com/JamesMGreene/qunit-composite
5+
*
6+
* Copyright jQuery Foundation and other contributors
7+
* Released under the MIT license.
8+
* https://jquery.org/license/
9+
*/
10+
(function( factory ) {
11+
if ( typeof define === "function" && define.amd ) {
12+
define( [ "qunit" ], factory );
13+
} else {
14+
factory( QUnit );
15+
}
16+
}(function( QUnit ) {
17+
var iframe, hasBound,
18+
modules = 1,
19+
executingComposite = false;
20+
21+
function hasClass( elem, name ) {
22+
return ( " " + elem.className + " " ).indexOf( " " + name + " " ) > -1;
23+
}
24+
25+
function addClass( elem, name ) {
26+
if ( !hasClass( elem, name ) ) {
27+
elem.className += ( elem.className ? " " : "" ) + name;
28+
}
29+
}
30+
31+
function addEvent( elem, type, fn ) {
32+
if ( elem.addEventListener ) {
33+
// Standards-based browsers
34+
elem.addEventListener( type, fn, false );
35+
} else if ( elem.attachEvent ) {
36+
// support: IE <9
37+
elem.attachEvent( "on" + type, fn );
38+
}
39+
}
40+
41+
function runSuite( suite ) {
42+
var path;
43+
44+
if ( QUnit.is( "object", suite ) ) {
45+
path = suite.path;
46+
suite = suite.name;
47+
} else {
48+
path = suite;
49+
}
50+
51+
QUnit.asyncTest( suite, function() {
52+
iframe.setAttribute( "src", path );
53+
// QUnit.start is called from the child iframe's QUnit.done hook.
54+
});
55+
}
56+
57+
function initIframe() {
58+
var iframeWin,
59+
body = document.body;
60+
61+
function onIframeLoad() {
62+
var moduleName, testName,
63+
count = 0;
64+
65+
if ( !iframe.src ) {
66+
return;
67+
}
68+
69+
// Deal with QUnit being loaded asynchronously via AMD
70+
if ( !iframeWin.QUnit && iframeWin.define && iframeWin.define.amd ) {
71+
return iframeWin.require( [ "qunit" ], onIframeLoad );
72+
}
73+
74+
iframeWin.QUnit.moduleStart(function( data ) {
75+
// Capture module name for messages
76+
moduleName = data.name;
77+
});
78+
79+
iframeWin.QUnit.testStart(function( data ) {
80+
// Capture test name for messages
81+
testName = data.name;
82+
});
83+
iframeWin.QUnit.testDone(function() {
84+
testName = undefined;
85+
});
86+
87+
iframeWin.QUnit.log(function( data ) {
88+
if (testName === undefined) {
89+
return;
90+
}
91+
// Pass all test details through to the main page
92+
var message = ( moduleName ? moduleName + ": " : "" ) + testName + ": " + ( data.message || ( data.result ? "okay" : "failed" ) );
93+
expect( ++count );
94+
QUnit.push( data.result, data.actual, data.expected, message );
95+
});
96+
97+
// Continue the outer test when the iframe's test is done
98+
iframeWin.QUnit.done(function() {
99+
QUnit.start();
100+
});
101+
}
102+
103+
iframe = document.createElement( "iframe" );
104+
iframe.className = "qunit-composite-suite";
105+
body.appendChild( iframe );
106+
107+
addEvent( iframe, "load", onIframeLoad );
108+
109+
iframeWin = iframe.contentWindow;
110+
}
111+
112+
function appendSuitesToHeader( suites ) {
113+
var i, suitesLen, suite, path, name, suitesEl, testResultEl,
114+
newSuiteListItemEl, newSuiteLinkEl;
115+
116+
suitesEl = document.getElementById("qunit-testsuites");
117+
118+
if (!suitesEl) {
119+
testResultEl = document.getElementById("qunit-testresult");
120+
121+
if (!testResultEl) {
122+
// QUnit has not been set up yet. Defer until QUnit is ready.
123+
QUnit.begin(function () {
124+
appendSuitesToHeader(suites);
125+
});
126+
return;
127+
}
128+
129+
suitesEl = document.createElement("ul");
130+
suitesEl.id = "qunit-testsuites";
131+
testResultEl.parentNode.insertBefore(suitesEl, testResultEl);
132+
}
133+
134+
for (i = 0, suitesLen = suites.length; i < suitesLen; ++i) {
135+
suite = suites[i];
136+
newSuiteLinkEl = document.createElement("a");
137+
newSuiteLinkEl.innerHTML = suite.name || suite;
138+
newSuiteLinkEl.href = suite.path || suite;
139+
140+
newSuiteListItemEl = document.createElement("li");
141+
newSuiteListItemEl.appendChild(newSuiteLinkEl);
142+
143+
suitesEl.appendChild(newSuiteListItemEl);
144+
}
145+
}
146+
147+
/**
148+
* @param {string} [name] Module name to group these test suites.
149+
* @param {Array} suites List of suites where each suite
150+
* may either be a string (path to the html test page),
151+
* or an object with a path and name property.
152+
*/
153+
QUnit.testSuites = function( name, suites ) {
154+
var i, suitesLen;
155+
156+
if ( arguments.length === 1 ) {
157+
suites = name;
158+
name = "Composition #" + modules++;
159+
}
160+
suitesLen = suites.length;
161+
162+
appendSuitesToHeader(suites);
163+
164+
if ( !hasBound ) {
165+
hasBound = true;
166+
QUnit.begin( initIframe );
167+
168+
// TODO: Would be better to use something like QUnit.once( 'moduleDone' )
169+
// after the last test suite.
170+
QUnit.moduleDone( function () {
171+
executingComposite = false;
172+
} );
173+
174+
QUnit.done(function() {
175+
iframe.style.display = "none";
176+
});
177+
}
178+
179+
QUnit.module( name, {
180+
setup: function () {
181+
executingComposite = true;
182+
}
183+
});
184+
185+
for ( i = 0; i < suitesLen; i++ ) {
186+
runSuite( suites[ i ] );
187+
}
188+
};
189+
190+
QUnit.testDone(function( data ) {
191+
if ( !executingComposite ) {
192+
return;
193+
}
194+
195+
var i, len,
196+
testId = data.testId || QUnit.config.current.testId || data.testNumber || QUnit.config.current.testNumber,
197+
current = testId ?
198+
(
199+
// QUnit @^1.16.0
200+
document.getElementById( "qunit-test-output-" + testId ) ||
201+
// QUnit @1.15.x
202+
document.getElementById( "qunit-test-output" + testId )
203+
) :
204+
// QUnit @<1.15.0
205+
document.getElementById( QUnit.config.current.id ),
206+
children = current && current.children,
207+
src = iframe.src;
208+
209+
if (!(current && children)) {
210+
return;
211+
}
212+
213+
addEvent( current, "dblclick", function( e ) {
214+
var target = e && e.target ? e.target : window.event.srcElement;
215+
if ( target.nodeName.toLowerCase() === "span" || target.nodeName.toLowerCase() === "b" ) {
216+
target = target.parentNode;
217+
}
218+
if ( window.location && target.nodeName.toLowerCase() === "strong" ) {
219+
window.location = src;
220+
}
221+
});
222+
223+
// Undo QUnit's auto-expansion for bad tests
224+
for ( i = 0, len = children.length; i < len; i++ ) {
225+
if ( children[ i ].nodeName.toLowerCase() === "ol" ) {
226+
addClass( children[ i ], "qunit-collapsed" );
227+
}
228+
}
229+
230+
// Update Rerun link to point to the standalone test suite page
231+
current.getElementsByTagName( "a" )[ 0 ].href = src;
232+
});
233+
234+
}));

0 commit comments

Comments
 (0)