制造unit testing的git回购

我在节点中的function应该返回最近修改(1天)的文件列表中的git。 该function基本上做类似的东西

git diff --name-only $(git rev-list -n1 --before="1 day ago" HEAD) 

要么

 git log --since="1.day" --name-only --oneline 

所以,我想validation函数做它应该做的。 所以,在摩卡testing中,我有:

  var tmp = require('tmp'); describe('Git test', function() { var today = new Date(); var threedays = new Date(); var yesterday = new Date(); threedays.setDate(today.getDate() - 3); yesterday.setDate(today.getDate() - 1); beforeEach(function(done) { tmp.dir({ template: '/tmp/test-XXXXXX', unsafeCleanup: true }, function _tempDirCreated(err, path) { if (err) { throw err; } repo = path; sh.exec('cd ' + repo + '; git init'); sh.exec('touch ' + repo + '/file1'); sh.exec('touch ' + repo + '/file2'); //sh.exec('touch ' + repo + '/file3'); //sh.exec('cd ' + repo + '; git add file3; GIT_COMMITTER_DATE="' + // threedays.toISOString() + // '" git commit -m "file3" file3 --date ' + threedays.toISOString()); sh.exec('cd ' + repo + '; git add file2; GIT_COMMITTER_DATE="' + yesterday.toISOString() + '" git commit -m "FILE2" file2 --date ' + yesterday.toISOString()); sh.exec('cd ' + repo + '; git add file1; git commit -m "FILE1" file1'); sessionConfig = new Session(repo, repo); done(); } ); }); 

我注意到的是,在我创build了git repo之后,只返回最近修改过的文件的git命令似乎没有返回结果。 但是,如果我添加file3(注释部分),该命令将工作。

我想最终创build的是一个具有旧提交和新提交的回购以及仅返回最近修改的文件的命令。 任何build议感激!

事实certificate,在转换为ISOstring时,获取“昨天”在处理时区时遇到了一些问题。

我修改我的昨天是午夜,现在一切正常。