PageRenderTime 39ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/tutorial/node_modules/typings-core/dist/utils/parse.spec.js

https://gitlab.com/adriancarayol/django-angular2
JavaScript | 303 lines | 302 code | 0 blank | 1 comment | 0 complexity | ffd8ace21ccf6d8a2dbc71cf4ac553c3 MD5 | raw file
  1. "use strict";
  2. var test = require('blue-tape');
  3. var path_1 = require('path');
  4. var parse_1 = require('./parse');
  5. var config_1 = require('./config');
  6. test('parse', function (t) {
  7. t.test('parse dependency', function (t) {
  8. t.test('parse filename', function (t) {
  9. var actual = parse_1.parseDependency('file:./foo/bar.d.ts');
  10. var expected = {
  11. raw: 'file:./foo/bar.d.ts',
  12. location: path_1.normalize('foo/bar.d.ts'),
  13. meta: {
  14. name: 'bar',
  15. path: path_1.normalize('foo/bar.d.ts')
  16. },
  17. type: 'file'
  18. };
  19. t.deepEqual(actual, expected);
  20. t.end();
  21. });
  22. t.test('parse filename relative', function (t) {
  23. var actual = parse_1.parseDependency('file:foo/bar.d.ts');
  24. var expected = {
  25. raw: 'file:foo/bar.d.ts',
  26. location: path_1.normalize('foo/bar.d.ts'),
  27. meta: {
  28. name: 'bar',
  29. path: path_1.normalize('foo/bar.d.ts')
  30. },
  31. type: 'file'
  32. };
  33. t.deepEqual(actual, expected);
  34. t.end();
  35. });
  36. t.test('parse npm', function (t) {
  37. var actual = parse_1.parseDependency('npm:foobar');
  38. var expected = {
  39. raw: 'npm:foobar',
  40. type: 'npm',
  41. meta: {
  42. name: 'foobar',
  43. path: 'package.json'
  44. },
  45. location: path_1.normalize('foobar/package.json')
  46. };
  47. t.deepEqual(actual, expected);
  48. t.end();
  49. });
  50. t.test('parse scoped npm packages', function (t) {
  51. var actual = parse_1.parseDependency('npm:@foo/bar');
  52. var expected = {
  53. raw: 'npm:@foo/bar',
  54. type: 'npm',
  55. meta: {
  56. name: '@foo/bar',
  57. path: 'package.json'
  58. },
  59. location: path_1.normalize('@foo/bar/package.json')
  60. };
  61. t.deepEqual(actual, expected);
  62. t.end();
  63. });
  64. t.test('parse npm filename', function (t) {
  65. var actual = parse_1.parseDependency('npm:typescript/bin/lib.es6.d.ts');
  66. var expected = {
  67. raw: 'npm:typescript/bin/lib.es6.d.ts',
  68. type: 'npm',
  69. meta: {
  70. name: 'typescript',
  71. path: path_1.normalize('bin/lib.es6.d.ts')
  72. },
  73. location: path_1.normalize('typescript/bin/lib.es6.d.ts')
  74. };
  75. t.deepEqual(actual, expected);
  76. t.end();
  77. });
  78. t.test('parse bower', function (t) {
  79. var actual = parse_1.parseDependency('bower:foobar');
  80. var expected = {
  81. raw: 'bower:foobar',
  82. type: 'bower',
  83. meta: {
  84. name: 'foobar',
  85. path: 'bower.json'
  86. },
  87. location: path_1.normalize('foobar/bower.json')
  88. };
  89. t.deepEqual(actual, expected);
  90. t.end();
  91. });
  92. t.test('parse bower filename', function (t) {
  93. var actual = parse_1.parseDependency('bower:foobar/' + config_1.CONFIG_FILE);
  94. var expected = {
  95. raw: 'bower:foobar/' + config_1.CONFIG_FILE,
  96. type: 'bower',
  97. meta: {
  98. name: 'foobar',
  99. path: config_1.CONFIG_FILE
  100. },
  101. location: path_1.normalize('foobar/' + config_1.CONFIG_FILE)
  102. };
  103. t.deepEqual(actual, expected);
  104. t.end();
  105. });
  106. t.test('parse github', function (t) {
  107. var actual = parse_1.parseDependency('github:foo/bar');
  108. var expected = {
  109. raw: 'github:foo/bar',
  110. type: 'github',
  111. meta: {
  112. name: undefined,
  113. org: 'foo',
  114. path: config_1.CONFIG_FILE,
  115. repo: 'bar',
  116. sha: 'master'
  117. },
  118. location: 'https://raw.githubusercontent.com/foo/bar/master/' + config_1.CONFIG_FILE
  119. };
  120. t.deepEqual(actual, expected);
  121. t.end();
  122. });
  123. t.test('parse github with sha and append config file', function (t) {
  124. var actual = parse_1.parseDependency('github:foo/bar#test');
  125. var expected = {
  126. raw: 'github:foo/bar#test',
  127. type: 'github',
  128. meta: {
  129. name: undefined,
  130. org: 'foo',
  131. path: config_1.CONFIG_FILE,
  132. repo: 'bar',
  133. sha: 'test'
  134. },
  135. location: 'https://raw.githubusercontent.com/foo/bar/test/' + config_1.CONFIG_FILE
  136. };
  137. t.deepEqual(actual, expected);
  138. t.end();
  139. });
  140. t.test('parse github paths to `.d.ts` files', function (t) {
  141. var actual = parse_1.parseDependency('github:foo/bar/typings/file.d.ts');
  142. var expected = {
  143. raw: 'github:foo/bar/typings/file.d.ts',
  144. type: 'github',
  145. meta: {
  146. name: 'file',
  147. org: 'foo',
  148. path: 'typings/file.d.ts',
  149. repo: 'bar',
  150. sha: 'master'
  151. },
  152. location: 'https://raw.githubusercontent.com/foo/bar/master/typings/file.d.ts'
  153. };
  154. t.deepEqual(actual, expected);
  155. t.end();
  156. });
  157. t.test('parse github paths to config file', function (t) {
  158. var actual = parse_1.parseDependency('github:foo/bar/src/' + config_1.CONFIG_FILE);
  159. var expected = {
  160. raw: 'github:foo/bar/src/' + config_1.CONFIG_FILE,
  161. type: 'github',
  162. meta: {
  163. name: undefined,
  164. org: 'foo',
  165. path: "src/" + config_1.CONFIG_FILE,
  166. repo: 'bar',
  167. sha: 'master'
  168. },
  169. location: 'https://raw.githubusercontent.com/foo/bar/master/src/' + config_1.CONFIG_FILE
  170. };
  171. t.deepEqual(actual, expected);
  172. t.end();
  173. });
  174. t.test('parse bitbucket', function (t) {
  175. var actual = parse_1.parseDependency('bitbucket:foo/bar');
  176. var expected = {
  177. raw: 'bitbucket:foo/bar',
  178. type: 'bitbucket',
  179. meta: {
  180. name: undefined,
  181. org: 'foo',
  182. path: config_1.CONFIG_FILE,
  183. repo: 'bar',
  184. sha: 'master'
  185. },
  186. location: 'https://bitbucket.org/foo/bar/raw/master/' + config_1.CONFIG_FILE
  187. };
  188. t.deepEqual(actual, expected);
  189. t.end();
  190. });
  191. t.test('parse bitbucket and append config file to path', function (t) {
  192. var actual = parse_1.parseDependency('bitbucket:foo/bar/dir');
  193. var expected = {
  194. raw: 'bitbucket:foo/bar/dir',
  195. type: 'bitbucket',
  196. meta: {
  197. name: undefined,
  198. org: 'foo',
  199. path: "dir/" + config_1.CONFIG_FILE,
  200. repo: 'bar',
  201. sha: 'master'
  202. },
  203. location: 'https://bitbucket.org/foo/bar/raw/master/dir/' + config_1.CONFIG_FILE
  204. };
  205. t.deepEqual(actual, expected);
  206. t.end();
  207. });
  208. t.test('parse bitbucket with sha', function (t) {
  209. var actual = parse_1.parseDependency('bitbucket:foo/bar#abc');
  210. var expected = {
  211. raw: 'bitbucket:foo/bar#abc',
  212. type: 'bitbucket',
  213. meta: {
  214. name: undefined,
  215. org: 'foo',
  216. path: config_1.CONFIG_FILE,
  217. repo: 'bar',
  218. sha: 'abc'
  219. },
  220. location: 'https://bitbucket.org/foo/bar/raw/abc/' + config_1.CONFIG_FILE
  221. };
  222. t.deepEqual(actual, expected);
  223. t.end();
  224. });
  225. t.test('parse url', function (t) {
  226. var actual = parse_1.parseDependency('http://example.com/foo/' + config_1.CONFIG_FILE);
  227. var expected = {
  228. raw: 'http://example.com/foo/' + config_1.CONFIG_FILE,
  229. type: 'http',
  230. meta: {},
  231. location: 'http://example.com/foo/' + config_1.CONFIG_FILE
  232. };
  233. t.deepEqual(actual, expected);
  234. t.end();
  235. });
  236. t.test('parse registry', function (t) {
  237. var actual = parse_1.parseDependency('registry:dt/node');
  238. var expected = {
  239. raw: 'registry:dt/node',
  240. type: 'registry',
  241. meta: { name: 'node', source: 'dt', tag: undefined, version: undefined },
  242. location: 'https://api.typings.org/entries/dt/node/versions/latest'
  243. };
  244. t.deepEqual(actual, expected);
  245. t.end();
  246. });
  247. t.test('parse registry with scoped package', function (t) {
  248. var actual = parse_1.parseDependency('registry:npm/@scoped/npm');
  249. var expected = {
  250. raw: 'registry:npm/@scoped/npm',
  251. type: 'registry',
  252. meta: { name: '@scoped/npm', source: 'npm', tag: undefined, version: undefined },
  253. location: 'https://api.typings.org/entries/npm/%40scoped%2Fnpm/versions/latest'
  254. };
  255. t.deepEqual(actual, expected);
  256. t.end();
  257. });
  258. t.test('parse registry with tag', function (t) {
  259. var actual = parse_1.parseDependency('registry:npm/dep#3.0.0-2016');
  260. var expected = {
  261. raw: 'registry:npm/dep#3.0.0-2016',
  262. type: 'registry',
  263. meta: { name: 'dep', source: 'npm', tag: '3.0.0-2016', version: undefined },
  264. location: 'https://api.typings.org/entries/npm/dep/tags/3.0.0-2016'
  265. };
  266. t.deepEqual(actual, expected);
  267. t.end();
  268. });
  269. t.test('parse registry with version', function (t) {
  270. var actual = parse_1.parseDependency('registry:npm/dep@^4.0');
  271. var expected = {
  272. raw: 'registry:npm/dep@^4.0',
  273. type: 'registry',
  274. meta: { name: 'dep', source: 'npm', tag: undefined, version: '^4.0' },
  275. location: 'https://api.typings.org/entries/npm/dep/versions/%5E4.0/latest'
  276. };
  277. t.deepEqual(actual, expected);
  278. t.end();
  279. });
  280. t.test('expand registry with default source', function (t) {
  281. var actual = parse_1.expandRegistry('domready');
  282. var expected = 'registry:npm/domready';
  283. t.deepEqual(actual, expected);
  284. t.end();
  285. });
  286. t.test('expand registry with provided source', function (t) {
  287. var actual = parse_1.expandRegistry('env~atom');
  288. var expected = 'registry:env/atom';
  289. t.deepEqual(actual, expected);
  290. t.end();
  291. });
  292. t.test('unknown scheme', function (t) {
  293. t.throws(function () { return parse_1.parseDependency('random:fake/dep'); }, /Unknown dependency: /);
  294. t.end();
  295. });
  296. });
  297. t.test('resolve dependency', function (t) {
  298. t.equal(parse_1.resolveDependency('github:foo/bar/baz/x.d.ts', '../lib/test.d.ts'), 'github:foo/bar/lib/test.d.ts');
  299. t.equal(parse_1.resolveDependency('http://example.com/foo/bar.d.ts', 'x.d.ts'), 'http://example.com/foo/x.d.ts');
  300. t.end();
  301. });
  302. });
  303. //# sourceMappingURL=parse.spec.js.map