Skip to content

Commit

Permalink
Merge pull request #135 from MasterOdin/matt-test-recursive-mkdir
Browse files Browse the repository at this point in the history
Add test around recursively making socket directory
  • Loading branch information
eriktrom committed Aug 3, 2022
2 parents 27cbfc8 + 652d41a commit 0795f6f
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions test/port-finder-socket-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,15 @@ function stopServers(callback, index) {
}

function cleanup(callback) {
fs.rmdirSync(badDir);
if (fs.existsSync(path.join(badDir, 'deeply', 'nested'))) {
fs.rmdirSync(path.join(badDir, 'deeply', 'nested'));
}
if (fs.existsSync(path.join(badDir, 'deeply'))) {
fs.rmdirSync(path.join(badDir, 'deeply'));
}
if (fs.existsSync(badDir)) {
fs.rmdirSync(badDir);
}
stopServers(callback, 0);
}

Expand All @@ -81,7 +89,7 @@ vows.describe('portfinder').addBatch({
}, this.callback);
}.bind(this));
},
"the getPort() method": {
"the getSocket() method": {
topic: function () {
portfinder.getSocket({
path: path.join(socketDir, 'test.sock')
Expand All @@ -98,7 +106,7 @@ vows.describe('portfinder').addBatch({
"When using portfinder module": {
"with no existing servers": {
"the getSocket() method": {
"with a directory that doesnt exist": {
"with a directory that doesn't exist": {
topic: function () {
fs.rmdir(badDir, function () {
portfinder.getSocket({
Expand All @@ -111,6 +119,24 @@ vows.describe('portfinder').addBatch({
assert.equal(socket, path.join(badDir, 'test.sock'));
}
},
"with a nested directory that doesn't exist": {
topic: function () {
var that = this;
fs.rmdir(path.join(badDir, 'deeply', 'nested'), function () {
fs.rmdir(path.join(badDir, 'deeply'), function () {
fs.rmdir(badDir, function () {
portfinder.getSocket({
path: path.join(badDir, 'deeply', 'nested', 'test.sock')
}, that.callback);
});
});
});
},
"should respond with the first free socket (test.sock)": function (err, socket) {
assert.isTrue(!err);
assert.equal(socket, path.join(badDir, 'deeply', 'nested', 'test.sock'));
}
},
"with a directory that exists": {
topic: function () {
portfinder.getSocket({
Expand Down

0 comments on commit 0795f6f

Please sign in to comment.