yarn.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 spawn = require('cross-spawn')
  12. const BufferStream = require('./lib/buffer-stream')
  13. const { result, removeResult } = require('./lib/util')
  14. // ------------------------------------------------------------------------------
  15. // Helpers
  16. // ------------------------------------------------------------------------------
  17. /**
  18. * Execute a command.
  19. * @param {string} command A command to execute.
  20. * @param {string[]} args Arguments for the command.
  21. * @returns {Promise<void>} The result of child process's stdout.
  22. */
  23. function exec (command, args) {
  24. return new Promise((resolve, reject) => {
  25. const stderr = new BufferStream()
  26. const cp = spawn(command, args, { stdio: ['ignore', 'ignore', 'pipe'] })
  27. cp.stderr.pipe(stderr)
  28. cp.on('exit', (exitCode) => {
  29. if (exitCode) {
  30. reject(new Error(`Exited with ${exitCode}: ${stderr.value}`))
  31. return
  32. }
  33. resolve()
  34. })
  35. cp.on('error', reject)
  36. })
  37. }
  38. const nodeVersion = Number(process.versions.node.split('.')[0])
  39. // ------------------------------------------------------------------------------
  40. // Test
  41. // ------------------------------------------------------------------------------
  42. ;(nodeVersion >= 6 ? describe : xdescribe)('[yarn]', () => {
  43. before(() => process.chdir('test-workspace'))
  44. after(() => process.chdir('..'))
  45. beforeEach(removeResult)
  46. describe("'yarn run' command", () => {
  47. it("should run 'npm-run-all' in scripts with yarn.", async () => {
  48. await exec('yarn', ['run', 'test-task:yarn'])
  49. assert(result() === 'aabb')
  50. })
  51. })
  52. })