1 |
|
2 |
|
3 | fs = require 'fs'
|
4 | path = require 'path'
|
5 | {exec} = require 'child_process'
|
6 | fsu = require '../lib/fs-util'
|
7 |
|
8 |
|
9 |
|
10 | version = fs.readFileSync (path.join __dirname, '../package.json'), 'utf-8'
|
11 | console.log '\nCurrent version is: ' + (JSON.parse version).version
|
12 |
|
13 |
|
14 |
|
15 | base_path = path.join __dirname, 'tmp-tools'
|
16 | fs.mkdirSync base_path, '0755'
|
17 |
|
18 | describe '• FS Tools', ->
|
19 |
|
20 |
|
21 | describe 'When making a deep-dir structure', ->
|
22 | it 'the structure must to be created', ->
|
23 | fullpath = path.join base_path, 'created/a/b/c'
|
24 | fsu.mkdir_p fullpath
|
25 | (fs.existsSync fullpath).should.equal true
|
26 |
|
27 |
|
28 |
|
29 | describe 'When touching a file', ->
|
30 | it 'the file must be touched', ->
|
31 | fullpath = path.join base_path, 'created/a/b/c/tempfile.coffee'
|
32 | fsu.touch fullpath
|
33 | (fs.readFileSync fullpath).toString().should.equal ''
|
34 |
|
35 |
|
36 |
|
37 | describe 'When copying a structure', ->
|
38 | it 'the structure must to be copied', ->
|
39 | from = path.join base_path, 'created'
|
40 | to = path.join base_path, 'copied'
|
41 | fsu.cp_r from, to
|
42 | filepath = path.join base_path, 'copied/a/b/c/tempfile.coffee'
|
43 | (fs.existsSync filepath).should.equal true
|
44 | (fs.statSync filepath).isFile().should.equal true
|
45 | (fs.readFileSync filepath).toString().should.equal ''
|
46 |
|
47 |
|
48 | describe 'When copying a single file', ->
|
49 | it 'the file must to be copied', ->
|
50 | from = path.join base_path, 'created/a/b/c/tempfile.coffee'
|
51 | to = path.join base_path, 'created/a/b/c/tempfile-copy.coffee'
|
52 | fsu.cp from, to
|
53 | filepath = path.join base_path, 'created/a/b/c/tempfile-copy.coffee'
|
54 | (fs.existsSync filepath).should.equal true
|
55 | (fs.statSync filepath).isFile().should.equal true
|
56 | (fs.readFileSync filepath).toString().should.equal ''
|
57 | (fs.unlinkSync filepath)
|
58 |
|
59 |
|
60 |
|
61 | describe 'When searching a file', ->
|
62 | it 'the search must to return the proper results', ->
|
63 | found = fsu.find path.join base_path, /.coffee$/m, true
|
64 | check = [
|
65 | a = (path.join base_path, 'created/a/b/c/tempfile.coffee'),
|
66 | b = (path.join base_path, 'copied/a/b/c/tempfile.coffee')
|
67 | ]
|
68 | (found[0] is a or found[0] is b).should.equal true
|
69 | (found[1] is a or found[1] is b).should.equal true
|
70 |
|
71 |
|
72 |
|
73 | describe 'When searching a directory', ->
|
74 | it 'the search must to return the proper results', ->
|
75 | check = [
|
76 | a = (path.join base_path, 'created/a/b/c/tempfile.coffee'),
|
77 | b = (path.join base_path, 'copied/a/b/c/tempfile.coffee')
|
78 | ]
|
79 | found = fsu.find path.join base_path, /c*/m, false
|
80 | (found[0] is a or found[0] is b).should.equal true
|
81 | (found[1] is a or found[1] is b).should.equal true
|
82 |
|
83 |
|
84 |
|
85 | describe 'When listing a directory', ->
|
86 | it 'the list must to return the dir contents', ->
|
87 | fullpath = path.join base_path, 'copied'
|
88 | res = fsu.ls fullpath
|
89 | res.length.should.equal 1
|
90 | res[0].should.equal (path.join fullpath, 'a')
|
91 |
|
92 |
|
93 |
|
94 | describe 'When removing a strucuture recursively', ->
|
95 | it 'the structure must to removed recursively', ->
|
96 | fullpath = path.join base_path, 'copied'
|
97 | fsu.rm_rf fullpath
|
98 | (fs.existsSync fullpath).should.equal false |
\ | No newline at end of file |