Skip to content

Commit

Permalink
Add test for dir.clean()
Browse files Browse the repository at this point in the history
  • Loading branch information
Alfiana Sibuea committed Sep 6, 2014
1 parent 6bb1cf6 commit 984cd85
Showing 1 changed file with 33 additions and 14 deletions.
47 changes: 33 additions & 14 deletions test/testDir.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

var lodash = require('lodash');
var path = require('path');
var fs = require('fs-extra');
var assert = require('assert');
var utils = require('./utils.js');

Expand All @@ -21,24 +22,24 @@ var dir = require('../src/dir.js');
* /level-2
* - two.html
*/
function createFiles() {
// Create fake directory and files
var listFile = [
'./zero.html',
'./three.html',
'./level-1/one.html',
'./level-1/level-2/two.html'
];

lodash.forEach(listFile, function(file) {
utils.createFile(file, 'test');
});
}

describe('Compiler Module:', function() {

beforeEach(function(done) {
utils.createContainer(function() {

// Create fake directory and files
var listFile = [
'./zero.html',
'./three.html',
'./level-1/one.html',
'./level-1/level-2/two.html'
];

lodash.forEach(listFile, function(file) {
utils.createFile(file, 'test');
});

return done();
});
});
Expand All @@ -49,10 +50,12 @@ describe('Compiler Module:', function() {
});
});

describe('getFileList() test', function() {
describe('fileList() test', function() {

it('should return list of file based on source dir', function(done) {

createFiles();

dir.fileList('./', [], function(files) {
assert.deepEqual(files, [
'level-1/level-2/two.html',
Expand All @@ -67,6 +70,8 @@ describe('Compiler Module:', function() {

it('should return list of file based on source dir and also ignore list', function(done) {

createFiles();

dir.fileList('./', ['./level-1/**/*'], function(files) {
assert.deepEqual(files, [
'three.html',
Expand All @@ -79,4 +84,18 @@ describe('Compiler Module:', function() {

});

describe('clean() test', function() {

it('should be clean all files inside the folder', function() {

createFiles();
var dirPath = process.cwd();

dir.clean(dirPath);

assert.deepEqual([], fs.readdirSync(dirPath));
});

});

});

0 comments on commit 984cd85

Please sign in to comment.