build.spec.js 8.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var Constants = require("./util/constants");
  4. var helpers = require("./util/helpers");
  5. var build = require("./build");
  6. var buildUtils = require("./build/util");
  7. var bundle = require("./bundle");
  8. var copy = require("./copy");
  9. var clean = require("./clean");
  10. var deepLinking = require("./deep-linking");
  11. var lint = require("./lint");
  12. var minify = require("./minify");
  13. var ngc = require("./ngc");
  14. var postprocess = require("./postprocess");
  15. var preprocess = require("./preprocess");
  16. var sass = require("./sass");
  17. var transpile = require("./transpile");
  18. describe('build', function () {
  19. beforeEach(function () {
  20. spyOn(clean, 'clean');
  21. spyOn(helpers, helpers.readFileAsync.name).and.returnValue(Promise.resolve());
  22. spyOn(transpile, transpile.getTsConfigAsync.name).and.callFake(function () {
  23. return Promise.resolve({
  24. 'options': {
  25. 'sourceMap': true
  26. }
  27. });
  28. });
  29. spyOn(buildUtils, buildUtils.scanSrcTsFiles.name).and.returnValue(Promise.resolve());
  30. spyOn(buildUtils, buildUtils.validateRequiredFilesExist.name).and.returnValue(Promise.resolve(['fileOneContent', 'fileTwoContent']));
  31. spyOn(buildUtils, buildUtils.validateTsConfigSettings.name).and.returnValue(Promise.resolve());
  32. spyOn(buildUtils, buildUtils.readVersionOfDependencies.name).and.returnValue(Promise.resolve());
  33. spyOn(bundle, bundle.bundle.name).and.returnValue(Promise.resolve());
  34. spyOn(copy, copy.copy.name).and.returnValue(Promise.resolve());
  35. spyOn(deepLinking, deepLinking.deepLinking.name).and.returnValue(Promise.resolve());
  36. spyOn(minify, minify.minifyCss.name).and.returnValue(Promise.resolve());
  37. spyOn(minify, minify.minifyJs.name).and.returnValue(Promise.resolve());
  38. spyOn(lint, lint.lint.name).and.returnValue(Promise.resolve());
  39. spyOn(ngc, ngc.ngc.name).and.returnValue(Promise.resolve());
  40. spyOn(postprocess, postprocess.postprocess.name).and.returnValue(Promise.resolve());
  41. spyOn(preprocess, preprocess.preprocess.name).and.returnValue(Promise.resolve());
  42. spyOn(sass, sass.sass.name).and.returnValue(Promise.resolve());
  43. spyOn(transpile, transpile.transpile.name).and.returnValue(Promise.resolve());
  44. });
  45. it('should do a prod build', function () {
  46. var context = {
  47. isProd: true,
  48. optimizeJs: true,
  49. runMinifyJs: true,
  50. runMinifyCss: true,
  51. runAot: true
  52. };
  53. var getBooleanPropertyValueSpy = spyOn(helpers, helpers.getBooleanPropertyValue.name).and.returnValue(true);
  54. return build.build(context).then(function () {
  55. expect(buildUtils.scanSrcTsFiles).toHaveBeenCalled();
  56. expect(copy.copy).toHaveBeenCalled();
  57. expect(deepLinking.deepLinking).toHaveBeenCalled();
  58. expect(ngc.ngc).toHaveBeenCalled();
  59. expect(bundle.bundle).toHaveBeenCalled();
  60. expect(minify.minifyJs).toHaveBeenCalled();
  61. expect(sass.sass).toHaveBeenCalled();
  62. expect(minify.minifyCss).toHaveBeenCalled();
  63. expect(lint.lint).toHaveBeenCalled();
  64. expect(getBooleanPropertyValueSpy.calls.all()[1].args[0]).toEqual(Constants.ENV_ENABLE_LINT);
  65. expect(transpile.transpile).not.toHaveBeenCalled();
  66. });
  67. });
  68. it('should do a dev build', function () {
  69. var context = {
  70. isProd: false,
  71. optimizeJs: false,
  72. runMinifyJs: false,
  73. runMinifyCss: false,
  74. runAot: false
  75. };
  76. var getBooleanPropertyValueSpy = spyOn(helpers, helpers.getBooleanPropertyValue.name).and.returnValue(true);
  77. return build.build(context).then(function () {
  78. expect(buildUtils.scanSrcTsFiles).toHaveBeenCalled();
  79. expect(copy.copy).toHaveBeenCalled();
  80. expect(deepLinking.deepLinking).toHaveBeenCalled();
  81. expect(transpile.transpile).toHaveBeenCalled();
  82. expect(bundle.bundle).toHaveBeenCalled();
  83. expect(sass.sass).toHaveBeenCalled();
  84. expect(lint.lint).toHaveBeenCalled();
  85. expect(getBooleanPropertyValueSpy.calls.all()[1].args[0]).toEqual(Constants.ENV_ENABLE_LINT);
  86. expect(postprocess.postprocess).toHaveBeenCalled();
  87. expect(preprocess.preprocess).toHaveBeenCalled();
  88. expect(ngc.ngc).not.toHaveBeenCalled();
  89. expect(minify.minifyJs).not.toHaveBeenCalled();
  90. expect(minify.minifyCss).not.toHaveBeenCalled();
  91. });
  92. });
  93. it('should skip lint', function () {
  94. var context = {
  95. isProd: false,
  96. optimizeJs: false,
  97. runMinifyJs: false,
  98. runMinifyCss: false,
  99. runAot: false
  100. };
  101. var getBooleanPropertyValueSpy = spyOn(helpers, helpers.getBooleanPropertyValue.name).and.returnValue(false);
  102. return build.build(context).then(function () {
  103. expect(buildUtils.scanSrcTsFiles).toHaveBeenCalled();
  104. expect(copy.copy).toHaveBeenCalled();
  105. expect(transpile.transpile).toHaveBeenCalled();
  106. expect(bundle.bundle).toHaveBeenCalled();
  107. expect(sass.sass).toHaveBeenCalled();
  108. expect(lint.lint).not.toHaveBeenCalled();
  109. expect(getBooleanPropertyValueSpy.calls.all()[1].args[0]).toEqual(Constants.ENV_ENABLE_LINT);
  110. expect(postprocess.postprocess).toHaveBeenCalled();
  111. expect(preprocess.preprocess).toHaveBeenCalled();
  112. expect(ngc.ngc).not.toHaveBeenCalled();
  113. expect(minify.minifyJs).not.toHaveBeenCalled();
  114. expect(minify.minifyCss).not.toHaveBeenCalled();
  115. });
  116. });
  117. });
  118. describe('test project requirements before building', function () {
  119. it('should fail if APP_ENTRY_POINT file does not exist', function () {
  120. process.env[Constants.ENV_APP_ENTRY_POINT] = 'src/app/main.ts';
  121. process.env[Constants.ENV_TS_CONFIG] = 'tsConfig.js';
  122. var error = new Error('App entry point was not found');
  123. spyOn(helpers, 'readFileAsync').and.returnValue(Promise.reject(error));
  124. return build.build({}).catch(function (e) {
  125. expect(helpers.readFileAsync).toHaveBeenCalledTimes(1);
  126. expect(e).toEqual(error);
  127. });
  128. });
  129. it('should fail if IONIC_TS_CONFIG file does not exist', function () {
  130. process.env[Constants.ENV_APP_ENTRY_POINT] = 'src/app/main.ts';
  131. process.env[Constants.ENV_TS_CONFIG] = 'tsConfig.js';
  132. var error = new Error('Config was not found');
  133. spyOn(helpers, helpers.readFileAsync.name).and.returnValues(Promise.resolve());
  134. spyOn(transpile, transpile.getTsConfigAsync.name).and.returnValues(Promise.reject(error));
  135. return build.build({}).catch(function (e) {
  136. expect(transpile.getTsConfigAsync).toHaveBeenCalledTimes(1);
  137. expect(helpers.readFileAsync).toHaveBeenCalledTimes(1);
  138. expect(e).toEqual(error);
  139. });
  140. });
  141. it('should fail fataly if IONIC_TS_CONFIG file does not contain valid JSON', function () {
  142. process.env[Constants.ENV_APP_ENTRY_POINT] = 'src/app/main.ts';
  143. process.env[Constants.ENV_TS_CONFIG] = 'tsConfig.js';
  144. spyOn(transpile, transpile.getTsConfigAsync.name).and.callFake(function () {
  145. return Promise.resolve("{\n \"options\" {\n \"sourceMap\": false\n }\n }\n ");
  146. });
  147. spyOn(buildUtils, buildUtils.scanSrcTsFiles.name).and.returnValue(Promise.resolve());
  148. spyOn(buildUtils, buildUtils.readVersionOfDependencies.name).and.returnValue(Promise.resolve());
  149. return build.build({}).catch(function (e) {
  150. expect(transpile.getTsConfigAsync).toHaveBeenCalledTimes(1);
  151. expect(e.isFatal).toBeTruthy();
  152. });
  153. });
  154. it('should fail fataly if IONIC_TS_CONFIG file does not contain compilerOptions.sourceMap === true', function () {
  155. process.env[Constants.ENV_APP_ENTRY_POINT] = 'src/app/main.ts';
  156. process.env[Constants.ENV_TS_CONFIG] = 'tsConfig.js';
  157. spyOn(transpile, transpile.getTsConfigAsync.name).and.callFake(function () {
  158. return Promise.resolve("{\n \"options\": {\n \"sourceMap\": false\n }\n }\n ");
  159. });
  160. spyOn(buildUtils, buildUtils.scanSrcTsFiles.name).and.returnValue(Promise.resolve());
  161. spyOn(buildUtils, buildUtils.readVersionOfDependencies.name).and.returnValue(Promise.resolve());
  162. return build.build({}).catch(function (e) {
  163. expect(transpile.getTsConfigAsync).toHaveBeenCalledTimes(1);
  164. expect(e.isFatal).toBeTruthy();
  165. });
  166. });
  167. });