tsconfig.spec.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var chai_1 = require("chai");
  4. var path_1 = require("path");
  5. var util_1 = require("util");
  6. var tsconfig = require("./tsconfig");
  7. var TEST_DIR = path_1.join(__dirname, '../tests');
  8. describe('tsconfig', function () {
  9. var tests = [
  10. {
  11. args: [TEST_DIR, 'invalidfile'],
  12. error: parseInt(process.versions.node, 10) > 5 ? 'Unexpected token s in JSON at position 0' : 'Unexpected token s'
  13. },
  14. {
  15. args: [TEST_DIR, 'missing'],
  16. error: 'Cannot find a tsconfig.json file at the specified directory: missing'
  17. },
  18. {
  19. args: [TEST_DIR, 'missing/foobar'],
  20. error: 'The specified path does not exist: missing/foobar'
  21. },
  22. {
  23. args: ['/'],
  24. config: {
  25. files: [],
  26. compilerOptions: {}
  27. }
  28. },
  29. {
  30. args: [TEST_DIR, 'empty'],
  31. config: {},
  32. path: path_1.join(TEST_DIR, 'empty/tsconfig.json')
  33. },
  34. {
  35. args: [TEST_DIR, 'empty/tsconfig.json'],
  36. config: {},
  37. path: path_1.join(TEST_DIR, 'empty/tsconfig.json')
  38. },
  39. {
  40. args: [path_1.join(TEST_DIR, 'find/up/config')],
  41. config: {},
  42. path: path_1.join(TEST_DIR, 'find/tsconfig.json')
  43. },
  44. {
  45. args: [TEST_DIR, 'valid'],
  46. config: {
  47. compilerOptions: {
  48. module: 'commonjs',
  49. noImplicitAny: true,
  50. outDir: 'dist',
  51. removeComments: true,
  52. sourceMap: true,
  53. preserveConstEnums: true
  54. },
  55. files: [
  56. './src/foo.ts'
  57. ]
  58. },
  59. path: path_1.join(TEST_DIR, 'valid/tsconfig.json')
  60. },
  61. {
  62. args: [TEST_DIR, 'bom'],
  63. config: {
  64. compilerOptions: {
  65. module: 'commonjs',
  66. noImplicitAny: true,
  67. outDir: 'dist',
  68. removeComments: true,
  69. sourceMap: true,
  70. preserveConstEnums: true
  71. },
  72. files: [
  73. './src/bom.ts'
  74. ]
  75. },
  76. path: path_1.join(TEST_DIR, 'bom/tsconfig.json')
  77. },
  78. {
  79. args: [path_1.join(TEST_DIR, 'cwd')],
  80. config: {
  81. compilerOptions: {
  82. module: 'commonjs',
  83. noImplicitAny: true,
  84. outDir: 'dist',
  85. removeComments: true,
  86. sourceMap: true,
  87. preserveConstEnums: true
  88. }
  89. },
  90. path: path_1.join(TEST_DIR, 'cwd/tsconfig.json')
  91. }
  92. ];
  93. describe('sync', function () {
  94. tests.forEach(function (test) {
  95. describe(util_1.inspect(test.args), function () {
  96. it('should try to find config', function () {
  97. var result;
  98. try {
  99. result = tsconfig.loadSync(test.args[0], test.args[1]);
  100. }
  101. catch (err) {
  102. chai_1.expect(err.message).to.equal(test.error);
  103. return;
  104. }
  105. chai_1.expect(result.path).to.equal(test.path);
  106. chai_1.expect(result.config).to.deep.equal(test.config);
  107. });
  108. if (test.path) {
  109. it('should resolve filename', function () {
  110. chai_1.expect(tsconfig.resolveSync(test.args[0], test.args[1])).to.equal(test.path);
  111. });
  112. }
  113. });
  114. });
  115. });
  116. describe('async', function () {
  117. tests.forEach(function (test) {
  118. describe(util_1.inspect(test.args), function () {
  119. it('should try to find config', function () {
  120. return tsconfig.load(test.args[0], test.args[1])
  121. .then(function (result) {
  122. chai_1.expect(result.path).to.equal(test.path);
  123. chai_1.expect(result.config).to.deep.equal(test.config);
  124. }, function (error) {
  125. chai_1.expect(error.message).to.equal(test.error);
  126. });
  127. });
  128. if (test.path) {
  129. it('should resolve filename', function () {
  130. return tsconfig.resolve(test.args[0], test.args[1])
  131. .then(function (filename) {
  132. chai_1.expect(filename).to.equal(test.path);
  133. });
  134. });
  135. }
  136. });
  137. });
  138. });
  139. });
  140. //# sourceMappingURL=tsconfig.spec.js.map