index.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. (function (factory) {
  2. if (typeof module === 'object' && typeof module.exports === 'object') {
  3. var v = factory(require, exports); if (v !== undefined) module.exports = v;
  4. }
  5. else if (typeof define === 'function' && define.amd) {
  6. define(["require", "exports", 'intern!object', 'intern/chai!assert', 'intern/dojo/node!../../index', 'intern/dojo/node!fs'], factory);
  7. }
  8. })(function (require, exports) {
  9. "use strict";
  10. var registerSuite = require('intern!object');
  11. var assert = require('intern/chai!assert');
  12. var index_1 = require('intern/dojo/node!../../index');
  13. var fs = require('intern/dojo/node!fs');
  14. registerSuite({
  15. name: 'index',
  16. 'api': function () {
  17. assert.isFunction(index_1.default, 'generate should be a function');
  18. },
  19. 'generate': function () {
  20. return index_1.default({
  21. name: 'foo',
  22. baseDir: 'tests/support/foo',
  23. files: ['index.ts'],
  24. out: 'tmp/foo.d.ts'
  25. }).then(function () {
  26. var contents = fs.readFileSync('tmp/foo.d.ts', { encoding: 'utf8' });
  27. assert(contents, 'foo.d.ts should exist and have contents');
  28. assert.include(contents, "module 'foo/index'");
  29. assert.include(contents, "module 'foo/Bar'");
  30. });
  31. },
  32. 'no files': function () {
  33. return index_1.default({
  34. name: 'foo',
  35. baseDir: 'tests/support/foo',
  36. out: 'tmp/foo.nofiles.d.ts'
  37. }).then(function () {
  38. var contents = fs.readFileSync('tmp/foo.nofiles.d.ts', { encoding: 'utf8' });
  39. assert(contents, 'foo.nofiles.d.ts should exist and have contents');
  40. assert.include(contents, "module 'foo/index'");
  41. assert.include(contents, "module 'foo/Bar'");
  42. });
  43. },
  44. 'project': function () {
  45. return index_1.default({
  46. name: 'foo',
  47. project: 'tests/support/foo',
  48. out: 'tmp/foo.config.d.ts'
  49. }).then(function () {
  50. var contents = fs.readFileSync('tmp/foo.config.d.ts', { encoding: 'utf8' });
  51. assert(contents, 'foo.config.d.ts should exist and have contents');
  52. assert.include(contents, "module 'foo/index'");
  53. assert.include(contents, "module 'foo/Bar'");
  54. });
  55. },
  56. 'es6 main module': function () {
  57. return index_1.default({
  58. name: 'foo',
  59. project: 'tests/support/foo-es6',
  60. out: 'tmp/foo.es6.d.ts',
  61. main: 'index.ts'
  62. }).then(function () {
  63. var contents = fs.readFileSync('tmp/foo.es6.d.ts', { encoding: 'utf8' });
  64. assert(contents, 'foo.es6.d.ts should exist and have contents');
  65. // assert.include(contents, `module 'foo/index'`);
  66. // assert.include(contents, `module 'foo/Bar'`);
  67. });
  68. }
  69. });
  70. });