From f0535dca0fb8ef40b2fa78d3c606080d8c3f998b Mon Sep 17 00:00:00 2001 From: Jonathan Wilsson Date: Sat, 28 Jan 2017 15:17:10 +0100 Subject: [PATCH] Add a few Lesshint fs tests --- test/specs/lesshint.js | 53 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/test/specs/lesshint.js b/test/specs/lesshint.js index e9d196d5..8b1172b3 100644 --- a/test/specs/lesshint.js +++ b/test/specs/lesshint.js @@ -1,7 +1,9 @@ 'use strict'; const expect = require('chai').expect; +const rimraf = require('rimraf'); const path = require('path'); +const fs = require('fs'); describe('lesshint', function () { const testDir = path.join(path.dirname(__dirname), '/data/files'); @@ -110,6 +112,23 @@ describe('lesshint', function () { expect(result).to.have.length(3); }); }); + + it('should reject on inaccessible paths', function () { + const lesshint = new Lesshint(); + + lesshint.configure(); + + const filePath = testDir + '/tmp.less'; + + fs.writeFileSync(filePath, ''); + fs.chmodSync(filePath, 222); // Don't allow read access + + return lesshint.checkDirectory(filePath).catch(function (err) { + expect(err).to.be.an.instanceof(Error); + + rimraf(filePath, function () {}); + }); + }); }); describe('checkFile', function () { @@ -122,6 +141,23 @@ describe('lesshint', function () { expect(result).to.have.length(1); }); }); + + it('should reject on inaccessible files', function () { + const lesshint = new Lesshint(); + + lesshint.configure(); + + const filePath = testDir + '/tmp.less'; + + fs.writeFileSync(filePath, ''); + fs.chmodSync(filePath, 222); // Don't allow read access + + return lesshint.checkFile(filePath).catch(function (err) { + expect(err).to.be.an.instanceof(Error); + + rimraf(filePath, function () {}); + }); + }); }); describe('checkPath', function () { @@ -162,6 +198,23 @@ describe('lesshint', function () { expect(result).to.have.length(0); }); }); + + it('should reject on inaccessible paths', function () { + const lesshint = new Lesshint(); + + lesshint.configure(); + + const filePath = testDir + '/tmp.less'; + + fs.writeFileSync(filePath, ''); + fs.chmodSync(filePath, 222); // Don't allow read access + + return lesshint.checkPath(filePath).catch(function (err) { + expect(err).to.be.an.instanceof(Error); + + rimraf(filePath, function () {}); + }); + }); }); describe('checkString', function () {