-
-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathgit-repo-age.js
72 lines (57 loc) · 1.99 KB
/
git-repo-age.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import test from 'ava';
import sinon from 'sinon';
import lint from '../_lint.js';
import gitRepoAge from '../../rules/git-repo-age.js';
const config = {
plugins: [
gitRepoAge,
],
};
let sandbox;
test.beforeEach(() => {
sandbox = sinon.createSandbox();
});
test.afterEach.always(() => {
sandbox.restore();
});
test.serial.failing('git-repo-age - error invalid git repo', async t => {
const execaStub = sandbox.stub(gitRepoAge.execa, 'stdout');
execaStub
.throws(new Error('"git" command not found'));
const messages = await lint({config, filename: 'test/fixtures/git-repo-age/0.md'});
t.deepEqual(messages, [
{
line: null,
ruleId: 'awesome-git-repo-age',
message: 'Awesome list must reside in a valid deep-cloned Git repository (see https://github.com/sindresorhus/awesome-lint#tip for more information)',
},
]);
});
test.serial.failing('git-repo-age - error repo is not old enough', async t => {
const execaStub = sandbox.stub(gitRepoAge.execa, 'stdout');
execaStub
.withArgs('git', ['rev-list', '--max-parents=0', 'HEAD'])
.returns('14fc116c8ff54fc8a13c4a3b7527eb95fb87d400');
execaStub
.withArgs('git', ['show', '-s', '--format=%ci', '14fc116c8ff54fc8a13c4a3b7527eb95fb87d400'])
.returns('2030-08-01 12:55:53 +0200');
const messages = await lint({config, filename: 'test/fixtures/git-repo-age/0.md'});
t.deepEqual(messages, [
{
line: null,
ruleId: 'awesome-git-repo-age',
message: 'Git repository must be at least 30 days old',
},
]);
});
test.serial.failing('git-repo-age - valid repo is old enough', async t => {
const execaStub = sandbox.stub(gitRepoAge.execa, 'stdout');
execaStub
.withArgs('git', ['rev-list', '--max-parents=0', 'HEAD'])
.returns('14fc116c8ff54fc8a13c4a3b7527eb95fb87d400');
execaStub
.withArgs('git', ['show', '-s', '--format=%ci', '14fc116c8ff54fc8a13c4a3b7527eb95fb87d400'])
.returns('2016-08-01 12:55:53 +0200');
const messages = await lint({config, filename: 'test/fixtures/git-repo-age/0.md'});
t.deepEqual(messages, []);
});