config.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 { result, removeResult, runAll, runPar, runSeq } = require('./lib/util')
  13. // ------------------------------------------------------------------------------
  14. // Test
  15. // ------------------------------------------------------------------------------
  16. describe('[config] it should have an ability to set config variables:', () => {
  17. before(() => process.chdir('test-workspace'))
  18. after(() => process.chdir('..'))
  19. beforeEach(removeResult)
  20. it('Node API should address "config" option', async () => {
  21. await nodeApi('test-task:config', { config: { test: 'this is a config' } })
  22. assert(result() === 'this is a config')
  23. })
  24. it('Node API should address "config" option for multiple variables', async () => {
  25. await nodeApi('test-task:config2', { config: { test: '1', test2: '2', test3: '3' } })
  26. assert(result() === '1\n2\n3')
  27. })
  28. describe('CLI commands should address "--a=b" style options', () => {
  29. it('npm-run-all command', async () => {
  30. await runAll(['test-task:config', '--test=GO'])
  31. assert(result() === 'GO')
  32. })
  33. it('run-s command', async () => {
  34. await runSeq(['test-task:config', '--test=GO'])
  35. assert(result() === 'GO')
  36. })
  37. it('run-p command', async () => {
  38. await runPar(['test-task:config', '--test=GO'])
  39. assert(result() === 'GO')
  40. })
  41. })
  42. describe('CLI commands should address "--b=c" style options for multiple variables', () => {
  43. it('npm-run-all command', async () => {
  44. await runAll(['test-task:config2', '--test=1', '--test2=2', '--test3=3'])
  45. assert(result() === '1\n2\n3')
  46. })
  47. it('run-s command', async () => {
  48. await runSeq(['test-task:config2', '--test=1', '--test2=2', '--test3=3'])
  49. assert(result() === '1\n2\n3')
  50. })
  51. it('run-p command', async () => {
  52. await runPar(['test-task:config2', '--test=1', '--test2=2', '--test3=3'])
  53. assert(result() === '1\n2\n3')
  54. })
  55. })
  56. describe('CLI commands should transfar configs to nested commands.', () => {
  57. it('npm-run-all command', async () => {
  58. await runAll(['test-task:nested-config', '--test=GO DEEP'])
  59. assert(result() === 'GO DEEP')
  60. })
  61. it('run-s command', async () => {
  62. await runSeq(['test-task:nested-config', '--test=GO DEEP'])
  63. assert(result() === 'GO DEEP')
  64. })
  65. it('run-p command', async () => {
  66. await runPar(['test-task:nested-config', '--test=GO DEEP'])
  67. assert(result() === 'GO DEEP')
  68. })
  69. })
  70. })