pattern.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. describe('(should ignore duplications) "test-task:append:b" "test-task:append:*" to "test-task:append:b", "test-task:append:a"', () => {
  59. it('Node API', async () => {
  60. await nodeApi(['test-task:append:b', 'test-task:append:*'])
  61. assert(result() === 'bbaa')
  62. })
  63. it('npm-run-all command', async () => {
  64. await runAll(['test-task:append:b', 'test-task:append:*'])
  65. assert(result() === 'bbaa')
  66. })
  67. it('run-s command', async () => {
  68. await runSeq(['test-task:append:b', 'test-task:append:*'])
  69. assert(result() === 'bbaa')
  70. })
  71. it('run-p command', async () => {
  72. await runPar(['test-task:append:b', 'test-task:append:*'])
  73. assert(
  74. result() === 'baba' ||
  75. result() === 'baab' ||
  76. result() === 'abab' ||
  77. result() === 'abba'
  78. )
  79. })
  80. })
  81. describe('"a" should not match to "test-task:append:a"', () => {
  82. it('Node API', async () => {
  83. try {
  84. await nodeApi('a')
  85. assert(false, 'should not match')
  86. } catch (err) {
  87. assert((/not found/i).test(err.message))
  88. }
  89. })
  90. it('npm-run-all command', async () => {
  91. const stderr = new BufferStream()
  92. try {
  93. await runAll(['a'], null, stderr)
  94. assert(false, 'should not match')
  95. } catch (_err) {
  96. assert((/not found/i).test(stderr.value))
  97. }
  98. })
  99. it('run-s command', async () => {
  100. const stderr = new BufferStream()
  101. try {
  102. await runSeq(['a'], null, stderr)
  103. assert(false, 'should not match')
  104. } catch (_err) {
  105. assert((/not found/i).test(stderr.value))
  106. }
  107. })
  108. it('run-p command', async () => {
  109. const stderr = new BufferStream()
  110. try {
  111. await runPar(['a'], null, stderr)
  112. assert(false, 'should not match')
  113. } catch (_err) {
  114. assert((/not found/i).test(stderr.value))
  115. }
  116. })
  117. })
  118. describe('"!test-task:**" should not match to anything', () => {
  119. it('Node API', async () => {
  120. try {
  121. await nodeApi('!test-task:**')
  122. assert(false, 'should not match')
  123. } catch (err) {
  124. assert((/not found/i).test(err.message))
  125. }
  126. })
  127. it('npm-run-all command', async () => {
  128. const stderr = new BufferStream()
  129. try {
  130. await runAll(['!test-task:**'], null, stderr)
  131. assert(false, 'should not match')
  132. } catch (_err) {
  133. assert((/not found/i).test(stderr.value))
  134. }
  135. })
  136. it('run-s command', async () => {
  137. const stderr = new BufferStream()
  138. try {
  139. await runSeq(['!test-task:**'], null, stderr)
  140. assert(false, 'should not match')
  141. } catch (_err) {
  142. assert((/not found/i).test(stderr.value))
  143. }
  144. })
  145. it('run-p command', async () => {
  146. const stderr = new BufferStream()
  147. try {
  148. await runPar(['!test-task:**'], null, stderr)
  149. assert(false, 'should not match')
  150. } catch (_err) {
  151. assert((/not found/i).test(stderr.value))
  152. }
  153. })
  154. })
  155. describe('"!test" "?test" to "!test", "?test"', () => {
  156. it('Node API', async () => {
  157. await nodeApi(['!test', '?test'])
  158. assert(result().trim() === 'XQ')
  159. })
  160. it('npm-run-all command', async () => {
  161. await runAll(['!test', '?test'])
  162. assert(result().trim() === 'XQ')
  163. })
  164. it('run-s command', async () => {
  165. await runSeq(['!test', '?test'])
  166. assert(result().trim() === 'XQ')
  167. })
  168. it('run-p command', async () => {
  169. await runPar(['!test', '?test'])
  170. assert(result().trim() === 'XQ' || result().trim() === 'QX')
  171. })
  172. })
  173. })