Skip to content

Commit

Permalink
CLI: Avoid directory scanning for arguments that are known files
Browse files Browse the repository at this point in the history
Check if the argument is path to a simple known file, if so do not
traverse the entire folder for that glob only to find self.

Closes #1385.

Co-authored-by: Robert Jackson <[email protected]>
  • Loading branch information
2 people authored and Krinkle committed Jul 30, 2020
1 parent 93e7edd commit 194fa05
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
22 changes: 16 additions & 6 deletions src/cli/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,36 @@ function findFiles( baseDir, options ) {
}

function getFilesFromArgs( args ) {
let globs = args.slice();
const globs = args.slice();

// Default to files in the test directory
if ( !globs.length ) {
globs.push( "test/**/*.js" );
}

const files = [];
const filteredGlobs = [];

// For each of the potential globs, we check if it is a directory path and
// update it so that it matches the JS files in that directory.
globs = globs.map( glob => {
globs.forEach( glob => {
const stat = existsStat( glob );

if ( stat && stat.isDirectory() ) {
return `${glob}/**/*.js`;
if ( stat && stat.isFile() ) {

// Remember known files to avoid (slow) directory-wide glob scanning.
// https://github.com/qunitjs/qunit/pull/1385
files.push( glob );
} else if ( stat && stat.isDirectory() ) {
filteredGlobs.push( `${glob}/**/*.js` );
} else {
return glob;
filteredGlobs.push( glob );
}
} );

const files = findFiles( process.cwd(), { match: globs } );
if ( filteredGlobs.length ) {
files.push.apply( files, findFiles( process.cwd(), { match: filteredGlobs } ) );
}

if ( !files.length ) {
error( "No files were found matching: " + args.join( ", " ) );
Expand Down
18 changes: 9 additions & 9 deletions test/cli/fixtures/expected/tap-outputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ ok 1 Single > has a test

"qunit single.js double.js":
`TAP version 13
ok 1 Double > has a test
ok 2 Double > has another test
ok 3 Single > has a test
ok 1 Single > has a test
ok 2 Double > has a test
ok 3 Double > has another test
1..3
# pass 3
# skip 0
Expand Down Expand Up @@ -71,9 +71,9 @@ not ok 1 Throws match > bad

"qunit test single.js 'glob/**/*-test.js'":
`TAP version 13
ok 1 A-Test > derp
ok 2 Nested-Test > herp
ok 3 Single > has a test
ok 1 Single > has a test
ok 2 A-Test > derp
ok 3 Nested-Test > herp
ok 4 First > 1
ok 5 Second > 1
1..5
Expand All @@ -85,10 +85,10 @@ ok 5 Second > 1
"qunit --seed 's33d' test single.js 'glob/**/*-test.js'": `Running tests with seed: s33d
TAP version 13
ok 1 Second > 1
ok 2 Single > has a test
ok 2 Nested-Test > herp
ok 3 First > 1
ok 4 Nested-Test > herp
ok 5 A-Test > derp
ok 4 A-Test > derp
ok 5 Single > has a test
1..5
# pass 5
# skip 0
Expand Down

0 comments on commit 194fa05

Please sign in to comment.