aggregate-output.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 util = require('./lib/util')
  14. const runAll = util.runAll
  15. const runPar = util.runPar
  16. const runSeq = util.runSeq
  17. // ------------------------------------------------------------------------------
  18. // Test
  19. // ------------------------------------------------------------------------------
  20. describe('[aggregated-output] npm-run-all', () => {
  21. before(() => process.chdir('test-workspace'))
  22. after(() => process.chdir('..'))
  23. /**
  24. * create expected text
  25. * @param {string} term the term to use when creating a line
  26. * @returns {string} the complete line
  27. */
  28. function createExpectedOutput (term) {
  29. return `[${term}]__[${term}]`
  30. }
  31. describe('should not intermingle output of various commands', () => {
  32. const EXPECTED_PARALLELIZED_TEXT = [
  33. createExpectedOutput('second'),
  34. createExpectedOutput('third'),
  35. createExpectedOutput('first'),
  36. '',
  37. ].join('\n')
  38. let stdout = null
  39. beforeEach(() => {
  40. stdout = new BufferStream()
  41. })
  42. it('Node API with parallel', async () => {
  43. await nodeApi(
  44. ['test-task:delayed first 5000', 'test-task:delayed second 1000', 'test-task:delayed third 3000'],
  45. { stdout, parallel: true, silent: true, aggregateOutput: true }
  46. )
  47. assert.equal(stdout.value, EXPECTED_PARALLELIZED_TEXT)
  48. })
  49. it('Node API without parallel should fail', async () => {
  50. try {
  51. await nodeApi(
  52. ['test-task:delayed first 5000', 'test-task:delayed second 1000', 'test-task:delayed third 3000'],
  53. { stdout, silent: true, aggregateOutput: true }
  54. )
  55. } catch (_err) {
  56. return
  57. }
  58. assert(false, 'should fail')
  59. })
  60. it('npm-run-all command with parallel', async () => {
  61. await runAll(
  62. ['--parallel', 'test-task:delayed first 5000', 'test-task:delayed second 1000', 'test-task:delayed third 3000', '--silent', '--aggregate-output'],
  63. stdout
  64. )
  65. assert.equal(stdout.value, EXPECTED_PARALLELIZED_TEXT)
  66. })
  67. it('npm-run-all command without parallel should fail', async () => {
  68. try {
  69. await runAll(
  70. ['test-task:delayed first 5000', 'test-task:delayed second 1000', 'test-task:delayed third 3000', '--silent', '--aggregate-output'],
  71. stdout
  72. )
  73. } catch (_err) {
  74. return
  75. }
  76. assert(false, 'should fail')
  77. })
  78. it('run-s command should fail', async () => {
  79. try {
  80. await runSeq(
  81. ['test-task:delayed first 5000', 'test-task:delayed second 1000', 'test-task:delayed third 3000', '--silent', '--aggregate-output'],
  82. stdout
  83. )
  84. } catch (_err) {
  85. return
  86. }
  87. assert(false, 'should fail')
  88. })
  89. it('run-p command', async () => {
  90. await runPar(
  91. [
  92. 'test-task:delayed first 5000',
  93. 'test-task:delayed second 1000',
  94. 'test-task:delayed third 3000',
  95. '--silent', '--aggregate-output',
  96. ],
  97. stdout
  98. )
  99. assert.equal(stdout.value, EXPECTED_PARALLELIZED_TEXT)
  100. })
  101. })
  102. })