UNPKG

2.33 kBtext/coffeescriptView Raw
1
2fs = require 'fs'
3path = require 'path'
4fs.exists ?= path.exists
5should = require 'should'
6mecano = if process.env.MECANO_COV then require '../lib-cov/mecano' else require '../lib/mecano'
7test = require './test'
8
9describe 'copy', ->
10
11 scratch = test.scratch @
12
13 it 'should only copy if destination does not exists', (next) ->
14 source = "#{__dirname}/../resources/a_dir/a_file"
15 destination = "#{scratch}/a_new_file"
16 mecano.copy
17 source: source
18 destination: destination
19 , (err, copied) ->
20 should.not.exist err
21 copied.should.eql 1
22 mecano.copy
23 source: source
24 destination: destination
25 , (err, copied) ->
26 should.not.exist err
27 copied.should.eql 0
28 next()
29
30 it 'should always copy with `force` option', (next) ->
31 source = "#{__dirname}/../resources/a_dir/a_file"
32 destination = "#{scratch}/a_new_file"
33 mecano.copy
34 source: source
35 destination: destination
36 , (err, copied) ->
37 should.not.exist err
38 copied.should.eql 1
39 mecano.copy
40 source: source
41 destination: destination
42 force: true
43 , (err, copied) ->
44 should.not.exist err
45 copied.should.eql 1
46 next()
47
48 it 'should copy a file into an existing directory', (next) ->
49 source = "#{__dirname}/../resources/a_dir/a_file"
50 destination = "#{scratch}/"
51 # Copy non existing file
52 mecano.copy
53 source: source
54 destination: destination
55 , (err, copied) ->
56 should.not.exist err
57 copied.should.eql 1
58 fs.exists "#{destination}/a_file", (exists) ->
59 should.ok exists
60 # Copy over existing file
61 mecano.copy
62 source: source
63 destination: destination
64 , (err, copied) ->
65 should.not.exist err
66 copied.should.eql 0
67 next()
68
69 # it 'should copy a directory', (next) ->
70 # source = "#{__dirname}/../resources/a_dir"
71 # destination = "#{__dirname}/a_new_dir"
72 # mecano.copy
73 # source: source
74 # destination: destination
75 # , (err, copied) ->
76 # should.not.exist err
77 # copied.should.eql 1
78 # mecano.copy
79 # source: source
80 # destination: destination
81 # , (err, copied) ->
82 # should.not.exist err
83 # copied.should.eql 0
84 # next()
85
86
87