produce.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 fail if foo.amd.json is present and there is no foo', function (done) {
  21. builder.produceConfigObject(fixture('local-and-missing'), function (err, result) {
  22. assert.ok(err);
  23. done();
  24. });
  25. });
  26. it('should fail if there is no applicable file', function (done) {
  27. builder.produceConfigObject(fixture('nothing'), function (err, result) {
  28. assert.ok(err);
  29. done();
  30. });
  31. });
  32. it('should include deep local.amd.json if none other is present', function (done) {
  33. builder.produceConfigObject(fixture('single-deep-local'), function (err, result) {
  34. assert.ifError(err);
  35. assert.deepEqual(result, {
  36. config: {fooDeep: {foo: "bar"}}
  37. });
  38. done();
  39. });
  40. });
  41. it('should include both local.amd.json if root and deep are present', function (done) {
  42. builder.produceConfigObject(fixture('two-locals'), function (err, result) {
  43. assert.ifError(err);
  44. assert.deepEqual(result, {
  45. config: {foo: {foo: "bar"}, fooDeep: {foo: "bar"}}
  46. });
  47. done();
  48. });
  49. });
  50. it('should include {root,deep}/local.amd.json first and {foo,bar}.amd.json afterwards given {foo,bar} dir is present', function (done) {
  51. builder.produceConfigObject(fixture('two-locals-two-others'), function (err, result) {
  52. assert.ifError(err);
  53. assert.deepEqual(result, {
  54. config: {a:2, b:2, c:2, d:2, e:1, f:1}
  55. });
  56. done();
  57. });
  58. });
  59. });
  60. describe('#produceConfigObject knows to deal with shims', function () {
  61. it('should output default array as {deps: anArray} in shim', function (done) {
  62. builder.produceConfigObject(fixture('single-local-shim'), function (err, result) {
  63. assert.ifError(err);
  64. assert.deepEqual(result, {
  65. shim: {foo: {deps: ["bar"]}}
  66. });
  67. done();
  68. });
  69. });
  70. it('should merge shims from {root,deep}/local.amd.json then from {foo,bar}.amd.json given {foo,bar} dir is present', function (done) {
  71. builder.produceConfigObject(fixture('two-locals-two-others-shim'), function (err, result) {
  72. assert.ifError(err);
  73. assert.deepEqual(result, {
  74. config: {a:2, b:2, c:2, d:2, e:1, f:1},
  75. shim: {
  76. a: {deps: ["deeplocal", "other"], exports: "deep"},
  77. b: {deps: ["rootlocal", "deep"], exports: "other"}
  78. }
  79. });
  80. done();
  81. });
  82. });
  83. });
  84. describe('#produceConfigObject paths', function () {
  85. it('should leave root local.amd.json paths unchanged', function (done) {
  86. builder.produceConfigObject(fixture('single-local-paths'), function (err, result) {
  87. assert.ifError(err);
  88. assert.deepEqual(result, {
  89. paths: {dot: ".", rel: "relative", sibling: "../sibling", abs: "/absolute", uri: "http://example.com/uri"}
  90. });
  91. done();
  92. });
  93. });
  94. it('should make deep local.amd.json paths relative to deep', function (done) {
  95. builder.produceConfigObject(fixture('single-deep-local-paths'), function (err, result) {
  96. assert.ifError(err);
  97. assert.deepEqual(result, {
  98. paths: {dot: "deep", rel: "deep/relative", sibling: "sibling", abs: "/absolute", uri: "http://example.com/uri"}
  99. });
  100. done();
  101. });
  102. });
  103. it('should make foo.amd.json paths relative to foo that is least deep', function (done) {
  104. builder.produceConfigObject(fixture('single-other-paths'), function (err, result) {
  105. assert.ifError(err);
  106. assert.deepEqual(result, {
  107. paths: {dot: "z2/other", rel: "z2/other/relative", sibling: "z2/sibling", abs: "/absolute", uri: "http://example.com/uri"}
  108. });
  109. done();
  110. });
  111. });
  112. });