fetch.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*global describe, before, it */
  2. var fs = require('fs');
  3. var path = require('path');
  4. var util = require('util');
  5. var events = require('events');
  6. var assert = require('assert');
  7. var generators = require('..');
  8. describe('yeoman.generators.Base', function () {
  9. // increase timeout to 15s for this suite (slow connections like mine
  10. // needs that)
  11. this.timeout(50000);
  12. before(generators.test.before(path.join(__dirname, 'temp')));
  13. before(function () {
  14. function Dummy() {
  15. generators.Base.apply(this, arguments);
  16. }
  17. util.inherits(Dummy, generators.Base);
  18. Dummy.prototype.test = function () {
  19. this.shouldRun = true;
  20. };
  21. this.env = generators();
  22. this.dummy = new Dummy({
  23. env: this.env,
  24. resolved: 'test:fetch'
  25. });
  26. this.Dummy = Dummy;
  27. });
  28. it('generator.bowerInstall(name)', function (done) {
  29. this.dummy.bowerInstall('backbone', function (err) {
  30. fs.stat('bower_components/backbone', done);
  31. });
  32. });
  33. describe('generator.tarball(tarball, destination, cb)', function () {
  34. it('should allow the fecthing / untar of a given tarball, at the given location', function (done) {
  35. this.dummy.tarball('https://github.com/yeoman/yeoman.io/tarball/gh-pages', './yeoman.io/', function (err) {
  36. if (err) {
  37. return done(err);
  38. }
  39. fs.stat('./yeoman.io/index.html', done);
  40. });
  41. });
  42. });
  43. describe('generator.fetch(url, destination, cb)', function () {
  44. it('should allow the fething of a single file', function (done) {
  45. this.dummy.fetch('https://raw.github.com/yeoman/generators/master/README.md', './some/path/README.md', function (err) {
  46. if (err) {
  47. return done(err);
  48. }
  49. fs.stat('./some/path/README.md', done);
  50. });
  51. });
  52. });
  53. describe('generator.remote(user, repo, branch, cb)', function () {
  54. it('should remotely fetch a package on github', function (done) {
  55. this.dummy.remote('yeoman', 'generators', done);
  56. });
  57. it('should have the result cached internally into a `_cache` folder', function (done) {
  58. fs.stat(path.join(this.dummy.cacheRoot(), 'yeoman/generators/master'), done);
  59. });
  60. it('should invoke `cb` with a remote object to interract with the downloaded package', function (done) {
  61. this.dummy.remote('yeoman', 'generators', function (err, remote) {
  62. if (err) {
  63. return done(err);
  64. }
  65. ['copy', 'template', 'directory'].forEach(function (method) {
  66. assert.equal(typeof remote[method], 'function');
  67. });
  68. done();
  69. });
  70. });
  71. });
  72. });