produce.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /**
  2. * Created by Herby on 31. 5. 2014.
  3. */
  4. var builder = require('../lib/config-builder'),
  5. assert = require('assert'),
  6. path = require('path');
  7. function fixture(fixturePath) {
  8. return path.join(__dirname, fixturePath);
  9. }
  10. describe('#produceConfigObject merging', function () {
  11. it('should include local.amd.json if none other is present', function (done) {
  12. builder.produceConfigObject(fixture('single-local'), function (err, result) {
  13. assert.ifError(err);
  14. assert.deepEqual(result, {
  15. config: {foo: {foo: "bar"}}
  16. });
  17. done();
  18. });
  19. });
  20. it('should work root being \'.\'', function (done) {
  21. process.chdir(fixture('single-local'));
  22. builder.produceConfigObject('.', function (err, result) {
  23. assert.ifError(err);
  24. assert.deepEqual(result, {
  25. config: {foo: {foo: "bar"}}
  26. });
  27. done();
  28. });
  29. });
  30. it('should fail if foo.amd.json is present and there is no foo', function (done) {
  31. builder.produceConfigObject(fixture('local-and-missing'), function (err, result) {
  32. assert.ok(err);
  33. done();
  34. });
  35. });
  36. it('should fail if there is no applicable file', function (done) {
  37. builder.produceConfigObject(fixture('nothing'), function (err, result) {
  38. assert.ok(err);
  39. done();
  40. });
  41. });
  42. it('should include deep local.amd.json if none other is present', function (done) {
  43. builder.produceConfigObject(fixture('single-deep-local'), function (err, result) {
  44. assert.ifError(err);
  45. assert.deepEqual(result, {
  46. config: {fooDeep: {foo: "bar"}}
  47. });
  48. done();
  49. });
  50. });
  51. it('should include both local.amd.json if root and deep are present', function (done) {
  52. builder.produceConfigObject(fixture('two-locals'), function (err, result) {
  53. assert.ifError(err);
  54. assert.deepEqual(result, {
  55. config: {foo: {foo: "bar"}, fooDeep: {foo: "bar"}}
  56. });
  57. done();
  58. });
  59. });
  60. it('should include {root,deep}/local.amd.json first and {foo,bar}.amd.json afterwards given {foo,bar} dir is present', function (done) {
  61. builder.produceConfigObject(fixture('two-locals-two-others'), function (err, result) {
  62. assert.ifError(err);
  63. assert.deepEqual(result, {
  64. config: {a: 2, b: 2, c: 2, d: 2, e: 1, f: 1}
  65. });
  66. done();
  67. });
  68. });
  69. });
  70. describe('#produceConfigObject knows to deal with shims', function () {
  71. it('should output default array as {deps: anArray} in shim', function (done) {
  72. builder.produceConfigObject(fixture('single-local-shim'), function (err, result) {
  73. assert.ifError(err);
  74. assert.deepEqual(result, {
  75. shim: {foo: {deps: ["bar"]}}
  76. });
  77. done();
  78. });
  79. });
  80. it('should merge shims from {root,deep}/local.amd.json then from {foo,bar}.amd.json given {foo,bar} dir is present', function (done) {
  81. builder.produceConfigObject(fixture('two-locals-two-others-shim'), function (err, result) {
  82. assert.ifError(err);
  83. assert.deepEqual(result, {
  84. config: {a: 2, b: 2, c: 2, d: 2, e: 1, f: 1},
  85. shim: {
  86. a: {deps: ["deeplocal", "other"], exports: "deep"},
  87. b: {deps: ["rootlocal", "deep"], exports: "other"}
  88. }
  89. });
  90. done();
  91. });
  92. });
  93. });
  94. describe('#produceConfigObject paths', function () {
  95. it('should leave root local.amd.json paths unchanged', function (done) {
  96. builder.produceConfigObject(fixture('single-local-paths'), function (err, result) {
  97. assert.ifError(err);
  98. assert.deepEqual(result, {
  99. paths: {dot: ".", rel: "relative", sibling: "../sibling", abs: "/absolute", uri: "http://example.com/uri"}
  100. });
  101. done();
  102. });
  103. });
  104. it('should make deep local.amd.json paths relative to deep', function (done) {
  105. builder.produceConfigObject(fixture('single-deep-local-paths'), function (err, result) {
  106. assert.ifError(err);
  107. assert.deepEqual(result, {
  108. paths: {dot: "deep", rel: "deep/relative", sibling: "sibling", abs: "/absolute", uri: "http://example.com/uri"}
  109. });
  110. done();
  111. });
  112. });
  113. it('should make foo.amd.json paths relative to foo that is least deep', function (done) {
  114. builder.produceConfigObject(fixture('single-other-paths'), function (err, result) {
  115. assert.ifError(err);
  116. assert.deepEqual(result, {
  117. paths: {dot: "z2/other", rel: "z2/other/relative", sibling: "z2/sibling", abs: "/absolute", uri: "http://example.com/uri"}
  118. });
  119. done();
  120. });
  121. });
  122. it('should works with array paths correctly', function (done) {
  123. builder.produceConfigObject(fixture('arrays-in-paths'), function (err, result) {
  124. assert.ifError(err);
  125. assert.deepEqual(result, {
  126. paths: {
  127. dot0: ".", rel0: "relative", sibling0: "../sibling", abs0: "/absolute", uri0: "http://example.com/uri",
  128. arr0: [".", "relative", "../sibling", "/absolute", "http://example.com/uri"],
  129. dot1: "deep", rel1: "deep/relative", sibling1: "sibling", abs1: "/absolute", uri1: "http://example.com/uri",
  130. arr1: ["deep", "deep/relative", "sibling", "/absolute", "http://example.com/uri"],
  131. dot2: "z2/other", rel2: "z2/other/relative", sibling2: "z2/sibling", abs2: "/absolute", uri2: "http://example.com/uri",
  132. arr2: ["z2/other", "z2/other/relative", "z2/sibling", "/absolute", "http://example.com/uri"]
  133. }
  134. });
  135. done();
  136. });
  137. });
  138. });