package-config.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 { execSync } = require('child_process')
  11. const assert = require('assert').strict
  12. const nodeApi = require('../lib')
  13. const { result, removeResult, runAll, runPar, runSeq } = require('./lib/util')
  14. // ------------------------------------------------------------------------------
  15. // Test
  16. // ------------------------------------------------------------------------------
  17. describe("[package-config] it should have an ability to overwrite package's config:", () => {
  18. before(() => process.chdir('test-workspace'))
  19. after(() => process.chdir('..'))
  20. beforeEach(removeResult)
  21. const [major] = execSync('npm --version', { encoding: 'utf8' }).trim().split('.')
  22. const supportsOverrides = major <= 6
  23. if (supportsOverrides) {
  24. it('Node API should address "packageConfig" option', async () => {
  25. await nodeApi('test-task:package-config', { packageConfig: { 'npm-run-all-test': { test: 'OVERWRITTEN' } } })
  26. assert.equal(result(), 'OVERWRITTEN')
  27. })
  28. it('Node API should address "packageConfig" option for multiple variables', async () => {
  29. await nodeApi('test-task:package-config2', { packageConfig: { 'npm-run-all-test': { test: '1', test2: '2', test3: '3' } } })
  30. assert.equal(result(), '1\n2\n3')
  31. })
  32. describe('CLI commands should address "--a:b=c" style options', () => {
  33. it('npm-run-all command', async () => {
  34. await runAll(['test-task:package-config', '--npm-run-all-test:test=OVERWRITTEN'])
  35. assert.equal(result(), 'OVERWRITTEN')
  36. })
  37. it('run-s command', async () => {
  38. await runSeq(['test-task:package-config', '--npm-run-all-test:test=OVERWRITTEN'])
  39. assert.equal(result(), 'OVERWRITTEN')
  40. })
  41. it('run-p command', async () => {
  42. await runPar(['test-task:package-config', '--npm-run-all-test:test=OVERWRITTEN'])
  43. assert.equal(result(), 'OVERWRITTEN')
  44. })
  45. })
  46. describe('CLI commands should address "--a:b=c" style options for multiple variables', () => {
  47. it('npm-run-all command', async () => {
  48. await runAll(['test-task:package-config2', '--npm-run-all-test:test=1', '--npm-run-all-test:test2=2', '--npm-run-all-test:test3=3'])
  49. assert.equal(result(), '1\n2\n3')
  50. })
  51. it('run-s command', async () => {
  52. await runSeq(['test-task:package-config2', '--npm-run-all-test:test=1', '--npm-run-all-test:test2=2', '--npm-run-all-test:test3=3'])
  53. assert.equal(result(), '1\n2\n3')
  54. })
  55. it('run-p command', async () => {
  56. await runPar(['test-task:package-config2', '--npm-run-all-test:test=1', '--npm-run-all-test:test2=2', '--npm-run-all-test:test3=3'])
  57. assert.equal(result(), '1\n2\n3')
  58. })
  59. })
  60. describe('CLI commands should address "--a:b c" style options', () => {
  61. it('npm-run-all command', async () => {
  62. await runAll(['test-task:package-config', '--npm-run-all-test:test', 'OVERWRITTEN'])
  63. assert.equal(result(), 'OVERWRITTEN')
  64. })
  65. it('run-s command', async () => {
  66. await runSeq(['test-task:package-config', '--npm-run-all-test:test', 'OVERWRITTEN'])
  67. assert.equal(result(), 'OVERWRITTEN')
  68. })
  69. it('run-p command', async () => {
  70. await runPar(['test-task:package-config', '--npm-run-all-test:test', 'OVERWRITTEN'])
  71. assert.equal(result(), 'OVERWRITTEN')
  72. })
  73. })
  74. describe('CLI commands should transfar overriting nested commands.', () => {
  75. it('npm-run-all command', async () => {
  76. await runAll(['test-task:nested-package-config', '--npm-run-all-test:test', 'OVERWRITTEN'])
  77. assert.equal(result(), 'OVERWRITTEN')
  78. })
  79. it('run-s command', async () => {
  80. await runSeq(['test-task:nested-package-config', '--npm-run-all-test:test', 'OVERWRITTEN'])
  81. assert.equal(result(), 'OVERWRITTEN')
  82. })
  83. it('run-p command', async () => {
  84. await runPar(['test-task:nested-package-config', '--npm-run-all-test:test', 'OVERWRITTEN'])
  85. assert.equal(result(), 'OVERWRITTEN')
  86. })
  87. })
  88. }
  89. })