Skip to content

Commit

Permalink
CLI: Introduce QUnit CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
Trent Willis committed Mar 17, 2017
1 parent f40e35c commit 33b8eba
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 8 deletions.
18 changes: 18 additions & 0 deletions bin/qunitjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#! /usr/bin/env node
/* eslint-env node */

var program = require( "commander" );
var run = require( "./run" );
var utils = require( "./utils" );
var pkg = require( "../package.json" );

program._name = "qunit";
program
.version( pkg.version )
.usage( "[options] [files]" )
.parse( process.argv );

var args = program.args;
var files = utils.getFilesFromArgs( args );

run( files );
34 changes: 34 additions & 0 deletions bin/run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* eslint-env node */
var path = require( "path" );
var TapReporter = require( "js-reporters" ).TapReporter;

// During development, QUnit is built into "dist/", but when published to npm
// we move it to "qunit/". This IIFE handles both cases.
var QUnit = ( function requireQUnit() {
try {
return require( "../qunit/qunit" );
} catch ( e ) {
if ( e.code === "MODULE_NOT_FOUND" ) {
return require( "../dist/qunit" );
}

throw e;
}
}() );

module.exports = function run( files ) {
global.QUnit = QUnit;

TapReporter.init( QUnit );

for ( var i = 0; i < files.length; i++ ) {
var filePath = path.resolve( process.cwd(), files[ i ] );
require( filePath );
}

QUnit.start();

QUnit.on( "runEnd", function( data ) {
process.exitCode = data.testCounts.failed;
} );
};
27 changes: 27 additions & 0 deletions bin/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* eslint-env node */

var walkSync = require( "walk-sync" );

function getFilesFromArgs( args ) {
if ( !args.length ) {
error( "Please include at least one file argument" );
}

var files = walkSync( process.cwd(), { globs: args } );

if ( !files.length ) {
error( "No files were found matching: " + args.join( ", " ) );
}

return files;
}

function error( message ) {
console.error( message );
process.exit( 1 );
}

module.exports = {
error: error,
getFilesFromArgs: getFilesFromArgs
};
11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,20 @@
"url": "https://github.com/qunitjs/qunit/issues"
},
"license": "MIT",
"bin": {
"qunit": "bin/qunitjs"
},
"files": [
"bin/",
"qunit/qunit.js",
"qunit/qunit.css",
"LICENSE.txt"
],
"dependencies": {},
"dependencies": {
"commander": "^2.9.0",
"js-reporters": "^1.1.0",
"walk-sync": "^0.3.1"
},
"devDependencies": {
"async": "2.1.4",
"babel-plugin-external-helpers": "6.18.0",
Expand Down Expand Up @@ -65,6 +73,7 @@
"All",
"Assert",
"Build",
"CLI",
"CSS",
"Core",
"Dump",
Expand Down
35 changes: 28 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,10 @@ end-of-stream@^1.1.0:
dependencies:
once "~1.3.0"

ensure-posix-path@^1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/ensure-posix-path/-/ensure-posix-path-1.0.2.tgz#a65b3e42d0b71cfc585eb774f9943c8d9b91b0c2"

entities@^1.1.1, entities@~1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/entities/-/entities-1.1.1.tgz#6e5c2d0a5621b5dadaecef80b90edfb5cd7772f0"
Expand Down Expand Up @@ -1339,7 +1343,7 @@ glob@^5.0.15, glob@~5.0.0:
once "^1.3.0"
path-is-absolute "^1.0.0"

glob@^7.0.0, glob@^7.0.5, glob@~7.1.1:
glob@^7.0.0, glob@~7.1.1:
version "7.1.1"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.1.tgz#805211df04faaf1c63a3600306cdf5ade50b2ec8"
dependencies:
Expand All @@ -1350,7 +1354,7 @@ glob@^7.0.0, glob@^7.0.5, glob@~7.1.1:
once "^1.3.0"
path-is-absolute "^1.0.0"

glob@^7.0.3, glob@~7.0.0:
glob@^7.0.3, glob@^7.0.5, glob@~7.0.0:
version "7.0.6"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.0.6.tgz#211bafaf49e525b8cd93260d14ab136152b3f57a"
dependencies:
Expand Down Expand Up @@ -1833,6 +1837,10 @@ jodid25519@^1.0.0:
dependencies:
jsbn "~0.1.0"

js-reporters@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/js-reporters/-/js-reporters-1.1.0.tgz#c83c00fe0d4c9f67f944b4edd5f3b2957497cd62"

js-tokens@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-2.0.0.tgz#79903f5563ee778cc1162e6dcf1a0027c97f9cb5"
Expand Down Expand Up @@ -2002,6 +2010,12 @@ map-obj@^1.0.0, map-obj@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/map-obj/-/map-obj-1.0.1.tgz#d933ceb9205d82bdcf4886f6742bdc2b4dea146d"

matcher-collection@^1.0.0:
version "1.0.4"
resolved "https://registry.yarnpkg.com/matcher-collection/-/matcher-collection-1.0.4.tgz#2f66ae0869996f29e43d0b62c83dd1d43e581755"
dependencies:
minimatch "^3.0.2"

[email protected]:
version "0.3.0"
resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748"
Expand Down Expand Up @@ -2553,16 +2567,16 @@ right-align@^0.1.1:
dependencies:
align-text "^0.1.1"

rimraf@^2.2.8, rimraf@~2.2.8:
version "2.2.8"
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.2.8.tgz#e439be2aaee327321952730f99a8929e4fc50582"

rimraf@^2.5.2:
rimraf@^2.2.8, rimraf@^2.5.2:
version "2.5.4"
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.5.4.tgz#96800093cbf1a0c86bd95b4625467535c29dfa04"
dependencies:
glob "^7.0.5"

rimraf@~2.2.8:
version "2.2.8"
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.2.8.tgz#e439be2aaee327321952730f99a8929e4fc50582"

[email protected]:
version "2.6.1"
resolved "https://registry.yarnpkg.com/rollup-plugin-babel/-/rollup-plugin-babel-2.6.1.tgz#470b03486337045d7e8a3e43fc5fc00e8db82c26"
Expand Down Expand Up @@ -2971,6 +2985,13 @@ [email protected]:
dependencies:
extsprintf "1.0.2"

walk-sync@^0.3.1:
version "0.3.1"
resolved "https://registry.yarnpkg.com/walk-sync/-/walk-sync-0.3.1.tgz#558a16aeac8c0db59c028b73c66f397684ece465"
dependencies:
ensure-posix-path "^1.0.0"
matcher-collection "^1.0.0"

websocket-driver@>=0.5.1:
version "0.6.5"
resolved "https://registry.yarnpkg.com/websocket-driver/-/websocket-driver-0.6.5.tgz#5cb2556ceb85f4373c6d8238aa691c8454e13a36"
Expand Down

0 comments on commit 33b8eba

Please sign in to comment.