UNPKG

2.5 kBtext/coffeescriptView Raw
1
2should = require 'should'
3mecano = if process.env.MECANO_COV then require '../lib-cov/mecano' else require '../lib/mecano'
4test = require './test'
5
6describe 'extract', ->
7
8 scratch = test.scratch @
9
10 it 'should see extension .tgz', (next) ->
11 # Test a non existing extracted dir
12 mecano.extract
13 source: "#{__dirname}/../resources/a_dir.tgz"
14 destination: scratch
15 , (err, extracted) ->
16 should.not.exist err
17 extracted.should.eql 1
18 # Test an existing extracted dir
19 # Note, there is no way for us to know which directory
20 # it is in advance
21 mecano.extract
22 source: "#{__dirname}/../resources/a_dir.tgz"
23 destination: scratch
24 , (err, extracted) ->
25 should.not.exist err
26 extracted.should.eql 1
27 next()
28
29 it 'should see extension .zip', (next) ->
30 # Test a non existing extracted dir
31 mecano.extract
32 source: "#{__dirname}/../resources/a_dir.zip"
33 destination: scratch
34 , (err, extracted) ->
35 should.not.exist err
36 extracted.should.eql 1
37 # Test an existing extracted dir
38 # Note, there is no way for us to know which directory
39 # it is in advance
40 mecano.extract
41 source: "#{__dirname}/../resources/a_dir.zip"
42 destination: scratch
43 , (err, extracted) ->
44 should.not.exist err
45 extracted.should.eql 1
46 next()
47
48 it 'should validate a created file', (next) ->
49 # Test with invalid creates option
50 mecano.extract
51 source: "#{__dirname}/../resources/a_dir.tgz"
52 destination: scratch
53 creates: "#{scratch}/oh_no"
54 , (err, extracted) ->
55 err.message.should.eql "Failed to create 'oh_no'"
56 # Test with valid creates option
57 mecano.extract
58 source: "#{__dirname}/../resources/a_dir.tgz"
59 destination: scratch
60 creates: "#{scratch}/a_dir"
61 , (err, extracted) ->
62 should.not.exist err
63 extracted.should.eql 1
64 next()
65
66 it 'should # option # not_if_exists', (next) ->
67 # Test with invalid creates option
68 mecano.extract
69 source: "#{__dirname}/../resources/a_dir.tgz"
70 destination: scratch
71 not_if_exists: __dirname
72 , (err, extracted) ->
73 should.not.exist err
74 extracted.should.eql 0
75 next()
76
77 it 'should # error # extension', (next) ->
78 mecano.extract
79 source: __filename
80 , (err, extracted) ->
81 err.message.should.eql 'Unsupported extension, got ".coffee"'
82 next()
83
84