1
1
import execa from 'execa' ;
2
- // Disable ftb
3
- // import {git} from '@commitlint/test';
4
- // import which from 'which';
2
+ import { git } from '@commitlint/test' ;
5
3
6
- // Disable ftb
7
- // const NODE_BIN = which.sync('node');
8
4
const bin = require . resolve ( '../lib/cli.js' ) ;
9
5
10
- // Disable ftb
11
- // const TRAVIS_COMMITLINT_BIN = require.resolve('../fixtures/commitlint');
12
- // const TRAVIS_COMMITLINT_GIT_BIN = require.resolve('../fixtures/git');
13
- // const TRAVIS_BRANCH = 'TRAVIS_BRANCH';
14
- // const TRAVIS_COMMIT = 'TRAVIS_COMMIT';
6
+ const TRAVIS_COMMITLINT_BIN = require . resolve ( '../fixtures/commitlint' ) ;
7
+ const TRAVIS_COMMITLINT_GIT_BIN = require . resolve ( '../fixtures/git' ) ;
8
+
9
+ const validBaseEnv = {
10
+ TRAVIS : true ,
11
+ CI : true ,
12
+ TRAVIS_COMMIT : 'TRAVIS_COMMIT' ,
13
+ TRAVIS_COMMITLINT_BIN : TRAVIS_COMMITLINT_BIN ,
14
+ TRAVIS_COMMITLINT_GIT_BIN : TRAVIS_COMMITLINT_GIT_BIN ,
15
+ TRAVIS_COMMIT_RANGE : 'TRAVIS_COMMIT_A.TRAVIS_COMMIT_B' ,
16
+ TRAVIS_EVENT_TYPE : 'TRAVIS_EVENT_TYPE' ,
17
+ TRAVIS_REPO_SLUG : 'TRAVIS_REPO_SLUG' ,
18
+ TRAVIS_PULL_REQUEST_SLUG : 'TRAVIS_PULL_REQUEST_SLUG'
19
+ } ;
15
20
16
21
const cli = async ( config = { } ) => {
17
22
try {
@@ -43,128 +48,53 @@ test('should throw when on travis ci, but env vars are missing', async () => {
43
48
) ;
44
49
} ) ;
45
50
46
- /*
47
- test('should call git with expected args on shallow repo', async () => {
51
+ test ( 'should call git with expected args' , async ( ) => {
48
52
const cwd = await git . clone (
49
53
'https://github.com/conventional-changelog/commitlint.git' ,
50
- ['--depth=10']
51
- );
52
-
53
- const env = {
54
- TRAVIS: true,
55
- CI: true,
56
- TRAVIS_BRANCH,
57
- TRAVIS_COMMIT,
58
- TRAVIS_COMMITLINT_BIN,
54
+ [ '--depth=10' ] ,
55
+ __dirname ,
59
56
TRAVIS_COMMITLINT_GIT_BIN
60
- } ;
57
+ ) ;
61
58
62
- const result = await cli({cwd, env});
59
+ const result = await cli ( {
60
+ cwd,
61
+ env : validBaseEnv
62
+ } ) ;
63
63
const invocations = await getInvocations ( result . stdout ) ;
64
- t.is(invocations.length, 7);
65
-
66
- const [
67
- stash,
68
- branches,
69
- unshallow,
70
- checkout,
71
- back,
72
- pop,
73
- commilint
74
- ] = invocations;
75
-
76
- t.deepEqual(stash, [NODE_BIN, TRAVIS_COMMITLINT_GIT_BIN, 'stash']);
77
- t.deepEqual(branches, [
78
- NODE_BIN,
79
- TRAVIS_COMMITLINT_GIT_BIN,
80
- 'remote',
81
- 'set-branches',
82
- 'origin',
83
- TRAVIS_BRANCH
84
- ]);
85
- t.deepEqual(unshallow, [
86
- NODE_BIN,
87
- TRAVIS_COMMITLINT_GIT_BIN,
88
- 'fetch',
89
- '--unshallow',
90
- '--quiet'
91
- ]);
92
- t.deepEqual(checkout, [
93
- NODE_BIN,
94
- TRAVIS_COMMITLINT_GIT_BIN,
95
- 'checkout',
96
- TRAVIS_BRANCH,
97
- '--quiet'
98
- ]);
99
- t.deepEqual(back, [
100
- NODE_BIN,
101
- TRAVIS_COMMITLINT_GIT_BIN,
102
- 'checkout',
103
- '-',
104
- '--quiet'
105
- ]);
106
- t.deepEqual(pop, [NODE_BIN, TRAVIS_COMMITLINT_GIT_BIN, 'stash', 'pop']);
107
- t.deepEqual(commilint, [
108
- NODE_BIN,
109
- TRAVIS_COMMITLINT_BIN,
110
- '--from',
111
- TRAVIS_BRANCH,
112
- '--to',
113
- TRAVIS_COMMIT
114
- ]);
64
+ expect ( invocations . length ) . toBe ( 3 ) ;
65
+
66
+ const [ stash , branches , commilint ] = invocations ;
67
+
68
+ expect ( stash ) . toEqual ( [ 'git' , 'stash' , '-k' , '-u' , '--quiet' ] ) ;
69
+ expect ( branches ) . toEqual ( [ 'git' , 'stash' , 'pop' , '--quiet' ] ) ;
70
+ expect ( commilint ) . toEqual ( [ 'commitlint' ] ) ;
115
71
} ) ;
116
72
117
- test('should call git with expected args on unshallow repo ', async () => {
73
+ test ( 'should call git with expected args on pull_request ' , async ( ) => {
118
74
const cwd = await git . clone (
119
- 'https://github.com/conventional-changelog/commitlint.git'
120
- );
121
-
122
- const env = {
123
- TRAVIS: true,
124
- CI: true,
125
- TRAVIS_BRANCH,
126
- TRAVIS_COMMIT,
127
- TRAVIS_COMMITLINT_BIN,
75
+ 'https://github.com/conventional-changelog/commitlint.git' ,
76
+ [ '--depth=10' ] ,
77
+ __dirname ,
128
78
TRAVIS_COMMITLINT_GIT_BIN
129
- } ;
79
+ ) ;
130
80
131
- const result = await cli({cwd, env});
81
+ const result = await cli ( {
82
+ cwd,
83
+ env : { ...validBaseEnv , TRAVIS_EVENT_TYPE : 'pull_request' }
84
+ } ) ;
132
85
const invocations = await getInvocations ( result . stdout ) ;
133
- t.is(invocations.length, 6);
134
-
135
- const [stash, branches, checkout, back, pop, commilint] = invocations;
136
-
137
- t.deepEqual(stash, [NODE_BIN, TRAVIS_COMMITLINT_GIT_BIN, 'stash']);
138
- t.deepEqual(branches, [
139
- NODE_BIN,
140
- TRAVIS_COMMITLINT_GIT_BIN,
141
- 'remote',
142
- 'set-branches',
143
- 'origin',
144
- TRAVIS_BRANCH
145
- ]);
146
- t.deepEqual(checkout, [
147
- NODE_BIN,
148
- TRAVIS_COMMITLINT_GIT_BIN,
149
- 'checkout',
150
- TRAVIS_BRANCH,
151
- '--quiet'
152
- ]);
153
- t.deepEqual(back, [
154
- NODE_BIN,
155
- TRAVIS_COMMITLINT_GIT_BIN,
156
- 'checkout',
157
- '-',
158
- '--quiet'
159
- ]);
160
- t.deepEqual(pop, [NODE_BIN, TRAVIS_COMMITLINT_GIT_BIN, 'stash', 'pop']);
161
- t.deepEqual(commilint, [
162
- NODE_BIN,
163
- TRAVIS_COMMITLINT_BIN,
86
+ expect ( invocations . length ) . toBe ( 3 ) ;
87
+
88
+ const [ stash , branches , commilint ] = invocations ;
89
+
90
+ expect ( stash ) . toEqual ( [ 'git' , 'stash' , '-k' , '-u' , '--quiet' ] ) ;
91
+ expect ( branches ) . toEqual ( [ 'git' , 'stash' , 'pop' , '--quiet' ] ) ;
92
+ expect ( commilint ) . toEqual ( [
93
+ 'commitlint' ,
164
94
'--from' ,
165
- TRAVIS_BRANCH ,
95
+ 'TRAVIS_COMMIT_A' ,
166
96
'--to' ,
167
- TRAVIS_COMMIT
97
+ 'TRAVIS_COMMIT_B'
168
98
] ) ;
169
99
} ) ;
170
100
@@ -182,4 +112,3 @@ function getInvocations(stdout) {
182
112
. filter ( Boolean )
183
113
) ;
184
114
}
185
- */
0 commit comments