提交学习笔记专用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

218 lines
6.3 KiB

  1. /**
  2. * @author Toru Nagashima
  3. * @copyright 2016 Toru Nagashima. All rights reserved.
  4. * See LICENSE file in root directory for full license.
  5. */
  6. 'use strict'
  7. // ------------------------------------------------------------------------------
  8. // Requirements
  9. // ------------------------------------------------------------------------------
  10. const assert = require('assert').strict
  11. const nodeApi = require('../lib')
  12. const BufferStream = require('./lib/buffer-stream')
  13. const { result, removeResult, runAll, runPar, runSeq } = require('./lib/util')
  14. // ------------------------------------------------------------------------------
  15. // Test
  16. // ------------------------------------------------------------------------------
  17. describe('[pattern] it should run matched tasks if glob like patterns are given.', () => {
  18. before(() => process.chdir('test-workspace'))
  19. after(() => process.chdir('..'))
  20. beforeEach(removeResult)
  21. describe('"test-task:append:*" to "test-task:append:a" and "test-task:append:b"', () => {
  22. it('Node API', async () => {
  23. await nodeApi('test-task:append:*')
  24. assert(result() === 'aabb')
  25. })
  26. it('npm-run-all command', async () => {
  27. await runAll(['test-task:append:*'])
  28. assert(result() === 'aabb')
  29. })
  30. it('run-s command', async () => {
  31. await runSeq(['test-task:append:*'])
  32. assert(result() === 'aabb')
  33. })
  34. it('run-p command', async () => {
  35. await runPar(['test-task:append:*'])
  36. assert(
  37. result() === 'abab' ||
  38. result() === 'abba' ||
  39. result() === 'baba' ||
  40. result() === 'baab'
  41. )
  42. })
  43. })
  44. describe('"test-task:append:**" to "test-task:append:a", "test-task:append:a:c", "test-task:append:a:d", and "test-task:append:b"', () => {
  45. it('Node API', async () => {
  46. await nodeApi('test-task:append:**')
  47. assert(result() === 'aaacacadadbb')
  48. })
  49. it('npm-run-all command', async () => {
  50. await runAll(['test-task:append:**'])
  51. assert(result() === 'aaacacadadbb')
  52. })
  53. it('run-s command', async () => {
  54. await runSeq(['test-task:append:**'])
  55. assert(result() === 'aaacacadadbb')
  56. })
  57. })
  58. // should act same way as section above
  59. describe('"test-task:append:**:*" to "test-task:append:a", "test-task:append:a:c", "test-task:append:a:d", and "test-task:append:b"', () => {
  60. it('Node API', async () => {
  61. await nodeApi('test-task:append:**:*')
  62. assert(result() === 'aaacacadadbb')
  63. })
  64. it('npm-run-all command', async () => {
  65. await runAll(['test-task:append:**:*'])
  66. assert(result() === 'aaacacadadbb')
  67. })
  68. it('run-s command', async () => {
  69. await runSeq(['test-task:append:**:*'])
  70. assert(result() === 'aaacacadadbb')
  71. })
  72. })
  73. describe('(should ignore duplications) "test-task:append:b" "test-task:append:*" to "test-task:append:b", "test-task:append:a"', () => {
  74. it('Node API', async () => {
  75. await nodeApi(['test-task:append:b', 'test-task:append:*'])
  76. assert(result() === 'bbaa')
  77. })
  78. it('npm-run-all command', async () => {
  79. await runAll(['test-task:append:b', 'test-task:append:*'])
  80. assert(result() === 'bbaa')
  81. })
  82. it('run-s command', async () => {
  83. await runSeq(['test-task:append:b', 'test-task:append:*'])
  84. assert(result() === 'bbaa')
  85. })
  86. it('run-p command', async () => {
  87. await runPar(['test-task:append:b', 'test-task:append:*'])
  88. assert(
  89. result() === 'baba' ||
  90. result() === 'baab' ||
  91. result() === 'abab' ||
  92. result() === 'abba'
  93. )
  94. })
  95. })
  96. describe('"a" should not match to "test-task:append:a"', () => {
  97. it('Node API', async () => {
  98. try {
  99. await nodeApi('a')
  100. assert(false, 'should not match')
  101. } catch (err) {
  102. assert((/not found/i).test(err.message))
  103. }
  104. })
  105. it('npm-run-all command', async () => {
  106. const stderr = new BufferStream()
  107. try {
  108. await runAll(['a'], null, stderr)
  109. assert(false, 'should not match')
  110. } catch (_err) {
  111. assert((/not found/i).test(stderr.value))
  112. }
  113. })
  114. it('run-s command', async () => {
  115. const stderr = new BufferStream()
  116. try {
  117. await runSeq(['a'], null, stderr)
  118. assert(false, 'should not match')
  119. } catch (_err) {
  120. assert((/not found/i).test(stderr.value))
  121. }
  122. })
  123. it('run-p command', async () => {
  124. const stderr = new BufferStream()
  125. try {
  126. await runPar(['a'], null, stderr)
  127. assert(false, 'should not match')
  128. } catch (_err) {
  129. assert((/not found/i).test(stderr.value))
  130. }
  131. })
  132. })
  133. describe('"!test-task:**" should not match to anything', () => {
  134. it('Node API', async () => {
  135. try {
  136. await nodeApi('!test-task:**')
  137. assert(false, 'should not match')
  138. } catch (err) {
  139. assert((/not found/i).test(err.message))
  140. }
  141. })
  142. it('npm-run-all command', async () => {
  143. const stderr = new BufferStream()
  144. try {
  145. await runAll(['!test-task:**'], null, stderr)
  146. assert(false, 'should not match')
  147. } catch (_err) {
  148. assert((/not found/i).test(stderr.value))
  149. }
  150. })
  151. it('run-s command', async () => {
  152. const stderr = new BufferStream()
  153. try {
  154. await runSeq(['!test-task:**'], null, stderr)
  155. assert(false, 'should not match')
  156. } catch (_err) {
  157. assert((/not found/i).test(stderr.value))
  158. }
  159. })
  160. it('run-p command', async () => {
  161. const stderr = new BufferStream()
  162. try {
  163. await runPar(['!test-task:**'], null, stderr)
  164. assert(false, 'should not match')
  165. } catch (_err) {
  166. assert((/not found/i).test(stderr.value))
  167. }
  168. })
  169. })
  170. describe('"!test" "?test" to "!test", "?test"', () => {
  171. it('Node API', async () => {
  172. await nodeApi(['!test', '?test'])
  173. assert(result().trim() === 'XQ')
  174. })
  175. it('npm-run-all command', async () => {
  176. await runAll(['!test', '?test'])
  177. assert(result().trim() === 'XQ')
  178. })
  179. it('run-s command', async () => {
  180. await runSeq(['!test', '?test'])
  181. assert(result().trim() === 'XQ')
  182. })
  183. it('run-p command', async () => {
  184. await runPar(['!test', '?test'])
  185. assert(result().trim() === 'XQ' || result().trim() === 'QX')
  186. })
  187. })
  188. })