|
1 | 1 | var fs = require('fs'); |
2 | 2 | var rimraf = require('rimraf'); |
3 | | -var ncp = require('ncp').ncp; |
4 | 3 | var exec = require('child_process').exec; |
5 | 4 | var path = require('path'); |
6 | 5 | var async = require('async'); |
7 | 6 |
|
8 | 7 | var testFiles = ['blob','difflist','oid','repo','tree_entry','commit','reference','revwalk','tree']; |
9 | 8 |
|
10 | 9 | function setupReposCache(cb) { |
11 | | - fs.mkdir('.reposCache',function() { |
12 | | - async.series([ |
13 | | - function empty(cb) { exec('git init .reposCache/empty',cb); }, |
14 | | - function workdir(cb) { exec('git clone https://github.com/nodegit/nodegit.git .reposCache/workdir',cb); }, |
15 | | - function nonrepo(cb) { |
16 | | - fs.mkdir('.reposCache/nonrepo',function() { |
17 | | - fs.writeFile('.reposCache/nonrepo/file.txt','This is a bogus file',cb); |
18 | | - }); |
19 | | - } |
20 | | - ],cb); |
21 | | - }); |
| 10 | + fs.mkdir('repos',function() { |
| 11 | + async.series([ |
| 12 | + function empty(cb) { exec('git init repos/empty',function() { cb(); }); }, |
| 13 | + function workdir(cb) { exec('git clone https://github.com/nodegit/nodegit.git repos/workdir',function() { cb(); }); }, |
| 14 | + function nonrepo(cb) { |
| 15 | + fs.mkdir('repos/nonrepo',function() { |
| 16 | + fs.writeFile('repos/nonrepo/file.txt','This is a bogus file',function() { |
| 17 | + cb(); |
| 18 | + }); |
| 19 | + }); |
| 20 | + } |
| 21 | + ],function() { |
| 22 | + cb(); |
| 23 | + }); |
| 24 | + }); |
22 | 25 | } |
23 | 26 |
|
24 | | -module.exports = { |
25 | | - setUp: function(cb) { |
26 | | - fs.exists('.reposCache',function(exists) { |
27 | | - if (exists) { |
28 | | - ncp('.reposCache','repos',cb); |
29 | | - } else { |
30 | | - setupReposCache(function(err) { |
31 | | - if (err) { return cb(err); } |
32 | | - ncp('.reposCache','repos',cb); |
33 | | - }); |
34 | | - } |
35 | | - }); |
36 | | - }, |
37 | | - tearDown: function(cb) { |
38 | | - rimraf('repos',cb); |
39 | | - } |
| 27 | +exports.setUp = function(cb) { |
| 28 | + fs.exists('.reposCache', function(exists) { |
| 29 | + if (!exists) { |
| 30 | + setupReposCache(function(err) { |
| 31 | + cb(); |
| 32 | + }); |
| 33 | + } |
| 34 | + }); |
40 | 35 | }; |
41 | 36 |
|
42 | | -for(var i in testFiles) { |
43 | | - var testFile = testFiles[i]; |
44 | | - module.exports[testFile] = require('./'+testFile); |
45 | | -} |
| 37 | +Object.keys(testFiles).forEach(function(fileName) { |
| 38 | + var testFile = testFiles[fileName] |
| 39 | + exports[testFile] = require('./' + testFile); |
| 40 | +}); |
0 commit comments