-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3723 from livankrekh/development
Add directory support for --ignore-watch, fixed --ignore-watch, implemented test and implemented flag --watch-delay
- Loading branch information
Showing
6 changed files
with
128 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
var fs = require('fs'); | ||
|
||
function handleFolders(folder, mas) { | ||
if (!folder || !mas || folder.indexOf("node_modules") !== -1) | ||
return ; | ||
|
||
try { | ||
fs.accessSync(folder, fs.constants.R_OK); | ||
} catch (err) { | ||
return ; | ||
} | ||
|
||
if (fs.statSync(folder) && fs.statSync(folder).isDirectory()) { | ||
fs.readdirSync(folder).forEach(file => { | ||
if (fs.statSync(folder)["mode"] & 4 === 0) | ||
return ; | ||
if (fs.existsSync(folder + file + '/')) | ||
handleFolders(folder + file + '/', mas); | ||
else | ||
mas.push(folder + file); | ||
}); | ||
} else { | ||
if (fs.statSync(folder).isFile()) { | ||
mas.push(folder); | ||
} | ||
} | ||
} | ||
|
||
module.exports.handleFolders = handleFolders; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
|
||
var should = require('should'); | ||
var f_w = require('../../lib/API/Modules/flagWatch.js'); | ||
var fs = require('fs'); | ||
|
||
describe('Flag --ignore-watch', function() { | ||
|
||
it('should return not empty result', function() { | ||
var res = []; | ||
f_w.handleFolders('./', res); | ||
should(res).be.not.empty(); | ||
}); | ||
it('should not crash', function() { | ||
var res = [] | ||
f_w.handleFolders(); | ||
f_w.handleFolders(res); | ||
f_w.handleFolders(''); | ||
f_w.handleFolders('lsdldmcsdf/amfkdmfk'); | ||
}); | ||
it('should give different results', function() { | ||
var tmp_res = []; | ||
var res = []; | ||
f_w.handleFolders('./lib', res); | ||
f_w.handleFolders('./examples', tmp_res); | ||
should(res).not.equal(tmp_res); | ||
}); | ||
it('should not crash in case, when no access for file or directory by permissions', function() { | ||
var fileStream; | ||
|
||
if (!fs.existsSync("noAccessDir")) | ||
fs.mkdirSync("noAccessDir", 0777); | ||
if (!fs.existsSync("noAccessDir/checkPermissions.txt")) { | ||
fileStream = fs.createWriteStream("noAccessDir/checkPermissions.txt"); | ||
fileStream.write("It's a temporary file for testing flag --ignore-watch in PM2"); | ||
fileStream.end(); | ||
} | ||
fs.chmodSync('noAccessDir/checkPermissions.txt', 0000); | ||
fs.chmodSync('noAccessDir', 0000); | ||
|
||
after(function () { | ||
fs.chmodSync('noAccessDir', 0777); | ||
fs.chmodSync('noAccessDir/checkPermissions.txt', 0777); | ||
fs.unlinkSync('noAccessDir/checkPermissions.txt'); | ||
fs.rmdirSync('noAccessDir/'); | ||
}); | ||
|
||
f_w.handleFolders('noAccessDir/', []); | ||
f_w.handleFolders('noAccessDir/checkPermissions.txt', []); | ||
}); | ||
it('should ignore node_modules folder', function() { | ||
var res = []; | ||
f_w.handleFolders('./node_modules', res); | ||
should(res).be.empty(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters