UNPKG

2.53 kBtext/coffeescriptView Raw
1
2fs = require 'fs'
3should = require 'should'
4mecano = if process.env.MECANO_COV then require '../lib-cov/mecano' else require '../lib/mecano'
5test = require './test'
6
7describe 'link', ->
8
9 scratch = test.scratch @
10
11 it 'should link file', (next) ->
12 # Create a non existing link
13 destination = "#{scratch}/link_test"
14 mecano.link
15 source: __filename
16 destination: destination
17 , (err, linked) ->
18 should.not.exist err
19 linked.should.eql 1
20 # Create on an existing link
21 mecano.link
22 source: __filename
23 destination: destination
24 , (err, linked) ->
25 should.not.exist err
26 linked.should.eql 0
27 fs.lstat destination, (err, stat) ->
28 stat.isSymbolicLink().should.be.ok
29 next()
30
31 it 'should link dir', (next) ->
32 # Create a non existing link
33 destination = "#{scratch}/link_test"
34 mecano.link
35 source: __dirname
36 destination: destination
37 , (err, linked) ->
38 should.not.exist err
39 linked.should.eql 1
40 # Create on an existing link
41 mecano.link
42 source: __dirname
43 destination: destination
44 , (err, linked) ->
45 should.not.exist err
46 linked.should.eql 0
47 fs.lstat destination, (err, stat) ->
48 stat.isSymbolicLink().should.be.ok
49 next()
50
51 it 'should create parent directories', (next) ->
52 # Create a non existing link
53 destination = "#{scratch}/test/dir/link_test"
54 mecano.link
55 source: __dirname
56 destination: destination
57 , (err, linked) ->
58 should.not.exist err
59 linked.should.eql 1
60 fs.lstat destination, (err, stat) ->
61 stat.isSymbolicLink().should.be.ok
62 # Test creating two identical parent dirs
63 destination = "#{scratch}/test/dir2"
64 mecano.link [
65 source: "#{__dirname}/merge.coffee"
66 destination: "#{destination}/merge.coffee"
67 ,
68 source: "#{__dirname}/mkdir.coffee"
69 destination: "#{destination}/mkdir.coffee"
70 ], (err, linked) ->
71 should.not.exist err
72 linked.should.eql 2
73 next()
74
75 it 'should validate arguments', (next) ->
76 # Test missing source
77 mecano.link
78 destination: __filename
79 , (err, linked) ->
80 err.message.should.eql "Missing source, got undefined"
81 # Test missing destination
82 mecano.link
83 source: __filename
84 , (err, linked) ->
85 err.message.should.eql "Missing destination, got undefined"
86 next()
87
88
89
90
91
92