UNPKG

savvy-js

Version:

Savvy - Style sheet documentation tool

77 lines (62 loc) 2.5 kB
(function(){ 'use strict'; var fs = require('fs'), Minimatch = require('minimatch').Minimatch, should = require('chai').should(), rimraf = require('rimraf'), fileReader = require('../js/fileReader'), folderPath = 'c:/myVerySpecialTestFolderThatPropbablyDoesntExsist', fileNames = ['a.scss', 'b.scss', 'c.css']; beforeEach(function(done){ // create a temp directory fs.mkdir(folderPath, function(){ fileNames.forEach(function(filePath){ fs.writeFileSync(folderPath + '/' + filePath, '123 test'); }); done(); }); }); afterEach(function(done){ // remove folder and files. rimraf(folderPath, done); }); describe('fileReader', function() { it('Can match a file path to a pattern and filter unwanted paths', function(){ var pattern, result; // match only js files pattern = new Minimatch('*.js', { matchBase: true }) result = fileReader.matchPattern(pattern, ['/myFile.js', 'C:/someOtherFile.css']); result.length.should.equal(1); result[0].should.equal('/myFile.js'); // match everything except js files. pattern = new Minimatch('!*.js', { matchBase: true }) result = fileReader.matchPattern(pattern, ['/myFile.js', 'C:/someOtherFile.css']); result.length.should.equal(1); result[0].should.equal('C:/someOtherFile.css'); }); it('getFiles() works on all files in a given single folder, if no pattern is provided.', function (done) { var callback; callback = function(err, files){ if(err){ return done(err); } files.length.should.equal(3); done(); }; fileReader.getFiles(folderPath, callback); }); it('getFiles() gets files by given pattern.', function (done) { var callback, pattern; callback = function(err, files){ if(err){ return done(err); } files.length.should.equal(2); done(); }; pattern = '*.scss'; fileReader.getFiles(folderPath, callback, pattern); }); }); }());