mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Build: Refactor Node smoke tests
Utilize the assert module, avoid inline JSHint comments.
This commit is contained in:
parent
1556c4661a
commit
9c8a3ecdc4
@ -15,7 +15,8 @@ module.exports = function( grunt ) {
|
|||||||
|
|
||||||
fs.readdirSync( testsDir )
|
fs.readdirSync( testsDir )
|
||||||
.filter( function( testFilePath ) {
|
.filter( function( testFilePath ) {
|
||||||
return fs.statSync( testsDir + testFilePath ).isFile();
|
return fs.statSync( testsDir + testFilePath ).isFile() &&
|
||||||
|
/\.js$/.test( testFilePath );
|
||||||
} )
|
} )
|
||||||
.forEach( function( testFilePath ) {
|
.forEach( function( testFilePath ) {
|
||||||
var taskName = "node_" + testFilePath.replace( /\.js$/, "" );
|
var taskName = "node_" + testFilePath.replace( /\.js$/, "" );
|
||||||
|
14
test/node_smoke_tests/.jshintrc
Normal file
14
test/node_smoke_tests/.jshintrc
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"boss": true,
|
||||||
|
"curly": true,
|
||||||
|
"eqeqeq": true,
|
||||||
|
"eqnull": true,
|
||||||
|
"expr": true,
|
||||||
|
"immed": true,
|
||||||
|
"noarg": true,
|
||||||
|
"quotmark": "double",
|
||||||
|
"undef": true,
|
||||||
|
"unused": true,
|
||||||
|
|
||||||
|
"node": true
|
||||||
|
}
|
@ -1,19 +1,11 @@
|
|||||||
/* jshint node: true */
|
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var ensureGlobalNotCreated = require( "./lib/ensure_global_not_created" ),
|
var assert = require( "assert" ),
|
||||||
|
ensureGlobalNotCreated = require( "./lib/ensure_global_not_created" ),
|
||||||
jQueryFactory = require( "../../dist/jquery.js" );
|
jQueryFactory = require( "../../dist/jquery.js" );
|
||||||
|
|
||||||
try {
|
assert.throws( function () {
|
||||||
jQueryFactory( {} );
|
jQueryFactory( {} );
|
||||||
console.error( "The jQuery factory should reject window without a document" );
|
}, /jQuery requires a window with a document/ );
|
||||||
process.exit( 1 );
|
|
||||||
} catch ( e ) {
|
ensureGlobalNotCreated( module.exports );
|
||||||
if ( e.message === "jQuery requires a window with a document" ) {
|
|
||||||
ensureGlobalNotCreated( module.exports );
|
|
||||||
process.exit( 0 );
|
|
||||||
}
|
|
||||||
console.error( "An unexpected error thrown; message: ", e.message );
|
|
||||||
process.exit( 1 );
|
|
||||||
}
|
|
||||||
|
@ -1,12 +1,9 @@
|
|||||||
/* jshint node: true */
|
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
var assert = require( "assert" );
|
||||||
|
|
||||||
require( "jsdom" ).env( "", function( errors, window ) {
|
require( "jsdom" ).env( "", function( errors, window ) {
|
||||||
if ( errors ) {
|
assert.ifError( errors );
|
||||||
console.error( errors );
|
|
||||||
process.exit( 1 );
|
|
||||||
}
|
|
||||||
|
|
||||||
var ensureJQuery = require( "./lib/ensure_jquery" ),
|
var ensureJQuery = require( "./lib/ensure_jquery" ),
|
||||||
ensureGlobalNotCreated = require( "./lib/ensure_global_not_created" ),
|
ensureGlobalNotCreated = require( "./lib/ensure_global_not_created" ),
|
||||||
|
@ -1,12 +1,9 @@
|
|||||||
/* jshint node: true */
|
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
var assert = require( "assert" );
|
||||||
|
|
||||||
require( "jsdom" ).env( "", function( errors, window ) {
|
require( "jsdom" ).env( "", function( errors, window ) {
|
||||||
if ( errors ) {
|
assert.ifError( errors );
|
||||||
console.error( errors );
|
|
||||||
process.exit( 1 );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pretend the window is a global.
|
// Pretend the window is a global.
|
||||||
global.window = window;
|
global.window = window;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/* jshint node: true */
|
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
var assert = require( "assert" );
|
||||||
|
|
||||||
// Ensure the jQuery property on global/window/module.exports/etc. was not
|
// Ensure the jQuery property on global/window/module.exports/etc. was not
|
||||||
// created in a CommonJS environment.
|
// created in a CommonJS environment.
|
||||||
// `global` is always checked in addition to passed parameters.
|
// `global` is always checked in addition to passed parameters.
|
||||||
@ -9,9 +9,7 @@ module.exports = function ensureGlobalNotCreated() {
|
|||||||
var args = [].slice.call( arguments ).concat( global );
|
var args = [].slice.call( arguments ).concat( global );
|
||||||
|
|
||||||
args.forEach( function( object ) {
|
args.forEach( function( object ) {
|
||||||
if ( object.jQuery ) {
|
assert.strictEqual( object.jQuery, undefined,
|
||||||
console.error( "A jQuery global was created in a CommonJS environment." );
|
"A jQuery global was created in a CommonJS environment." );
|
||||||
process.exit( 1 );
|
|
||||||
}
|
|
||||||
} );
|
} );
|
||||||
};
|
};
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
/* jshint node: true */
|
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
var assert = require( "assert" );
|
||||||
|
|
||||||
// Check if the object we got is the jQuery object by invoking a basic API.
|
// Check if the object we got is the jQuery object by invoking a basic API.
|
||||||
module.exports = function ensureJQuery( jQuery ) {
|
module.exports = function ensureJQuery( jQuery ) {
|
||||||
if ( !/^jQuery/.test( jQuery.expando ) ) {
|
assert( /^jQuery/.test( jQuery.expando ),
|
||||||
console.error( "jQuery.expando was not detected, the jQuery bootstrap process has failed" );
|
"jQuery.expando was not detected, the jQuery bootstrap process has failed" );
|
||||||
process.exit( 1 );
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user