Skip to content

Commit 4efc02a

Browse files
committed
test: fix test-fs-symlink-dir-junction-relative
* The test no longer relies on being invoked from a particular working directory to function properly. * fs.symlink() and fs.symlinkSync() are both tested. * The test now cleans up after itself. This commit fixes #126 PR-URL: #129 Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 8e272df commit 4efc02a

File tree

1 file changed

+30
-32
lines changed

1 file changed

+30
-32
lines changed

test/simple/test-fs-symlink-dir-junction-relative.js

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,50 +19,48 @@
1919
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
2020
// USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

22+
// Test creating and resolving relative junction or symbolic link
23+
2224
var common = require('../common');
2325
var assert = require('assert');
2426
var path = require('path');
2527
var fs = require('fs');
2628
var completed = 0;
27-
var expected_tests = 4;
28-
29-
// test creating and reading symbolic link
30-
var linkData = path.join(common.fixturesDir, 'cycles');
31-
var linkPath = path.join(common.tmpDir, 'cycles_link');
32-
var relative = '../fixtures/cycles';
29+
var expected_tests = 2;
3330

34-
// Delete previously created link
35-
try {
36-
fs.unlinkSync(linkPath);
37-
} catch (e) {}
31+
var linkPath1 = path.join(common.tmpDir, 'junction1');
32+
var linkPath2 = path.join(common.tmpDir, 'junction2');
33+
var linkTarget = path.join(common.fixturesDir);
34+
var linkData = '../fixtures';
3835

39-
console.log('linkData: ' + linkData);
40-
console.log('linkPath: ' + linkPath);
41-
console.log('relative target: ' + relative)
36+
// Prepare.
37+
try { fs.mkdirSync(common.tmpDir); } catch (e) {}
38+
try { fs.unlinkSync(linkPath1); } catch (e) {}
39+
try { fs.unlinkSync(linkPath2); } catch (e) {}
4240

43-
fs.symlink(relative, linkPath, 'junction', function(err) {
41+
// Test fs.symlink()
42+
fs.symlink(linkData, linkPath1, 'junction', function(err) {
4443
if (err) throw err;
45-
completed++;
44+
verifyLink(linkPath1);
45+
});
4646

47-
fs.lstat(linkPath, function(err, stats) {
48-
if (err) throw err;
49-
assert.ok(stats.isSymbolicLink());
50-
completed++;
47+
// Test fs.symlinkSync()
48+
fs.symlinkSync(linkData, linkPath2, 'junction');
49+
verifyLink(linkPath2);
5150

52-
fs.readlink(linkPath, function(err, destination) {
53-
if (err) throw err;
54-
assert.equal(path.resolve(destination), linkData);
55-
completed++;
51+
function verifyLink(linkPath) {
52+
var stats = fs.lstatSync(linkPath);
53+
assert.ok(stats.isSymbolicLink());
5654

57-
fs.unlink(linkPath, function(err) {
58-
if (err) throw err;
59-
assert(!fs.existsSync(linkPath));
60-
assert(fs.existsSync(linkData));
61-
completed++;
62-
});
63-
});
64-
});
65-
});
55+
var data1 = fs.readFileSync(linkPath + '/x.txt', 'ascii');
56+
var data2 = fs.readFileSync(linkTarget + '/x.txt', 'ascii');
57+
assert.strictEqual(data1, data2);
58+
59+
// Clean up.
60+
fs.unlinkSync(linkPath);
61+
62+
completed++;
63+
}
6664

6765
process.on('exit', function() {
6866
assert.equal(completed, expected_tests);

0 commit comments

Comments
 (0)