/
filesystem.js
48 lines (39 loc) · 1.52 KB
/
filesystem.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'use strict';
var assert = require('assert');
var fs = require('fs');
var filesystem = require('../src/filesystem');
describe('Filesystem', function () {
describe('#walkSync', function () {
it('Should return an array of files found in directory', function () {
var arr = [
'tmp/file1.js',
'tmp/test/file2.js'
];
fs.mkdirSync('tmp');
fs.mkdirSync('tmp/test');
fs.writeFileSync('tmp/file1.js', '');
fs.writeFileSync('tmp/test/file2.js', '');
assert.deepEqual(arr, filesystem.walkSync('tmp'));
fs.unlinkSync('tmp/test/file2.js');
fs.unlinkSync('tmp/file1.js');
fs.rmdirSync('tmp/test');
fs.rmdirSync('tmp');
});
});
describe('#removeDirectoryContents', function () {
it('Should remove all files and folders from directory', function () {
fs.mkdirSync('tmp');
fs.mkdirSync('tmp/test1');
fs.mkdirSync('tmp/test2');
fs.writeFileSync('tmp/test1/file.js', '');
fs.writeFileSync('tmp/test2/file.js', '');
filesystem.removeDirectoryContents('tmp/test1', function() {
assert.deepEqual(fs.readdirSync('tmp/test1').length, 0);
filesystem.removeDirectoryContents('tmp/', function() {
assert.deepEqual(fs.readdirSync('tmp').length, 0);
fs.rmdirSync('tmp');
});
});
});
});
});