|
| 1 | +var assert = require("assert"); |
| 2 | +var path = require("path"); |
| 3 | +var local = path.join.bind(path, __dirname); |
| 4 | +var promisify = require("promisify-node"); |
| 5 | +var fse = promisify(require("fs-extra")); |
| 6 | + |
| 7 | +describe("Tree", function() { |
| 8 | + var RepoUtils = require("../utils/repository_setup"); |
| 9 | + |
| 10 | + var repoPath = local("../repos/tree"); |
| 11 | + |
| 12 | + beforeEach(function() { |
| 13 | + var test = this; |
| 14 | + return RepoUtils.createRepository(repoPath) |
| 15 | + .then(function(repo) { |
| 16 | + test.repository = repo; |
| 17 | + }); |
| 18 | + }); |
| 19 | + |
| 20 | + after(function() { |
| 21 | + return fse.remove(repoPath); |
| 22 | + }); |
| 23 | + |
| 24 | + it("walks its entries and returns the same entries on both progress and end", |
| 25 | + function() { |
| 26 | + var repo = this.repository; |
| 27 | + var progressEntries = []; |
| 28 | + var endEntries; |
| 29 | + |
| 30 | + return RepoUtils.commitFileToRepo(repo, "test.txt", "") |
| 31 | + .then(function(commit) { |
| 32 | + return RepoUtils.commitFileToRepo(repo, "foo/bar.txt", "", commit); |
| 33 | + }) |
| 34 | + .then(function(commit) { |
| 35 | + return commit.getTree(); |
| 36 | + }) |
| 37 | + .then(function(tree) { |
| 38 | + assert(tree); |
| 39 | + |
| 40 | + return new Promise(function (resolve, reject) { |
| 41 | + var walker = tree.walk(); |
| 42 | + |
| 43 | + walker.on("entry", function(entry) { |
| 44 | + progressEntries.push(entry); |
| 45 | + }); |
| 46 | + walker.on("end", function(entries) { |
| 47 | + endEntries = entries; |
| 48 | + resolve(); |
| 49 | + }); |
| 50 | + walker.on("error", reject); |
| 51 | + |
| 52 | + walker.start(); |
| 53 | + }); |
| 54 | + }) |
| 55 | + .then(function() { |
| 56 | + assert(progressEntries.length); |
| 57 | + assert(endEntries && endEntries.length); |
| 58 | + |
| 59 | + assert.equal( |
| 60 | + progressEntries.length, endEntries.length, |
| 61 | + "Different number of progress entries and end entries" |
| 62 | + ); |
| 63 | + |
| 64 | + function getEntryPath(entry) { |
| 65 | + return entry.path(); |
| 66 | + } |
| 67 | + |
| 68 | + var progressFilePaths = progressEntries.map(getEntryPath).sort(); |
| 69 | + var endFilePaths = endEntries.map(getEntryPath); |
| 70 | + |
| 71 | + assert.deepEqual( |
| 72 | + progressFilePaths.sort(), endFilePaths.sort(), |
| 73 | + "progress entries do not match end entries" |
| 74 | + ); |
| 75 | + }); |
| 76 | + }); |
| 77 | +}); |
0 commit comments