Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #699 Replacing var with let/const and adding strict mode #706

Merged
merged 3 commits into from
Jan 31, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 41 additions & 40 deletions tests/spec/path-resolution.spec.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
var Filer = require('../../src');
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
'use strict';
const Filer = require('../../src');
const util = require('../lib/test-utils.js');
const expect = require('chai').expect;

// Support global URL and node's url module
var URL = global.URL || require('url').URL;
const URL = global.URL || require('url').URL;

describe('path resolution', function() {
beforeEach(util.setup);
afterEach(util.cleanup);

it('should follow a symbolic link to the root directory', function(done) {
var fs = util.fs();
const fs = util.fs();

fs.symlink('/', '/mydirectorylink', function(error) {
if(error) throw error;
Expand All @@ -19,7 +20,7 @@ describe('path resolution', function() {
if(error) throw error;

expect(result['node']).to.exist;
var _node = result['node'];
const _node = result['node'];

fs.stat('/mydirectorylink', function(error, result) {
expect(error).not.to.exist;
Expand All @@ -32,7 +33,7 @@ describe('path resolution', function() {
});

it('should follow a symbolic link to a directory', function(done) {
var fs = util.fs();
const fs = util.fs();

fs.mkdir('/mydir', function(error) {
if(error) throw error;
Expand All @@ -44,7 +45,7 @@ describe('path resolution', function() {
if(error) throw error;

expect(result['node']).to.exist;
var _node = result['node'];
const _node = result['node'];
fs.stat('/mydirectorylink', function(error, result) {
expect(error).not.to.exist;
expect(result).to.exist;
Expand All @@ -57,18 +58,18 @@ describe('path resolution', function() {
});

it('should follow a symbolic link to a file', function(done) {
var fs = util.fs();
const fs = util.fs();

fs.open('/myfile', 'w', function(error, result) {
if(error) throw error;
var fd = result;
const fd = result;
fs.close(fd, function(error) {
if(error) throw error;
fs.stat('/myfile', function(error, result) {
if(error) throw error;

expect(result['node']).to.exist;
var _node = result['node'];
const _node = result['node'];
fs.symlink('/myfile', '/myfilelink', function(error) {
if(error) throw error;

Expand All @@ -85,18 +86,18 @@ describe('path resolution', function() {
});

it('should follow multiple symbolic links to a file', function(done) {
var fs = util.fs();
const fs = util.fs();

fs.open('/myfile', 'w', function(error, result) {
if(error) throw error;
var fd = result;
const fd = result;
fs.close(fd, function(error) {
if(error) throw error;
fs.stat('/myfile', function(error, result) {
if(error) throw error;

expect(result['node']).to.exist;
var _node = result['node'];
const _node = result['node'];
fs.symlink('/myfile', '/myfilelink1', function(error) {
if(error) throw error;
fs.symlink('/myfilelink1', '/myfilelink2', function(error) {
Expand All @@ -116,7 +117,7 @@ describe('path resolution', function() {
});

it('should error if symbolic link leads to itself', function(done) {
var fs = util.fs();
const fs = util.fs();

fs.symlink('/mylink1', '/mylink2', function(error) {
if(error) throw error;
Expand All @@ -135,8 +136,8 @@ describe('path resolution', function() {
});

it('should error if it follows more than 10 symbolic links', function(done) {
var fs = util.fs();
var nlinks = 11;
const fs = util.fs();
const nlinks = 11;

function createSymlinkChain(n, callback) {
if(n > nlinks) {
Expand All @@ -148,7 +149,7 @@ describe('path resolution', function() {

fs.open('/myfile0', 'w', function(error, result) {
if(error) throw error;
var fd = result;
const fd = result;
fs.close(fd, function(error) {
if(error) throw error;
fs.stat('/myfile0', function(error, result) {
Expand All @@ -170,17 +171,17 @@ describe('path resolution', function() {
});

it('should follow a symbolic link in the path to a file', function(done) {
var fs = util.fs();
const fs = util.fs();

fs.open('/myfile', 'w', function(error, result) {
if(error) throw error;
var fd = result;
const fd = result;
fs.close(fd, function(error) {
if(error) throw error;
fs.stat('/myfile', function(error, result) {
if(error) throw error;

var _node = result['node'];
const _node = result['node'];
fs.symlink('/', '/mydirlink', function(error) {
if(error) throw error;

Expand All @@ -198,11 +199,11 @@ describe('path resolution', function() {
});

it('should error if a symbolic link in the path to a file is itself a file', function(done) {
var fs = util.fs();
const fs = util.fs();

fs.open('/myfile', 'w', function(error, result) {
if(error) throw error;
var fd = result;
const fd = result;
fs.close(fd, function(error) {
if(error) throw error;
fs.stat('/myfile', function(error, result) {
Expand All @@ -211,7 +212,7 @@ describe('path resolution', function() {

fs.open('/myfile2', 'w', function(error, result) {
if(error) throw error;
var fd = result;
const fd = result;
fs.close(fd, function(error) {
if(error) throw error;
fs.symlink('/myfile2', '/mynotdirlink', function(error) {
Expand All @@ -232,7 +233,7 @@ describe('path resolution', function() {
});

it('should properly add trailing slashes with Path.addTrailing()', function() {
var Path = Filer.Path;
const Path = Filer.Path;
expect(Path.addTrailing('/')).to.equal('/');
expect(Path.addTrailing('/////')).to.equal('/');
expect(Path.addTrailing('.')).to.equal('./');
Expand All @@ -241,7 +242,7 @@ describe('path resolution', function() {
});

it('should properly remove trailing slashes with Path.removeTrailing()', function() {
var Path = Filer.Path;
const Path = Filer.Path;
expect(Path.removeTrailing('/')).to.equal('/');
expect(Path.removeTrailing('/////')).to.equal('/');
expect(Path.removeTrailing('./')).to.equal('.');
Expand All @@ -250,10 +251,10 @@ describe('path resolution', function() {
});

it('should allow using Buffer for paths', function(done) {
var fs = util.fs();
var filePath = '/file';
var bufferPath = Buffer.from(filePath);
var data = 'data';
const fs = util.fs();
const filePath = '/file';
const bufferPath = Buffer.from(filePath);
const data = 'data';

fs.writeFile(bufferPath, data, function(err) {
if(err) throw err;
Expand All @@ -267,10 +268,10 @@ describe('path resolution', function() {
});

it('should allow using file: URLs for paths', function(done) {
var fs = util.fs();
var filePath = '/file';
var fileUrl = new URL(`file://${filePath}`);
var data = 'data';
const fs = util.fs();
const filePath = '/file';
const fileUrl = new URL(`file://${filePath}`);
const data = 'data';

fs.writeFile(fileUrl, data, function(err) {
if(err) throw err;
Expand All @@ -284,16 +285,16 @@ describe('path resolution', function() {
});

it('should error for non file: URLs for paths', function() {
var fs = util.fs();
var fileUrl = new URL('http://file');
var fn = () => fs.writeFile(fileUrl, 1);
const fs = util.fs();
const fileUrl = new URL('http://file');
const fn = () => fs.writeFile(fileUrl, 1);
expect(fn).to.throw();
});

it('should error if file: URLs include escaped / characters', function() {
var fs = util.fs();
var fileUrl = new URL('file:///p/a/t/h/%2F');
var fn = () => fs.writeFile(fileUrl, 1);
const fs = util.fs();
const fileUrl = new URL('file:///p/a/t/h/%2F');
const fn = () => fs.writeFile(fileUrl, 1);
expect(fn).to.throw();
});
});