index.coffee 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. 'use strict'
  2. should = require 'should'
  3. describe 'gulp-sync', ->
  4. gulp = null
  5. gulpsync = null
  6. tasks1 = ['a', 'b', 'c']
  7. tasks2 = ['a', ['b-1', 'b-2'], ['c-1', 'c-2', ['c-3-1', 'c-3-2']]]
  8. deepCheck = (tasks)->
  9. for task in tasks
  10. # console.log task
  11. deps = gulp.tasks[task]?.dep
  12. # console.log deps
  13. if deps
  14. for dep in deps
  15. # console.log dep
  16. should.exist gulp.tasks[dep]
  17. deepCheck deps
  18. createTasks = (tasks, isAsync)->
  19. wait = 300
  20. for task in tasks
  21. if Array.isArray task
  22. createTasks task, !isAsync
  23. else
  24. do (task)->
  25. gulp.task task, (cb)->
  26. setTimeout ->
  27. gulp.tasks[task].running.should.equal true
  28. console.log task, if isAsync then 'async' else 'sync'
  29. cb()
  30. , wait -= 100
  31. beforeEach ->
  32. delete require.cache[require.resolve 'gulp']
  33. delete require.cache[require.resolve '../lib/']
  34. gulp = require 'gulp'
  35. gulpsync = require('../lib/') gulp
  36. it 'async flat', (done)->
  37. console.log 'async flat'
  38. createTasks tasks1, true
  39. t = gulpsync.async tasks1
  40. should.exist t
  41. Array.isArray(t).should.equal true
  42. t[0].should.equal tasks1[0]
  43. t[1].should.equal tasks1[1]
  44. t[2].should.equal tasks1[2]
  45. deepCheck t
  46. gulp.task 'test', t, ->
  47. done()
  48. gulp.start 'test'
  49. # console.log '---------------'
  50. # console.log t
  51. # console.log gulp.tasks
  52. it 'async flat without custom group name', (done)->
  53. console.log 'async flat without custom group name'
  54. createTasks tasks1, true
  55. t = gulpsync.async tasks1
  56. should.exist t
  57. Array.isArray(t).should.equal true
  58. t[0].should.equal tasks1[0]
  59. t[1].should.equal tasks1[1]
  60. t[2].should.equal tasks1[2]
  61. deepCheck t
  62. gulp.task 'test', t, ->
  63. done()
  64. gulp.start 'test'
  65. # console.log '---------------'
  66. # console.log t
  67. # console.log gulp.tasks
  68. it 'async flat with custom group name', (done)->
  69. console.log 'async flat with custom group name'
  70. createTasks tasks1, true
  71. t = gulpsync.async tasks1, 'custom group name'
  72. should.exist t
  73. Array.isArray(t).should.equal true
  74. t[0].should.equal tasks1[0]
  75. t[1].should.equal tasks1[1]
  76. t[2].should.equal tasks1[2]
  77. deepCheck t
  78. gulp.task 'test', t, ->
  79. done()
  80. gulp.start 'test'
  81. # console.log '---------------'
  82. # console.log t
  83. # console.log gulp.tasks
  84. it 'async deep', (done)->
  85. console.log 'async deep'
  86. createTasks tasks2, true
  87. t = gulpsync.async tasks2
  88. should.exist t
  89. Array.isArray(t).should.equal true
  90. t[0].should.equal tasks2[0]
  91. should.exist gulp.tasks[t[1]]
  92. should.exist gulp.tasks[t[2]]
  93. deepCheck t
  94. gulp.task 'test', t, ->
  95. done()
  96. gulp.start 'test'
  97. # console.log '---------------'
  98. # console.log t
  99. # console.log gulp.tasks
  100. it 'async deep without custom group name', (done)->
  101. console.log 'async deep without custom group name'
  102. createTasks tasks2, true
  103. t = gulpsync.async tasks2
  104. should.exist t
  105. Array.isArray(t).should.equal true
  106. t[0].should.equal tasks2[0]
  107. should.exist gulp.tasks[t[1]]
  108. should.exist gulp.tasks[t[2]]
  109. deepCheck t
  110. gulp.task 'test', t, ->
  111. done()
  112. gulp.start 'test'
  113. # console.log '---------------'
  114. # console.log t
  115. # console.log gulp.tasks
  116. it 'async deep with custom group name', (done)->
  117. console.log 'async deep with custom group name'
  118. createTasks tasks2, true
  119. t = gulpsync.async tasks2, 'custom group name'
  120. should.exist t
  121. Array.isArray(t).should.equal true
  122. t[0].should.equal tasks2[0]
  123. should.exist gulp.tasks[t[1]]
  124. should.exist gulp.tasks[t[2]]
  125. t[1].split(':')[0].should.equal 'custom group name'
  126. t[2].split(':')[0].should.equal 'custom group name'
  127. deepCheck t
  128. gulp.task 'test', t, ->
  129. done()
  130. gulp.start 'test'
  131. # console.log '---------------'
  132. # console.log t
  133. # console.log gulp.tasks
  134. it 'sync flat', (done)->
  135. console.log 'sync flat'
  136. createTasks tasks1, false
  137. t = gulpsync.sync tasks1
  138. should.exist t
  139. Array.isArray(t).should.equal true
  140. t.length.should.equal 1
  141. should.exist gulp.tasks[t[0]]
  142. deepCheck t
  143. gulp.task 'test', t, ->
  144. done()
  145. gulp.start 'test'
  146. # console.log '---------------'
  147. # console.log t
  148. # console.log gulp.tasks
  149. it 'sync flat without custom group name', (done)->
  150. console.log 'sync flat without custom group name'
  151. createTasks tasks1, false
  152. t = gulpsync.sync tasks1
  153. should.exist t
  154. Array.isArray(t).should.equal true
  155. t.length.should.equal 1
  156. should.exist gulp.tasks[t[0]]
  157. deepCheck t
  158. gulp.task 'test', t, ->
  159. done()
  160. gulp.start 'test'
  161. # console.log '---------------'
  162. # console.log t
  163. # console.log gulp.tasks
  164. it 'sync flat with custom group name', (done)->
  165. console.log 'sync flat with custom group name'
  166. createTasks tasks1, false
  167. t = gulpsync.sync tasks1, 'custom group name'
  168. should.exist t
  169. Array.isArray(t).should.equal true
  170. t.length.should.equal 1
  171. should.exist gulp.tasks[t[0]]
  172. t[0].split(':')[0].should.equal 'custom group name'
  173. deepCheck t
  174. gulp.task 'test', t, ->
  175. done()
  176. gulp.start 'test'
  177. # console.log '---------------'
  178. # console.log t
  179. # console.log gulp.tasks
  180. it 'sync deep', (done)->
  181. console.log 'sync deep'
  182. createTasks tasks2, false
  183. t = gulpsync.sync tasks2
  184. should.exist t
  185. Array.isArray(t).should.equal true
  186. t.length.should.equal 1
  187. should.exist gulp.tasks[t[0]]
  188. deepCheck t
  189. gulp.task 'test', t, ->
  190. done()
  191. gulp.start 'test'
  192. # console.log '---------------'
  193. # console.log t
  194. # console.log gulp.tasks
  195. it 'sync deep without custom group name', (done)->
  196. console.log 'sync deep without custom group name'
  197. createTasks tasks2, false
  198. t = gulpsync.sync tasks2
  199. should.exist t
  200. Array.isArray(t).should.equal true
  201. t.length.should.equal 1
  202. should.exist gulp.tasks[t[0]]
  203. deepCheck t
  204. gulp.task 'test', t, ->
  205. done()
  206. gulp.start 'test'
  207. # console.log '---------------'
  208. # console.log t
  209. # console.log gulp.tasks
  210. it 'sync deep with custom group name', (done)->
  211. console.log 'sync deep with custom group name'
  212. createTasks tasks2, false
  213. t = gulpsync.sync tasks2, 'custom group name'
  214. should.exist t
  215. Array.isArray(t).should.equal true
  216. t.length.should.equal 1
  217. should.exist gulp.tasks[t[0]]
  218. t[0].split(':')[0].should.equal 'custom group name'
  219. deepCheck t
  220. gulp.task 'test', t, ->
  221. done()
  222. gulp.start 'test'
  223. # console.log '---------------'
  224. # console.log t
  225. # console.log gulp.tasks
  226. it 'mix and multiple without custom group name', (done)->
  227. console.log 'mix and multiple without custom group name'
  228. createTasks tasks1, true
  229. createTasks tasks2, false
  230. t1 = gulpsync.sync tasks1
  231. t2 = gulpsync.sync tasks2
  232. should.exist t1
  233. should.exist t2
  234. Array.isArray(t1).should.equal true
  235. Array.isArray(t2).should.equal true
  236. t1.length.should.equal 1
  237. t2.length.should.equal 1
  238. should.exist gulp.tasks[t1[0]]
  239. should.exist gulp.tasks[t2[0]]
  240. deepCheck t1
  241. deepCheck t2
  242. gulp.task 'test1', t1, ->
  243. gulp.start 'test2'
  244. gulp.task 'test2', t2, ->
  245. done()
  246. gulp.start 'test1'
  247. # console.log '---------------'
  248. # console.log t
  249. # console.log gulp.tasks
  250. it 'mix and multiple with custom group name', (done)->
  251. console.log 'mix and multiple with custom group name'
  252. createTasks tasks1, true
  253. createTasks tasks2, false
  254. t1 = gulpsync.sync tasks1, 'custom group name1'
  255. t2 = gulpsync.sync tasks2, 'custom group name2'
  256. should.exist t1
  257. should.exist t2
  258. Array.isArray(t1).should.equal true
  259. Array.isArray(t2).should.equal true
  260. t1.length.should.equal 1
  261. t2.length.should.equal 1
  262. should.exist gulp.tasks[t1[0]]
  263. should.exist gulp.tasks[t2[0]]
  264. t1[0].split(':')[0].should.equal 'custom group name1'
  265. t2[0].split(':')[0].should.equal 'custom group name2'
  266. deepCheck t1
  267. deepCheck t2
  268. gulp.task 'test1', t1, ->
  269. gulp.start 'test2'
  270. gulp.task 'test2', t2, ->
  271. done()
  272. gulp.start 'test1'
  273. # console.log '---------------'
  274. # console.log t
  275. # console.log gulp.tasks