Skip to content

Commit

Permalink
CLI: Prefer local version of QUnit
Browse files Browse the repository at this point in the history
  • Loading branch information
Trent Willis authored and trentmwillis committed Apr 22, 2017
1 parent 9e8fb1f commit f6dc7f9
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 25 deletions.
29 changes: 29 additions & 0 deletions bin/require-qunit.js
@@ -0,0 +1,29 @@
const resolve = require( "resolve" );

// Depending on the exact usage, QUnit could be in one of several places, this
// function handles finding it.
module.exports = function requireQUnit() {
try {

// First we attempt to find QUnit relative to the current working directory.
const localQUnitPath = resolve.sync( "qunitjs", { basedir: process.cwd() } );
delete require.cache[ localQUnitPath ];
return require( localQUnitPath );
} catch ( e ) {
try {

// Second, we use the globally installed QUnit
delete require.cache[ require.resolve( "../qunit/qunit" ) ];
return require( "../qunit/qunit" );
} catch ( e ) {
if ( e.code === "MODULE_NOT_FOUND" ) {

// Finally, we use the local development version of QUnit
delete require.cache[ require.resolve( "../dist/qunit" ) ];
return require( "../dist/qunit" );
}

throw e;
}
}
};
16 changes: 2 additions & 14 deletions bin/run.js
Expand Up @@ -2,6 +2,7 @@

const path = require( "path" );

const requireQUnit = require( "./require-qunit" );
const utils = require( "./utils" );

const IGNORED_GLOBS = [
Expand All @@ -13,20 +14,7 @@ let QUnit;
function run( args, options ) {
const files = utils.getFilesFromArgs( args );

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

if ( options.filter ) {
QUnit.config.filter = options.filter;
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -34,8 +34,9 @@
"chokidar": "1.6.1",
"commander": "2.9.0",
"exists-stat": "1.0.0",
"findup-sync": "^0.4.3",
"findup-sync": "0.4.3",
"js-reporters": "1.2.0",
"resolve": "1.3.2",
"walk-sync": "0.3.1"
},
"devDependencies": {
Expand Down
30 changes: 20 additions & 10 deletions yarn.lock
Expand Up @@ -1412,7 +1412,7 @@ find-up@^1.0.0:
path-exists "^2.0.0"
pinkie-promise "^2.0.0"

findup-sync@^0.4.3:
findup-sync@0.4.3:
version "0.4.3"
resolved "https://registry.yarnpkg.com/findup-sync/-/findup-sync-0.4.3.tgz#40043929e7bc60adf0b7f4827c4c6e75a0deca12"
dependencies:
Expand Down Expand Up @@ -2200,14 +2200,14 @@ js-tokens@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.1.tgz#08e9f132484a2c45a30907e9dc4d5567b7f114d7"

js-yaml@3.6.1, js-yaml@^3.5.1:
js-yaml@3.6.1, js-yaml@3.x, js-yaml@^3.5.1:
version "3.6.1"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.6.1.tgz#6e5fe67d8b205ce4d22fad05b7781e8dadcc4b30"
dependencies:
argparse "^1.0.7"
esprima "^2.6.0"

js-yaml@3.x, js-yaml@~3.5.2:
js-yaml@~3.5.2:
version "3.5.5"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.5.5.tgz#0377c38017cabc7322b0d1fbcd25a491641f2fbe"
dependencies:
Expand Down Expand Up @@ -2701,6 +2701,10 @@ path-key@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/path-key/-/path-key-2.0.1.tgz#411cadb574c5a140d3a4b1910d40d80cc9f40b40"

path-parse@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.5.tgz#3c1adf871ea9cd6c9431b6ea2bd74a0ff055c4c1"

path-type@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/path-type/-/path-type-1.1.0.tgz#59c44f7ee491da704da415da5a4070ba4f8fe441"
Expand Down Expand Up @@ -3069,6 +3073,12 @@ resolve@1.1.x, resolve@^1.1.6, resolve@~1.1.0:
version "1.1.7"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b"

resolve@1.3.2:
version "1.3.2"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.3.2.tgz#1f0442c9e0cbb8136e87b9305f932f46c7f28235"
dependencies:
path-parse "^1.0.5"

restore-cursor@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/restore-cursor/-/restore-cursor-1.0.1.tgz#34661f46886327fed2991479152252df92daa541"
Expand All @@ -3082,13 +3092,13 @@ right-align@^0.1.1:
dependencies:
align-text "^0.1.1"

rimraf@2, rimraf@^2.2.8, rimraf@^2.5.1, rimraf@^2.5.2, rimraf@^2.6.1:
rimraf@2, rimraf@^2.5.1, rimraf@^2.5.2, rimraf@^2.6.1:
version "2.6.1"
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.1.tgz#c2338ec643df7a1b7fe5c54fa86f57428a55f33d"
dependencies:
glob "^7.0.5"

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

Expand Down Expand Up @@ -3305,14 +3315,14 @@ sshpk@^1.7.0:
jsbn "~0.1.0"
tweetnacl "~0.14.0"

statuses@1, "statuses@>= 1.3.1 < 2", statuses@~1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.3.1.tgz#faf51b9eb74aaef3b3acf4ad5f61abf24cb7b93e"

statuses@~1.2.1:
statuses@1, statuses@~1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.2.1.tgz#dded45cc18256d51ed40aec142489d5c61026d28"

"statuses@>= 1.3.1 < 2", statuses@~1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.3.1.tgz#faf51b9eb74aaef3b3acf4ad5f61abf24cb7b93e"

stream-shift@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/stream-shift/-/stream-shift-1.0.0.tgz#d5c752825e5367e786f78e18e445ea223a155952"
Expand Down

0 comments on commit f6dc7f9

Please sign in to comment.