1
- // Disable ftb
2
- // const os = require('os');
3
- // const {git} = require('@commitlint/test');
4
- import test from 'ava' ;
5
1
import execa from 'execa' ;
6
2
// Disable ftb
7
- // const which = require('which');
3
+ // import {git} from '@commitlint/test';
4
+ // import which from 'which';
8
5
9
6
// Disable ftb
10
7
// const NODE_BIN = which.sync('node');
11
- const BIN = require . resolve ( '../lib/cli.js' ) ;
8
+ const bin = require . resolve ( '../lib/cli.js' ) ;
12
9
13
10
// Disable ftb
14
11
// const TRAVIS_COMMITLINT_BIN = require.resolve('../fixtures/commitlint');
15
12
// const TRAVIS_COMMITLINT_GIT_BIN = require.resolve('../fixtures/git');
16
13
// const TRAVIS_BRANCH = 'TRAVIS_BRANCH';
17
14
// const TRAVIS_COMMIT = 'TRAVIS_COMMIT';
18
15
19
- const bin = async ( config = { } ) => {
16
+ const cli = async ( config = { } ) => {
20
17
try {
21
- return await execa ( BIN , Object . assign ( { extendEnv : false } , config ) ) ;
18
+ return await execa ( bin , [ ] , config ) ;
22
19
} catch ( err ) {
23
- throw new Error ( [ err . stdout , err . stderr ] . join ( '\n' ) ) ;
20
+ return Promise . reject ( [ err . stdout , err . stderr ] . join ( '\n' ) ) ;
24
21
}
25
22
} ;
26
23
27
- test ( 'should throw when not on travis ci' , async t => {
24
+ test ( 'should throw when not on travis ci' , async ( ) => {
28
25
const env = {
29
26
CI : false ,
30
27
TRAVIS : false
31
28
} ;
32
29
33
- await t . throwsAsync (
34
- bin ( { env} ) ,
35
- / @ c o m m i t l i n t \/ t r a v i s - c l i i s i n t e n d e d t o b e u s e d o n T r a v i s C I /
30
+ await expect ( cli ( { env} ) ) . rejects . toContain (
31
+ '@commitlint/travis-cli is intended to be used on Travis CI'
36
32
) ;
37
33
} ) ;
38
34
39
- /* Test.failing(
40
- 'should throw when on travis ci, but env vars are missing',
41
- async t => {
42
- const env = {
43
- TRAVIS: true,
44
- CI: true
45
- };
35
+ test ( 'should throw when on travis ci, but env vars are missing' , async ( ) => {
36
+ const env = {
37
+ TRAVIS : true ,
38
+ CI : true
39
+ } ;
46
40
47
- await t.throwsAsync(bin({env}), /TRAVIS_COMMIT, TRAVIS_BRANCH/);
48
- }
49
- ); */
41
+ await expect ( cli ( { env} ) ) . rejects . toContain (
42
+ 'TRAVIS_COMMIT, TRAVIS_COMMIT_RANGE, TRAVIS_EVENT_TYPE, TRAVIS_REPO_SLUG, TRAVIS_PULL_REQUEST_SLUG'
43
+ ) ;
44
+ } ) ;
50
45
51
- test ( 'should throw when on travis ci, but TRAVIS_COMMIT is missing' , async t => {
46
+ test ( 'should throw when on travis ci, but TRAVIS_COMMIT is missing' , async ( ) => {
52
47
const env = {
53
48
TRAVIS : true ,
54
49
CI : true
55
50
} ;
56
51
57
- await t . throwsAsync ( bin ( { env} ) , / T R A V I S _ C O M M I T / ) ;
52
+ await expect ( cli ( { env} ) ) . rejects . toContain ( ' TRAVIS_COMMIT' ) ;
58
53
} ) ;
59
54
60
- /* Test.failing(
61
- 'should throw when on travis ci, but TRAVIS_BRANCH is missing',
62
- async t => {
63
- const env = {
64
- TRAVIS: true,
65
- CI: true
66
- };
67
-
68
- await t.throwsAsync(bin({env}), /TRAVIS_BRANCH/);
69
- }
70
- );
55
+ test ( 'should throw when on travis ci, but TRAVIS_BRANCH is missing' , async ( ) => {
56
+ const env = {
57
+ TRAVIS : true ,
58
+ CI : true
59
+ } ;
71
60
72
- test.failing('should call git with expected args on shallow repo', async t => {
73
- if (os.platform() === 'win32') {
74
- t.pass();
75
- return;
76
- }
61
+ await expect ( cli ( { env} ) ) . rejects . toContain ( 'TRAVIS_BRANCH' ) ;
62
+ } ) ;
77
63
78
- const cwd = await git.clone('https://github.com/conventional-changelog/commitlint.git', [
79
- '--depth=10'
80
- ]);
64
+ /*
65
+ test('should call git with expected args on shallow repo', async () => {
66
+ const cwd = await git.clone(
67
+ 'https://github.com/conventional-changelog/commitlint.git',
68
+ ['--depth=10']
69
+ );
81
70
82
71
const env = {
83
72
TRAVIS: true,
@@ -88,7 +77,7 @@ test.failing('should call git with expected args on shallow repo', async t => {
88
77
TRAVIS_COMMITLINT_GIT_BIN
89
78
};
90
79
91
- const result = await bin ({cwd, env});
80
+ const result = await cli ({cwd, env});
92
81
const invocations = await getInvocations(result.stdout);
93
82
t.is(invocations.length, 7);
94
83
@@ -143,76 +132,72 @@ test.failing('should call git with expected args on shallow repo', async t => {
143
132
]);
144
133
});
145
134
146
- test.failing(
147
- 'should call git with expected args on unshallow repo',
148
- async t => {
149
- if (os.platform() === 'win32') {
150
- t.pass();
151
- return;
152
- }
153
-
154
- const cwd = await git.clone('https://github.com/conventional-changelog/commitlint.git');
155
-
156
- const env = {
157
- TRAVIS: true,
158
- CI: true,
159
- TRAVIS_BRANCH,
160
- TRAVIS_COMMIT,
161
- TRAVIS_COMMITLINT_BIN,
162
- TRAVIS_COMMITLINT_GIT_BIN
163
- };
164
-
165
- const result = await bin({cwd, env});
166
- const invocations = await getInvocations(result.stdout);
167
- t.is(invocations.length, 6);
168
-
169
- const [stash, branches, checkout, back, pop, commilint] = invocations;
170
-
171
- t.deepEqual(stash, [NODE_BIN, TRAVIS_COMMITLINT_GIT_BIN, 'stash']);
172
- t.deepEqual(branches, [
173
- NODE_BIN,
174
- TRAVIS_COMMITLINT_GIT_BIN,
175
- 'remote',
176
- 'set-branches',
177
- 'origin',
178
- TRAVIS_BRANCH
179
- ]);
180
- t.deepEqual(checkout, [
181
- NODE_BIN,
182
- TRAVIS_COMMITLINT_GIT_BIN,
183
- 'checkout',
184
- TRAVIS_BRANCH,
185
- '--quiet'
186
- ]);
187
- t.deepEqual(back, [
188
- NODE_BIN,
189
- TRAVIS_COMMITLINT_GIT_BIN,
190
- 'checkout',
191
- '-',
192
- '--quiet'
193
- ]);
194
- t.deepEqual(pop, [NODE_BIN, TRAVIS_COMMITLINT_GIT_BIN, 'stash', 'pop']);
195
- t.deepEqual(commilint, [
196
- NODE_BIN,
197
- TRAVIS_COMMITLINT_BIN,
198
- '--from',
199
- TRAVIS_BRANCH,
200
- '--to',
201
- TRAVIS_COMMIT
202
- ]);
203
- }
204
- );
135
+ test('should call git with expected args on unshallow repo', async () => {
136
+ const cwd = await git.clone(
137
+ 'https://github.com/conventional-changelog/commitlint.git'
138
+ );
139
+
140
+ const env = {
141
+ TRAVIS: true,
142
+ CI: true,
143
+ TRAVIS_BRANCH,
144
+ TRAVIS_COMMIT,
145
+ TRAVIS_COMMITLINT_BIN,
146
+ TRAVIS_COMMITLINT_GIT_BIN
147
+ };
148
+
149
+ const result = await cli({cwd, env});
150
+ const invocations = await getInvocations(result.stdout);
151
+ t.is(invocations.length, 6);
152
+
153
+ const [stash, branches, checkout, back, pop, commilint] = invocations;
154
+
155
+ t.deepEqual(stash, [NODE_BIN, TRAVIS_COMMITLINT_GIT_BIN, 'stash']);
156
+ t.deepEqual(branches, [
157
+ NODE_BIN,
158
+ TRAVIS_COMMITLINT_GIT_BIN,
159
+ 'remote',
160
+ 'set-branches',
161
+ 'origin',
162
+ TRAVIS_BRANCH
163
+ ]);
164
+ t.deepEqual(checkout, [
165
+ NODE_BIN,
166
+ TRAVIS_COMMITLINT_GIT_BIN,
167
+ 'checkout',
168
+ TRAVIS_BRANCH,
169
+ '--quiet'
170
+ ]);
171
+ t.deepEqual(back, [
172
+ NODE_BIN,
173
+ TRAVIS_COMMITLINT_GIT_BIN,
174
+ 'checkout',
175
+ '-',
176
+ '--quiet'
177
+ ]);
178
+ t.deepEqual(pop, [NODE_BIN, TRAVIS_COMMITLINT_GIT_BIN, 'stash', 'pop']);
179
+ t.deepEqual(commilint, [
180
+ NODE_BIN,
181
+ TRAVIS_COMMITLINT_BIN,
182
+ '--from',
183
+ TRAVIS_BRANCH,
184
+ '--to',
185
+ TRAVIS_COMMIT
186
+ ]);
187
+ });
205
188
206
189
function getInvocations(stdout) {
207
190
const matches = stdout.match(/[^[\]]+/g);
208
191
const raw = Array.isArray(matches) ? matches : [];
209
192
210
- return raw.filter(invocation => invocation !== '\n').map(invocation =>
211
- invocation
212
- .split(',')
213
- .map(fragment => fragment.trim())
214
- .map(fragment => fragment.substring(1, fragment.length - 1))
215
- .filter(Boolean)
216
- );
193
+ return raw
194
+ .filter(invocation => invocation !== '\n')
195
+ .map(invocation =>
196
+ invocation
197
+ .split(',')
198
+ .map(fragment => fragment.trim())
199
+ .map(fragment => fragment.substring(1, fragment.length - 1))
200
+ .filter(Boolean)
201
+ );
217
202
}
218
203
*/
0 commit comments