UNPKG

3.43 kBtext/coffeescriptView Raw
1# ...
2# requirements
3fs = require 'fs'
4path = require 'path'
5{exec} = require 'child_process'
6fsu = require '../lib/fs-util'
7
8# ...
9# outputting version
10version = fs.readFileSync (path.join __dirname, '../package.json'), 'utf-8'
11console.log '\nCurrent version is: ' + (JSON.parse version).version
12
13# ...
14# defining global watcher var
15base_path = path.join __dirname, 'tmp-tools'
16fs.mkdirSync base_path, '0755'
17
18describe '• FS Tools', ->
19 # ...
20 # 1) cerating new dir with `mkdir_p`
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 # 2) touching file
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 # 3) cp_r
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 # 4) cp
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 # 5) finding with dirs
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 # 6) finding without dirs
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 # 7) updating file
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 # 8) deleting file
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