1 | describe 'building', ->
|
2 |
|
3 | dummyExec = undefined
|
4 | beforeEach ->
|
5 | dummyExec =
|
6 | MULTI: -> ->
|
7 | pack.build()
|
8 |
|
9 | it 'should use flow', ->
|
10 | expect(stub.stubs.flow.exec).toHaveBeenCalled()
|
11 |
|
12 | describe 'first flow action', ->
|
13 |
|
14 | describe 'with include_depends', ->
|
15 |
|
16 | beforeEach ->
|
17 | pack.httpGet = jasmine.createSpy 'http.get'
|
18 | pack.opts.include_depends = yes
|
19 | stub.stubs.flow.exec.calls[0].args[0].apply dummyExec
|
20 |
|
21 | it 'should load sources', ->
|
22 | expect(stub.stubs.fs.readFile).toHaveBeenCalled()
|
23 | expect(stub.stubs.fs.readFile.calls.length).toEqual 4
|
24 | expect(stub.stubs.fs.readFile.calls[0].args[0]).toEqual process.cwd()+'/requires/jquery.js'
|
25 | expect(stub.stubs.fs.readFile.calls[1].args[0]).toEqual process.cwd()+'/src/foo.js'
|
26 | expect(stub.stubs.fs.readFile.calls[2].args[0]).toEqual process.cwd()+'/src/baz.js'
|
27 | expect(stub.stubs.fs.readFile.calls[3].args[0]).toEqual process.cwd()+'/src/bar.js'
|
28 |
|
29 | it 'should fetch HTTP sources', ->
|
30 | expect(pack.httpGet).toHaveBeenCalled()
|
31 | expect(pack.httpGet.calls[0].args[0]).toEqual pack.depends[1]
|
32 | expect(pack.httpGet.calls[1].args[0]).toEqual pack.depends[2]
|
33 |
|
34 | describe 'without include_depends', ->
|
35 |
|
36 | beforeEach ->
|
37 | stub.stubs.flow.exec.calls[0].args[0].apply dummyExec
|
38 |
|
39 | it 'should load sources', ->
|
40 | expect(stub.stubs.fs.readFile).toHaveBeenCalled()
|
41 | expect(stub.stubs.fs.readFile.calls.length).toEqual 3
|
42 | expect(stub.stubs.fs.readFile.calls[0].args[0]).toEqual process.cwd()+'/src/foo.js'
|
43 | expect(stub.stubs.fs.readFile.calls[1].args[0]).toEqual process.cwd()+'/src/baz.js'
|
44 | expect(stub.stubs.fs.readFile.calls[2].args[0]).toEqual process.cwd()+'/src/bar.js'
|
45 |
|
46 | describe 'when the reading fails', ->
|
47 |
|
48 | beforeEach ->
|
49 | stub.stubs.flow.exec.calls[0].args[0].apply dummyExec
|
50 | for index, call of stub.stubs.fs.readFile.calls
|
51 | call.args[1] 'Error', index+1
|
52 | stub.stubs.flow.exec.calls[0].args[1].apply dummyExec
|
53 |
|
54 | it 'should error out', ->
|
55 | expect(pack.exitCode).toEqual 1
|
56 |
|
57 | describe 'second flow action', ->
|
58 |
|
59 | processExec = output = undefined
|
60 | beforeEach ->
|
61 | pack.minify = (str)->
|
62 | minify str
|
63 | str
|
64 | processExec = (f, fs, exec)->
|
65 | |
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 | letters = ['a', 'b', 'c']
|
77 | f.exec.calls[0].args[0].apply exec
|
78 | lines = []
|
79 | for index, call of fs.readFile.calls
|
80 | text = "#{letters[index]} = '#{call.args[0]}';"
|
81 | lines[index] = text
|
82 | call.args[1] null, text
|
83 | f.exec.calls[0].args[1].apply exec
|
84 | lines.join "\n"
|
85 |
|
86 | describe 'when minification is on', ->
|
87 |
|
88 | beforeEach ->
|
89 | pack.opts.minify = on
|
90 | output = processExec stub.stubs.flow, stub.stubs.fs, dummyExec
|
91 |
|
92 | it 'should pass the data through the minifier', ->
|
93 | expect(minify).toHaveBeenCalled()
|
94 | expect(minify.calls[0].args[0]).toEqual output
|
95 |
|
96 | describe 'when using a templated file path', ->
|
97 | output = undefined
|
98 | beforeEach ->
|
99 | pack.opts.name = 'russ'
|
100 | pack.opts.version = '2.0'
|
101 | pack.opts.build_output = "{{name}}.{{version}}.js"
|
102 | output = processExec stub.stubs.flow, stub.stubs.fs, dummyExec
|
103 |
|
104 | it 'should write the contents', ->
|
105 | expect(stub.stubs.fs.writeFile).toHaveBeenCalled()
|
106 | expect(stub.stubs.fs.writeFile.calls.length).toEqual 1
|
107 | expect(stub.stubs.fs.writeFile.calls[0].args[0]).toEqual process.cwd()+'/russ.2.0.js'
|
108 |
|
109 |
|
110 | describe 'when minification is off', ->
|
111 |
|
112 | output = undefined
|
113 | beforeEach ->
|
114 | pack.opts.minify = off
|
115 | output = processExec stub.stubs.flow, stub.stubs.fs, dummyExec
|
116 |
|
117 | it 'should write the contents', ->
|
118 | expect(stub.stubs.fs.writeFile).toHaveBeenCalled()
|
119 | expect(stub.stubs.fs.writeFile.calls.length).toEqual 1
|
120 | expect(stub.stubs.fs.writeFile.calls[0].args[0]).toEqual process.cwd()+'/output.js'
|
121 | expect(stub.stubs.fs.writeFile.calls[0].args[1]).toEqual output
|
122 |
|
123 | describe 'when writing succeeds', ->
|
124 | beforeEach ->
|
125 | stub.stubs.flow.exec.calls[0].args[2].apply dummyExec
|
126 |
|
127 | it 'should exit with a 0', ->
|
128 | expect(pack.exitCode).toEqual 0
|
129 |
|
130 | describe 'when writing fails', ->
|
131 | beforeEach ->
|
132 | stub.stubs.flow.exec.calls[0].args[2].apply dummyExec, ['Error']
|
133 |
|
134 | it 'should exit with a 1', ->
|
135 | expect(pack.exitCode).toEqual 1
|
136 |
|