Skip to content

Commit

Permalink
Ignore all those folders mentioned in the gitignore.
Browse files Browse the repository at this point in the history
1) ignore node_modules and .git folder always
2) Added test for new function
  • Loading branch information
sparshithNR committed Mar 15, 2019
1 parent 7ffd0e3 commit 7309106
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/cli/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ const requireQUnit = require( "./require-qunit" );
const utils = require( "./utils" );

const IGNORED_GLOBS = [
"**/node_modules/**"
".git",
"node_modules"
];

const RESTART_DEBOUNCE_LENGTH = 200;

let QUnit;
Expand All @@ -18,6 +20,11 @@ function run( args, options ) {
// Default to non-zero exit code to avoid false positives
process.exitCode = 1;

// Do not push content of .gitignore everytime when run is called
if ( IGNORED_GLOBS.length === 2 ) {
IGNORED_GLOBS.push.apply( IGNORED_GLOBS, utils.getIgnoreList( process.cwd() ) );
}

const files = utils.getFilesFromArgs( args );

QUnit = requireQUnit();
Expand Down
13 changes: 12 additions & 1 deletion src/cli/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ function existsStat() {
}
}


function getIgnoreList( baseDir ) {
if ( fs.existsSync( `${baseDir}/.gitignore` ) ) {
let gitIgnore = fs.readFileSync( `${baseDir}/.gitignore`, "utf-8" );
gitIgnore = gitIgnore.trim();
return gitIgnore.split( "\n" );
}
return [];
}

function findFilesInternal( dir, options, result = [], prefix = "" ) {
fs.readdirSync( dir ).forEach( ( name ) => {
const fullName = path.join( dir, name );
Expand Down Expand Up @@ -85,5 +95,6 @@ module.exports = {
findFiles,
capitalize,
error,
getFilesFromArgs
getFilesFromArgs,
getIgnoreList
};
8 changes: 8 additions & 0 deletions test/cli/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const { getIgnoreList } = require( "../../src/cli/utils" );

QUnit.module( "getIgnoreList", function() {
QUnit.test( "reads getIgnoreList", function( assert ) {
const ignoreList = getIgnoreList( `${process.cwd()}` );
assert.deepEqual( ignoreList, [ "dist", "node_modules", "build/report", "browserstack-run.pid", "temp/", "docs/_site/" ] );
} );
} );

0 comments on commit 7309106

Please sign in to comment.