Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
jquery
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏彬
jquery
Commits
5b9bf134
Commit
5b9bf134
authored
Dec 03, 2012
by
Richard Gibson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
No ticket: improve global variable/ajax request tracking
parent
27c9360a
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
68 additions
and
54 deletions
+68
-54
.jshintrc
test/.jshintrc
+0
-1
test.js
test/data/test.js
+1
-1
testinit.js
test/data/testinit.js
+31
-24
testrunner.js
test/data/testrunner.js
+8
-8
ajax.js
test/unit/ajax.js
+26
-7
core.js
test/unit/core.js
+1
-2
manipulation.js
test/unit/manipulation.js
+1
-11
No files found.
test/.jshintrc
View file @
5b9bf134
...
@@ -45,7 +45,6 @@
...
@@ -45,7 +45,6 @@
"createXMLFragment": true,
"createXMLFragment": true,
"moduleTeardown": true,
"moduleTeardown": true,
"testFoo": true,
"testFoo": true,
"foobar": true,
"url": true,
"url": true,
"t": true,
"t": true,
"q": true,
"q": true,
...
...
test/data/test.js
View file @
5b9bf134
var
foob
ar
=
"bar"
;
var
testB
ar
=
"bar"
;
jQuery
(
'#ap'
).
html
(
'bar'
);
jQuery
(
'#ap'
).
html
(
'bar'
);
ok
(
true
,
"test.js executed"
);
ok
(
true
,
"test.js executed"
);
test/data/testinit.js
View file @
5b9bf134
...
@@ -158,39 +158,46 @@ function ajaxTest( title, expect, options ) {
...
@@ -158,39 +158,46 @@ function ajaxTest( title, expect, options ) {
if
(
options
.
setup
)
{
if
(
options
.
setup
)
{
options
.
setup
();
options
.
setup
();
}
}
var
aborted
=
false
,
abort
=
function
(
reason
)
{
var
completed
=
false
,
if
(
!
aborted
)
{
complete
=
function
()
{
aborted
=
true
;
completed
=
true
;
delete
ajaxTest
.
abort
;
},
abort
=
ajaxTest
.
abort
=
function
(
reason
)
{
if
(
!
completed
)
{
complete
();
ok
(
false
,
"unexpected "
+
reason
);
ok
(
false
,
"unexpected "
+
reason
);
jQuery
.
each
(
requests
,
function
(
_
,
request
)
{
jQuery
.
each
(
requests
,
function
(
_
,
request
)
{
request
.
abort
();
if
(
request
&&
request
.
abort
)
{
request
.
abort
();
}
});
});
}
}
},
},
requests
=
jQuery
.
map
(
requestOptions
,
function
(
options
)
{
requests
=
jQuery
.
map
(
requestOptions
,
function
(
options
,
index
)
{
var
request
=
(
options
.
create
||
jQuery
.
ajax
)(
options
);
var
request
=
(
options
.
create
||
jQuery
.
ajax
)(
options
),
callIfDefined
=
function
(
deferType
,
optionType
)
{
var
handler
=
options
[
deferType
]
||
!!
options
[
optionType
];
return
handler
?
function
()
{
if
(
!
completed
&&
jQuery
.
isFunction
(
handler
)
)
{
handler
.
apply
(
this
,
arguments
);
}
}
:
function
()
{
abort
(
optionType
);
};
};
if
(
options
.
afterSend
)
{
if
(
options
.
afterSend
)
{
options
.
afterSend
(
request
);
options
.
afterSend
(
request
);
}
}
return
request
;
return
request
.
then
(
callIfDefined
(
"done"
,
"success"
),
callIfDefined
(
"fail"
,
"error"
)
);
});
});
jQuery
.
when
.
apply
(
jQuery
,
jQuery
.
map
(
requests
,
function
(
request
,
index
)
{
function
callIfDefined
(
deferType
,
optionType
)
{
jQuery
.
when
.
apply
(
jQuery
,
requests
).
always
(
complete
,
options
.
teardown
,
start
);
var
handler
=
requestOptions
[
index
][
deferType
]
||
!!
requestOptions
[
index
][
optionType
];
return
handler
?
function
()
{
if
(
!
aborted
&&
jQuery
.
isFunction
(
handler
)
)
{
handler
.
apply
(
this
,
arguments
);
}
}
:
function
()
{
abort
(
optionType
);
}
}
return
request
.
then
(
callIfDefined
(
"done"
,
"success"
),
callIfDefined
(
"fail"
,
"error"
)
);
})
).
always
(
options
.
teardown
,
start
);
});
});
};
};
...
...
test/data/testrunner.js
View file @
5b9bf134
...
@@ -3,10 +3,10 @@
...
@@ -3,10 +3,10 @@
*/
*/
jQuery
.
noConflict
();
jQuery
.
noConflict
();
// For checking globals pollution
// For checking globals pollution
despite auto-created globals in various environments
window
[
jQuery
.
expando
]
=
undefined
;
jQuery
.
each
(
[
jQuery
.
expando
,
"getInterface"
,
"Packages"
,
"java"
,
"netscape"
],
function
(
i
,
name
)
{
// ...in Gecko
window
[
name
]
=
window
[
name
];
this
.
getInterface
=
this
.
getInterface
;
})
;
// Expose Sizzle for Sizzle's selector tests
// Expose Sizzle for Sizzle's selector tests
// We remove Sizzle's globalization in jQuery
// We remove Sizzle's globalization in jQuery
...
@@ -138,7 +138,7 @@ function testSubproject( label, url, risTests ) {
...
@@ -138,7 +138,7 @@ function testSubproject( label, url, risTests ) {
// Explanation at http://perfectionkills.com/understanding-delete/#ie_bugs
// Explanation at http://perfectionkills.com/understanding-delete/#ie_bugs
var
Globals
=
(
function
()
{
var
Globals
=
(
function
()
{
var
globals
=
{};
var
globals
=
{};
return
QUnit
.
config
.
noglobals
?
{
return
{
register
:
function
(
name
)
{
register
:
function
(
name
)
{
globals
[
name
]
=
true
;
globals
[
name
]
=
true
;
jQuery
.
globalEval
(
"var "
+
name
);
jQuery
.
globalEval
(
"var "
+
name
);
...
@@ -153,9 +153,6 @@ var Globals = (function() {
...
@@ -153,9 +153,6 @@ var Globals = (function() {
"; } catch( x ) {}"
);
"; } catch( x ) {}"
);
}
}
}
}
}
:
{
register
:
jQuery
.
noop
,
cleanup
:
jQuery
.
noop
};
};
})();
})();
...
@@ -312,6 +309,9 @@ var Globals = (function() {
...
@@ -312,6 +309,9 @@ var Globals = (function() {
}
}
if
(
jQuery
.
active
!==
undefined
&&
jQuery
.
active
!==
oldActive
)
{
if
(
jQuery
.
active
!==
undefined
&&
jQuery
.
active
!==
oldActive
)
{
equal
(
jQuery
.
active
,
0
,
"No AJAX requests are still active"
);
equal
(
jQuery
.
active
,
0
,
"No AJAX requests are still active"
);
if
(
ajaxTest
.
abort
)
{
ajaxTest
.
abort
(
"active request"
);
}
oldActive
=
jQuery
.
active
;
oldActive
=
jQuery
.
active
;
}
}
};
};
...
...
test/unit/ajax.js
View file @
5b9bf134
...
@@ -533,7 +533,7 @@ module( "ajax", {
...
@@ -533,7 +533,7 @@ module( "ajax", {
ajaxTest
(
"jQuery.ajax() - dataType html"
,
5
,
{
ajaxTest
(
"jQuery.ajax() - dataType html"
,
5
,
{
setup
:
function
()
{
setup
:
function
()
{
Globals
.
register
(
"testFoo"
);
Globals
.
register
(
"testFoo"
);
Globals
.
register
(
"
foob
ar"
);
Globals
.
register
(
"
testB
ar"
);
},
},
dataType
:
"html"
,
dataType
:
"html"
,
url
:
url
(
"data/test.html"
),
url
:
url
(
"data/test.html"
),
...
@@ -541,7 +541,7 @@ module( "ajax", {
...
@@ -541,7 +541,7 @@ module( "ajax", {
ok
(
data
.
match
(
/^html text/
),
"Check content for datatype html"
);
ok
(
data
.
match
(
/^html text/
),
"Check content for datatype html"
);
jQuery
(
"#ap"
).
html
(
data
);
jQuery
(
"#ap"
).
html
(
data
);
strictEqual
(
window
[
"testFoo"
],
"foo"
,
"Check if script was evaluated for datatype html"
);
strictEqual
(
window
[
"testFoo"
],
"foo"
,
"Check if script was evaluated for datatype html"
);
strictEqual
(
window
[
"
foob
ar"
],
"bar"
,
"Check if script src was evaluated for datatype html"
);
strictEqual
(
window
[
"
testB
ar"
],
"bar"
,
"Check if script src was evaluated for datatype html"
);
}
}
});
});
...
@@ -588,6 +588,7 @@ module( "ajax", {
...
@@ -588,6 +588,7 @@ module( "ajax", {
jQuery
(
document
).
off
(
"ajaxError.passthru"
);
jQuery
(
document
).
off
(
"ajaxError.passthru"
);
start
();
start
();
});
});
Globals
.
register
(
"testBar"
);
ok
(
jQuery
.
get
(
url
(
target
),
success
),
"get"
);
ok
(
jQuery
.
get
(
url
(
target
),
success
),
"get"
);
ok
(
jQuery
.
post
(
url
(
target
),
success
),
"post"
);
ok
(
jQuery
.
post
(
url
(
target
),
success
),
"post"
);
...
@@ -836,28 +837,37 @@ module( "ajax", {
...
@@ -836,28 +837,37 @@ module( "ajax", {
});
});
ajaxTest
(
"jQuery.ajax() - script, Remote"
,
2
,
{
ajaxTest
(
"jQuery.ajax() - script, Remote"
,
2
,
{
setup
:
function
()
{
Globals
.
register
(
"testBar"
);
},
url
:
window
.
location
.
href
.
replace
(
/
[^\/]
*$/
,
""
)
+
"data/test.js"
,
url
:
window
.
location
.
href
.
replace
(
/
[^\/]
*$/
,
""
)
+
"data/test.js"
,
dataType
:
"script"
,
dataType
:
"script"
,
success
:
function
(
data
)
{
success
:
function
(
data
)
{
ok
(
window
[
"foobar"
]
,
"Script results returned (GET, no callback)"
);
strictEqual
(
window
[
"testBar"
],
"bar"
,
"Script results returned (GET, no callback)"
);
}
}
});
});
ajaxTest
(
"jQuery.ajax() - script, Remote with POST"
,
3
,
{
ajaxTest
(
"jQuery.ajax() - script, Remote with POST"
,
3
,
{
setup
:
function
()
{
Globals
.
register
(
"testBar"
);
},
url
:
window
.
location
.
href
.
replace
(
/
[^\/]
*$/
,
""
)
+
"data/test.js"
,
url
:
window
.
location
.
href
.
replace
(
/
[^\/]
*$/
,
""
)
+
"data/test.js"
,
type
:
"POST"
,
type
:
"POST"
,
dataType
:
"script"
,
dataType
:
"script"
,
success
:
function
(
data
,
status
)
{
success
:
function
(
data
,
status
)
{
ok
(
window
[
"foobar"
]
,
"Script results returned (POST, no callback)"
);
strictEqual
(
window
[
"testBar"
],
"bar"
,
"Script results returned (POST, no callback)"
);
strictEqual
(
status
,
"success"
,
"Script results returned (POST, no callback)"
);
strictEqual
(
status
,
"success"
,
"Script results returned (POST, no callback)"
);
}
}
});
});
ajaxTest
(
"jQuery.ajax() - script, Remote with scheme-less URL"
,
2
,
{
ajaxTest
(
"jQuery.ajax() - script, Remote with scheme-less URL"
,
2
,
{
setup
:
function
()
{
Globals
.
register
(
"testBar"
);
},
url
:
window
.
location
.
href
.
replace
(
/
[^\/]
*$/
,
""
).
replace
(
/^.*
?\/\/
/
,
"//"
)
+
"data/test.js"
,
url
:
window
.
location
.
href
.
replace
(
/
[^\/]
*$/
,
""
).
replace
(
/^.*
?\/\/
/
,
"//"
)
+
"data/test.js"
,
dataType
:
"script"
,
dataType
:
"script"
,
success
:
function
(
data
)
{
success
:
function
(
data
)
{
ok
(
window
[
"foobar"
]
,
"Script results returned (GET, no callback)"
);
strictEqual
(
window
[
"testBar"
],
"bar"
,
"Script results returned (GET, no callback)"
);
}
}
});
});
...
@@ -1655,17 +1665,20 @@ module( "ajax", {
...
@@ -1655,17 +1665,20 @@ module( "ajax", {
//----------- jQuery.getScript()
//----------- jQuery.getScript()
asyncTest
(
"jQuery.getScript( String, Function ) - with callback"
,
2
,
function
()
{
asyncTest
(
"jQuery.getScript( String, Function ) - with callback"
,
2
,
function
()
{
Globals
.
register
(
"testBar"
);
jQuery
.
getScript
(
url
(
"data/test.js"
),
function
(
data
,
_
,
jqXHR
)
{
jQuery
.
getScript
(
url
(
"data/test.js"
),
function
(
data
,
_
,
jqXHR
)
{
strictEqual
(
foobar
,
"bar"
,
"Check if script was evaluated"
);
strictEqual
(
window
[
"testBar"
]
,
"bar"
,
"Check if script was evaluated"
);
start
();
start
();
});
});
});
});
asyncTest
(
"jQuery.getScript( String, Function ) - no callback"
,
1
,
function
()
{
asyncTest
(
"jQuery.getScript( String, Function ) - no callback"
,
1
,
function
()
{
Globals
.
register
(
"testBar"
);
jQuery
.
getScript
(
url
(
"data/test.js"
)
).
done
(
start
);
jQuery
.
getScript
(
url
(
"data/test.js"
)
).
done
(
start
);
});
});
asyncTest
(
"#8082 - jQuery.getScript( String, Function ) - source as responseText"
,
2
,
function
()
{
asyncTest
(
"#8082 - jQuery.getScript( String, Function ) - source as responseText"
,
2
,
function
()
{
Globals
.
register
(
"testBar"
);
jQuery
.
getScript
(
url
(
"data/test.js"
),
function
(
data
,
_
,
jqXHR
)
{
jQuery
.
getScript
(
url
(
"data/test.js"
),
function
(
data
,
_
,
jqXHR
)
{
strictEqual
(
data
,
jqXHR
.
responseText
,
"Same-domain script requests returns the source of the script"
);
strictEqual
(
data
,
jqXHR
.
responseText
,
"Same-domain script requests returns the source of the script"
);
start
();
start
();
...
@@ -1729,10 +1742,14 @@ module( "ajax", {
...
@@ -1729,10 +1742,14 @@ module( "ajax", {
asyncTest
(
"jQuery.fn.load( String, Function ) - check scripts"
,
7
,
function
()
{
asyncTest
(
"jQuery.fn.load( String, Function ) - check scripts"
,
7
,
function
()
{
var
verifyEvaluation
=
function
()
{
var
verifyEvaluation
=
function
()
{
strictEqual
(
window
[
"
foob
ar"
],
"bar"
,
"Check if script src was evaluated after load"
);
strictEqual
(
window
[
"
testB
ar"
],
"bar"
,
"Check if script src was evaluated after load"
);
strictEqual
(
jQuery
(
"#ap"
).
html
(),
"bar"
,
"Check if script evaluation has modified DOM"
);
strictEqual
(
jQuery
(
"#ap"
).
html
(),
"bar"
,
"Check if script evaluation has modified DOM"
);
start
();
start
();
};
};
Globals
.
register
(
"testFoo"
);
Globals
.
register
(
"testBar"
);
jQuery
(
"#first"
).
load
(
url
(
"data/test.html"
),
function
()
{
jQuery
(
"#first"
).
load
(
url
(
"data/test.html"
),
function
()
{
ok
(
jQuery
(
"#first"
).
html
().
match
(
/^html text/
),
"Check content after loading html"
);
ok
(
jQuery
(
"#first"
).
html
().
match
(
/^html text/
),
"Check content after loading html"
);
strictEqual
(
jQuery
(
"#foo"
).
html
(),
"foo"
,
"Check if script evaluation has modified DOM"
);
strictEqual
(
jQuery
(
"#foo"
).
html
(),
"foo"
,
"Check if script evaluation has modified DOM"
);
...
@@ -1742,6 +1759,8 @@ module( "ajax", {
...
@@ -1742,6 +1759,8 @@ module( "ajax", {
});
});
asyncTest
(
"jQuery.fn.load( String, Function ) - check file with only a script tag"
,
3
,
function
()
{
asyncTest
(
"jQuery.fn.load( String, Function ) - check file with only a script tag"
,
3
,
function
()
{
Globals
.
register
(
"testFoo"
);
jQuery
(
"#first"
).
load
(
url
(
"data/test2.html"
),
function
()
{
jQuery
(
"#first"
).
load
(
url
(
"data/test2.html"
),
function
()
{
strictEqual
(
jQuery
(
"#foo"
).
html
(),
"foo"
,
"Check if script evaluation has modified DOM"
);
strictEqual
(
jQuery
(
"#foo"
).
html
(),
"foo"
,
"Check if script evaluation has modified DOM"
);
strictEqual
(
window
[
"testFoo"
],
"foo"
,
"Check if script was evaluated after load"
);
strictEqual
(
window
[
"testFoo"
],
"foo"
,
"Check if script was evaluated after load"
);
...
...
test/unit/core.js
View file @
5b9bf134
...
@@ -195,6 +195,7 @@ test( "selector state", function() {
...
@@ -195,6 +195,7 @@ test( "selector state", function() {
test
(
"globalEval"
,
function
()
{
test
(
"globalEval"
,
function
()
{
expect
(
3
);
expect
(
3
);
Globals
.
register
(
"globalEvalTest"
);
jQuery
.
globalEval
(
"globalEvalTest = 1;"
);
jQuery
.
globalEval
(
"globalEvalTest = 1;"
);
equal
(
window
.
globalEvalTest
,
1
,
"Test variable assignments are global"
);
equal
(
window
.
globalEvalTest
,
1
,
"Test variable assignments are global"
);
...
@@ -204,8 +205,6 @@ test( "globalEval", function() {
...
@@ -204,8 +205,6 @@ test( "globalEval", function() {
jQuery
.
globalEval
(
"this.globalEvalTest = 3;"
);
jQuery
.
globalEval
(
"this.globalEvalTest = 3;"
);
equal
(
window
.
globalEvalTest
,
3
,
"Test context (this) is the window object"
);
equal
(
window
.
globalEvalTest
,
3
,
"Test context (this) is the window object"
);
jQuery
.
globalEval
(
"delete globalEvalTest;"
);
});
});
test
(
"noConflict"
,
function
()
{
test
(
"noConflict"
,
function
()
{
...
...
test/unit/manipulation.js
View file @
5b9bf134
...
@@ -704,7 +704,7 @@ test("append(xml)", function() {
...
@@ -704,7 +704,7 @@ test("append(xml)", function() {
});
});
test
(
"appendTo(String|Element|Array<Element>|jQuery)"
,
function
()
{
test
(
"appendTo(String|Element|Array<Element>|jQuery)"
,
function
()
{
expect
(
16
+
(
jQuery
.
getScript
?
1
:
0
)
);
expect
(
16
);
var
defaultText
=
"Try them out:"
;
var
defaultText
=
"Try them out:"
;
...
@@ -775,16 +775,6 @@ test("appendTo(String|Element|Array<Element>|jQuery)", function() {
...
@@ -775,16 +775,6 @@ test("appendTo(String|Element|Array<Element>|jQuery)", function() {
div
.
remove
().
appendTo
(
"#qunit-fixture"
);
div
.
remove
().
appendTo
(
"#qunit-fixture"
);
equal
(
jQuery
(
"#qunit-fixture div"
).
length
,
num
,
"Make sure all the removed divs were inserted."
);
equal
(
jQuery
(
"#qunit-fixture div"
).
length
,
num
,
"Make sure all the removed divs were inserted."
);
QUnit
.
reset
();
if
(
jQuery
.
getScript
)
{
stop
();
jQuery
.
getScript
(
"data/test.js"
,
function
()
{
jQuery
(
"script[src*='data
\\
/test
\\
.js']"
).
remove
();
start
();
});
}
});
});
var
testPrepend
=
function
(
val
)
{
var
testPrepend
=
function
(
val
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment