Skip to content

Commit 9c8a3ec

Browse files
committed
Build: Refactor Node smoke tests
Utilize the assert module, avoid inline JSHint comments.
1 parent 1556c46 commit 9c8a3ec

File tree

7 files changed

+36
-39
lines changed

7 files changed

+36
-39
lines changed

build/tasks/node_smoke_tests.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ module.exports = function( grunt ) {
1515

1616
fs.readdirSync( testsDir )
1717
.filter( function( testFilePath ) {
18-
return fs.statSync( testsDir + testFilePath ).isFile();
18+
return fs.statSync( testsDir + testFilePath ).isFile() &&
19+
/\.js$/.test( testFilePath );
1920
} )
2021
.forEach( function( testFilePath ) {
2122
var taskName = "node_" + testFilePath.replace( /\.js$/, "" );

test/node_smoke_tests/.jshintrc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"boss": true,
3+
"curly": true,
4+
"eqeqeq": true,
5+
"eqnull": true,
6+
"expr": true,
7+
"immed": true,
8+
"noarg": true,
9+
"quotmark": "double",
10+
"undef": true,
11+
"unused": true,
12+
13+
"node": true
14+
}
Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
1-
/* jshint node: true */
2-
31
"use strict";
42

5-
var ensureGlobalNotCreated = require( "./lib/ensure_global_not_created" ),
3+
var assert = require( "assert" ),
4+
ensureGlobalNotCreated = require( "./lib/ensure_global_not_created" ),
65
jQueryFactory = require( "../../dist/jquery.js" );
76

8-
try {
7+
assert.throws( function () {
98
jQueryFactory( {} );
10-
console.error( "The jQuery factory should reject window without a document" );
11-
process.exit( 1 );
12-
} catch ( e ) {
13-
if ( e.message === "jQuery requires a window with a document" ) {
14-
ensureGlobalNotCreated( module.exports );
15-
process.exit( 0 );
16-
}
17-
console.error( "An unexpected error thrown; message: ", e.message );
18-
process.exit( 1 );
19-
}
9+
}, /jQuery requires a window with a document/ );
10+
11+
ensureGlobalNotCreated( module.exports );

test/node_smoke_tests/document_passed.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
/* jshint node: true */
2-
31
"use strict";
42

3+
var assert = require( "assert" );
4+
55
require( "jsdom" ).env( "", function( errors, window ) {
6-
if ( errors ) {
7-
console.error( errors );
8-
process.exit( 1 );
9-
}
6+
assert.ifError( errors );
107

118
var ensureJQuery = require( "./lib/ensure_jquery" ),
129
ensureGlobalNotCreated = require( "./lib/ensure_global_not_created" ),

test/node_smoke_tests/document_present_originally.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
/* jshint node: true */
2-
31
"use strict";
42

3+
var assert = require( "assert" );
4+
55
require( "jsdom" ).env( "", function( errors, window ) {
6-
if ( errors ) {
7-
console.error( errors );
8-
process.exit( 1 );
9-
}
6+
assert.ifError( errors );
107

118
// Pretend the window is a global.
129
global.window = window;
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
/* jshint node: true */
2-
31
"use strict";
42

3+
var assert = require( "assert" );
4+
55
// Ensure the jQuery property on global/window/module.exports/etc. was not
66
// created in a CommonJS environment.
77
// `global` is always checked in addition to passed parameters.
88
module.exports = function ensureGlobalNotCreated() {
99
var args = [].slice.call( arguments ).concat( global );
1010

1111
args.forEach( function( object ) {
12-
if ( object.jQuery ) {
13-
console.error( "A jQuery global was created in a CommonJS environment." );
14-
process.exit( 1 );
15-
}
12+
assert.strictEqual( object.jQuery, undefined,
13+
"A jQuery global was created in a CommonJS environment." );
1614
} );
1715
};
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
/* jshint node: true */
2-
31
"use strict";
42

3+
var assert = require( "assert" );
4+
55
// Check if the object we got is the jQuery object by invoking a basic API.
66
module.exports = function ensureJQuery( jQuery ) {
7-
if ( !/^jQuery/.test( jQuery.expando ) ) {
8-
console.error( "jQuery.expando was not detected, the jQuery bootstrap process has failed" );
9-
process.exit( 1 );
10-
}
7+
assert( /^jQuery/.test( jQuery.expando ),
8+
"jQuery.expando was not detected, the jQuery bootstrap process has failed" );
119
};

0 commit comments

Comments
 (0)