UNPKG

5.29 kBJavaScriptView Raw
1'use strict';
2
3// Disable ftb
4// const os = require('os');
5// const {git} = require('@commitlint/test');
6const test = require('ava');
7const execa = require('execa');
8// Disable ftb
9// const which = require('which');
10
11// Disable ftb
12// const NODE_BIN = which.sync('node');
13const BIN = require.resolve('../lib/cli.js');
14
15// Disable ftb
16// const TRAVIS_COMMITLINT_BIN = require.resolve('../fixtures/commitlint');
17// const TRAVIS_COMMITLINT_GIT_BIN = require.resolve('../fixtures/git');
18// const TRAVIS_BRANCH = 'TRAVIS_BRANCH';
19// const TRAVIS_COMMIT = 'TRAVIS_COMMIT';
20
21const bin = (config = {}) => new Promise(function ($return, $error) {
22 var $Try_1_Post = function () {
23 try {
24 return $return();
25 } catch ($boundEx) {
26 return $error($boundEx);
27 }
28 }.bind(this);var $Try_1_Catch = function (err) {
29 try {
30 throw new Error([err.stdout, err.stderr].join('\n'));
31 } catch ($boundEx) {
32 return $error($boundEx);
33 }
34 }.bind(this);
35 try {
36 return Promise.resolve(execa(BIN, Object.assign({ extendEnv: false }, config))).then($return, $Try_1_Catch);
37 } catch (err) {
38 $Try_1_Catch(err)
39 }
40}.bind(this));
41
42test('should throw when not on travis ci', t => new Promise(function ($return, $error) {
43 var env;
44 env = {
45 CI: false,
46 TRAVIS: false
47 };
48 return Promise.resolve(t.throws(bin({ env }), /@commitlint\/travis-cli is intended to be used on Travis CI/)).then(function ($await_3) {
49 try {
50 return $return();
51 } catch ($boundEx) {
52 return $error($boundEx);
53 }
54 }.bind(this), $error);
55}.bind(this)));
56
57/* Test.failing(
58 'should throw when on travis ci, but env vars are missing',
59 async t => {
60 const env = {
61 TRAVIS: true,
62 CI: true
63 };
64
65 await t.throws(bin({env}), /TRAVIS_COMMIT, TRAVIS_BRANCH/);
66 }
67); */
68
69test('should throw when on travis ci, but TRAVIS_COMMIT is missing', t => new Promise(function ($return, $error) {
70 var env;
71 env = {
72 TRAVIS: true,
73 CI: true
74 };
75 return Promise.resolve(t.throws(bin({ env }), /TRAVIS_COMMIT/)).then(function ($await_4) {
76 try {
77 return $return();
78 } catch ($boundEx) {
79 return $error($boundEx);
80 }
81 }.bind(this), $error);
82}.bind(this)));
83
84/* Test.failing(
85 'should throw when on travis ci, but TRAVIS_BRANCH is missing',
86 async t => {
87 const env = {
88 TRAVIS: true,
89 CI: true
90 };
91
92 await t.throws(bin({env}), /TRAVIS_BRANCH/);
93 }
94);
95
96test.failing('should call git with expected args on shallow repo', async t => {
97 if (os.platform() === 'win32') {
98 t.pass();
99 return;
100 }
101
102 const cwd = await git.clone('https://github.com/conventional-changelog/commitlint.git', [
103 '--depth=10'
104 ]);
105
106 const env = {
107 TRAVIS: true,
108 CI: true,
109 TRAVIS_BRANCH,
110 TRAVIS_COMMIT,
111 TRAVIS_COMMITLINT_BIN,
112 TRAVIS_COMMITLINT_GIT_BIN
113 };
114
115 const result = await bin({cwd, env});
116 const invocations = await getInvocations(result.stdout);
117 t.is(invocations.length, 7);
118
119 const [
120 stash,
121 branches,
122 unshallow,
123 checkout,
124 back,
125 pop,
126 commilint
127 ] = invocations;
128
129 t.deepEqual(stash, [NODE_BIN, TRAVIS_COMMITLINT_GIT_BIN, 'stash']);
130 t.deepEqual(branches, [
131 NODE_BIN,
132 TRAVIS_COMMITLINT_GIT_BIN,
133 'remote',
134 'set-branches',
135 'origin',
136 TRAVIS_BRANCH
137 ]);
138 t.deepEqual(unshallow, [
139 NODE_BIN,
140 TRAVIS_COMMITLINT_GIT_BIN,
141 'fetch',
142 '--unshallow',
143 '--quiet'
144 ]);
145 t.deepEqual(checkout, [
146 NODE_BIN,
147 TRAVIS_COMMITLINT_GIT_BIN,
148 'checkout',
149 TRAVIS_BRANCH,
150 '--quiet'
151 ]);
152 t.deepEqual(back, [
153 NODE_BIN,
154 TRAVIS_COMMITLINT_GIT_BIN,
155 'checkout',
156 '-',
157 '--quiet'
158 ]);
159 t.deepEqual(pop, [NODE_BIN, TRAVIS_COMMITLINT_GIT_BIN, 'stash', 'pop']);
160 t.deepEqual(commilint, [
161 NODE_BIN,
162 TRAVIS_COMMITLINT_BIN,
163 '--from',
164 TRAVIS_BRANCH,
165 '--to',
166 TRAVIS_COMMIT
167 ]);
168});
169
170test.failing(
171 'should call git with expected args on unshallow repo',
172 async t => {
173 if (os.platform() === 'win32') {
174 t.pass();
175 return;
176 }
177
178 const cwd = await git.clone('https://github.com/conventional-changelog/commitlint.git');
179
180 const env = {
181 TRAVIS: true,
182 CI: true,
183 TRAVIS_BRANCH,
184 TRAVIS_COMMIT,
185 TRAVIS_COMMITLINT_BIN,
186 TRAVIS_COMMITLINT_GIT_BIN
187 };
188
189 const result = await bin({cwd, env});
190 const invocations = await getInvocations(result.stdout);
191 t.is(invocations.length, 6);
192
193 const [stash, branches, checkout, back, pop, commilint] = invocations;
194
195 t.deepEqual(stash, [NODE_BIN, TRAVIS_COMMITLINT_GIT_BIN, 'stash']);
196 t.deepEqual(branches, [
197 NODE_BIN,
198 TRAVIS_COMMITLINT_GIT_BIN,
199 'remote',
200 'set-branches',
201 'origin',
202 TRAVIS_BRANCH
203 ]);
204 t.deepEqual(checkout, [
205 NODE_BIN,
206 TRAVIS_COMMITLINT_GIT_BIN,
207 'checkout',
208 TRAVIS_BRANCH,
209 '--quiet'
210 ]);
211 t.deepEqual(back, [
212 NODE_BIN,
213 TRAVIS_COMMITLINT_GIT_BIN,
214 'checkout',
215 '-',
216 '--quiet'
217 ]);
218 t.deepEqual(pop, [NODE_BIN, TRAVIS_COMMITLINT_GIT_BIN, 'stash', 'pop']);
219 t.deepEqual(commilint, [
220 NODE_BIN,
221 TRAVIS_COMMITLINT_BIN,
222 '--from',
223 TRAVIS_BRANCH,
224 '--to',
225 TRAVIS_COMMIT
226 ]);
227 }
228);
229
230function getInvocations(stdout) {
231 const matches = stdout.match(/[^[\]]+/g);
232 const raw = Array.isArray(matches) ? matches : [];
233
234 return raw.filter(invocation => invocation !== '\n').map(invocation =>
235 invocation
236 .split(',')
237 .map(fragment => fragment.trim())
238 .map(fragment => fragment.substring(1, fragment.length - 1))
239 .filter(Boolean)
240 );
241}
242*/
243//# sourceMappingURL=cli.test.js.map
\No newline at end of file