index.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. var assert = require('assert')
  2. var download = require('..')
  3. var read = require('fs-readdir-recursive')
  4. var rm = require('rimraf').sync
  5. describe('download-git-repo', function () {
  6. this.timeout(20000)
  7. beforeEach(function () {
  8. rm('test/tmp')
  9. })
  10. var filter = function (x) {
  11. return x[0] !== '.' || x === '.git'
  12. }
  13. var runStyle = function (type, style) {
  14. var clone = false
  15. if (style === 'clones') clone = true
  16. it(style + ' master branch by default', function (done) {
  17. download(type + ':flipxfx/download-git-repo-fixture', 'test/tmp', { clone: clone }, function (err) {
  18. if (err) return done(err)
  19. var actual = read('test/tmp', filter)
  20. var expected = read('test/fixtures/' + type + '/master')
  21. assert.deepEqual(actual, expected)
  22. done()
  23. })
  24. })
  25. it(style + ' a branch', function (done) {
  26. download(type + ':flipxfx/download-git-repo-fixture#my-branch', 'test/tmp', { clone: clone }, function (err) {
  27. if (err) return done(err)
  28. var actual = read('test/tmp', filter)
  29. var expected = read('test/fixtures/' + type + '/my-branch')
  30. assert.deepEqual(actual, expected)
  31. done()
  32. })
  33. })
  34. it(style + ' a branch with slashes', function (done) {
  35. download(type + ':flipxfx/download-git-repo-fixture#my/branch/with/slashes', 'test/tmp', { clone: clone }, function (err) {
  36. if (err) return done(err)
  37. var actual = read('test/tmp', filter)
  38. var expected = read('test/fixtures/' + type + '/my-branch-with-slashes')
  39. assert.deepEqual(actual, expected)
  40. done()
  41. })
  42. })
  43. it(style + ' master branch with specific origin', function (done) {
  44. download(type + ':' + type + '.com:flipxfx/download-git-repo-fixture', 'test/tmp', { clone: clone }, function (err) {
  45. if (err) return done(err)
  46. var actual = read('test/tmp', filter)
  47. var expected = read('test/fixtures/' + type + '/master')
  48. assert.deepEqual(actual, expected)
  49. done()
  50. })
  51. })
  52. it(style + ' master branch with specific origin and protocol', function (done) {
  53. download(type + ':https://' + type + '.com:flipxfx/download-git-repo-fixture', 'test/tmp', { clone: clone }, function (err) {
  54. if (err) return done(err)
  55. var actual = read('test/tmp', filter)
  56. var expected = read('test/fixtures/' + type + '/master')
  57. assert.deepEqual(actual, expected)
  58. done()
  59. })
  60. })
  61. }
  62. var runType = function (type) {
  63. runStyle(type, 'downloads')
  64. runStyle(type, 'clones')
  65. it('clones master branch with specific origin without type', function (done) {
  66. download(type + '.com:flipxfx/download-git-repo-fixture', 'test/tmp', { clone: true }, function (err) {
  67. if (err) return done(err)
  68. var actual = read('test/tmp', filter)
  69. var expected = read('test/fixtures/' + type + '/master')
  70. assert.deepEqual(actual, expected)
  71. done()
  72. })
  73. })
  74. it('clones master branch with specific origin and protocol without type', function (done) {
  75. download('https://' + type + '.com:flipxfx/download-git-repo-fixture', 'test/tmp', { clone: true }, function (err) {
  76. if (err) return done(err)
  77. var actual = read('test/tmp', filter)
  78. var expected = read('test/fixtures/' + type + '/master')
  79. assert.deepEqual(actual, expected)
  80. done()
  81. })
  82. })
  83. }
  84. describe('via github', function () {
  85. runType('github')
  86. it('downloads from github by default', function (done) {
  87. download('flipxfx/download-git-repo-fixture', 'test/tmp', function (err) {
  88. if (err) return done(err)
  89. var actual = read('test/tmp', filter)
  90. var expected = read('test/fixtures/github/master')
  91. assert.deepEqual(actual, expected)
  92. done()
  93. })
  94. })
  95. })
  96. describe('via gitlab', function () {
  97. runType('gitlab')
  98. })
  99. describe('via bitbucket', function () {
  100. runType('bitbucket')
  101. })
  102. describe('via direct', function () {
  103. it('downloads master branch', function (done) {
  104. download('direct:https://gitlab.com/flipxfx/download-git-repo-fixture/repository/archive.zip', 'test/tmp', function (err) {
  105. var actual = read('test/tmp', filter)
  106. var expected = read('test/fixtures/gitlab/master')
  107. assert.deepEqual(actual, expected)
  108. done()
  109. })
  110. })
  111. it('downloads a branch', function (done) {
  112. download('direct:https://gitlab.com/flipxfx/download-git-repo-fixture/repository/archive.zip?ref=my-branch', 'test/tmp', function (err) {
  113. var actual = read('test/tmp', filter)
  114. var expected = read('test/fixtures/gitlab/my-branch')
  115. assert.deepEqual(actual, expected)
  116. done()
  117. })
  118. })
  119. it('clones master branch', function (done) {
  120. download('direct:https://gitlab.com/flipxfx/download-git-repo-fixture.git', 'test/tmp', { clone: true }, function (err) {
  121. var actual = read('test/tmp', filter)
  122. var expected = read('test/fixtures/gitlab/master')
  123. assert.deepEqual(actual, expected)
  124. done()
  125. })
  126. })
  127. it('clones a branch', function (done) {
  128. download('direct:https://gitlab.com/flipxfx/download-git-repo-fixture.git#my-branch', 'test/tmp', { clone: true }, function (err) {
  129. var actual = read('test/tmp', filter)
  130. var expected = read('test/fixtures/gitlab/my-branch')
  131. assert.deepEqual(actual, expected)
  132. done()
  133. })
  134. })
  135. })
  136. })