produce.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 both local.amd.json if root and deep are present, deep first', function (done) {
  61. builder.produceConfigObject(fixture('two-locals-with-shared'), function (err, result) {
  62. assert.ifError(err);
  63. assert.deepEqual(result, {
  64. config: {foo: {foo: "bar"}, fooDeep: {foo: "bar"}, shared: "root"}
  65. });
  66. done();
  67. });
  68. });
  69. it('should include {root,deep}/local.amd.json first and {foo,bar}.amd.json afterwards given {foo,bar} dir is present', function (done) {
  70. builder.produceConfigObject(fixture('two-locals-two-others'), function (err, result) {
  71. assert.ifError(err);
  72. assert.deepEqual(result, {
  73. config: {a: 2, b: 2, c: 2, d: 2, e: 1, f: 1}
  74. });
  75. done();
  76. });
  77. });
  78. it('should include {root,deep}/local.amd.json first and {foo,bar}.amd.json afterwards given {foo,bar} dir is present, deeps first', function (done) {
  79. builder.produceConfigObject(fixture('two-locals-two-others-with-shared'), function (err, result) {
  80. assert.ifError(err);
  81. assert.deepEqual(result, {
  82. config: {a: 2, b: 2, c: 2, d: 2, e: 1, f: 1, g: 2, h: 1}
  83. });
  84. done();
  85. });
  86. });
  87. });
  88. describe('#produceConfigObject knows to deal with shims', function () {
  89. it('should output default array as {deps: anArray} in shim', function (done) {
  90. builder.produceConfigObject(fixture('single-local-shim'), function (err, result) {
  91. assert.ifError(err);
  92. assert.deepEqual(result, {
  93. shim: {foo: {deps: ["bar"]}}
  94. });
  95. done();
  96. });
  97. });
  98. it('should merge shims from {root,deep}/local.amd.json then from {foo,bar}.amd.json given {foo,bar} dir is present', function (done) {
  99. builder.produceConfigObject(fixture('two-locals-two-others-shim'), function (err, result) {
  100. assert.ifError(err);
  101. assert.deepEqual(result, {
  102. config: {a: 2, b: 2, c: 2, d: 2, e: 1, f: 1},
  103. shim: {
  104. a: {deps: ["deeplocal", "other"], exports: "deep"},
  105. b: {deps: ["rootlocal", "deep"], exports: "other"}
  106. }
  107. });
  108. done();
  109. });
  110. });
  111. });
  112. describe('#produceConfigObject paths', function () {
  113. it('should leave root local.amd.json paths unchanged', function (done) {
  114. builder.produceConfigObject(fixture('single-local-paths'), function (err, result) {
  115. assert.ifError(err);
  116. assert.deepEqual(result, {
  117. paths: {dot: ".", rel: "relative", sibling: "../sibling", abs: "/absolute", uri: "http://example.com/uri"}
  118. });
  119. done();
  120. });
  121. });
  122. it('should make deep local.amd.json paths relative to deep', function (done) {
  123. builder.produceConfigObject(fixture('single-deep-local-paths'), function (err, result) {
  124. assert.ifError(err);
  125. assert.deepEqual(result, {
  126. paths: {dot: "deep", rel: "deep/relative", sibling: "sibling", abs: "/absolute", uri: "http://example.com/uri"}
  127. });
  128. done();
  129. });
  130. });
  131. it('should make foo.amd.json paths relative to foo that is least deep', function (done) {
  132. builder.produceConfigObject(fixture('single-other-paths'), function (err, result) {
  133. assert.ifError(err);
  134. assert.deepEqual(result, {
  135. paths: {dot: "z2/other", rel: "z2/other/relative", sibling: "z2/sibling", abs: "/absolute", uri: "http://example.com/uri"}
  136. });
  137. done();
  138. });
  139. });
  140. it('should works with array paths correctly', function (done) {
  141. builder.produceConfigObject(fixture('arrays-in-paths'), function (err, result) {
  142. assert.ifError(err);
  143. assert.deepEqual(result, {
  144. paths: {
  145. dot0: ".", rel0: "relative", sibling0: "../sibling", abs0: "/absolute", uri0: "http://example.com/uri",
  146. arr0: [".", "relative", "../sibling", "/absolute", "http://example.com/uri"],
  147. dot1: "deep", rel1: "deep/relative", sibling1: "sibling", abs1: "/absolute", uri1: "http://example.com/uri",
  148. arr1: ["deep", "deep/relative", "sibling", "/absolute", "http://example.com/uri"],
  149. dot2: "z2/other", rel2: "z2/other/relative", sibling2: "z2/sibling", abs2: "/absolute", uri2: "http://example.com/uri",
  150. arr2: ["z2/other", "z2/other/relative", "z2/sibling", "/absolute", "http://example.com/uri"]
  151. }
  152. });
  153. done();
  154. });
  155. });
  156. });