Skip to content

Commit 2fb2a7d

Browse files
committed
Merge branch 'master' into fix/utils
2 parents 89edcaa + f74e036 commit 2fb2a7d

File tree

12 files changed

+91
-134
lines changed

12 files changed

+91
-134
lines changed

@commitlint/cli/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"@commitlint/utils": "^8.3.4",
5454
"babel-preset-commitlint": "^8.2.0",
5555
"cross-env": "7.0.0",
56-
"execa": "0.11.0",
56+
"execa": "^3.4.0",
5757
"fs-extra": "^8.1.0"
5858
},
5959
"dependencies": {

@commitlint/cli/src/cli.test.js

+34-34
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ const bin = require.resolve('../lib/cli.js');
88

99
const cli = (args, options) => {
1010
return (input = '') => {
11-
const c = execa(bin, args, {
11+
return execa(bin, args, {
1212
cwd: options.cwd,
1313
env: options.env,
14-
input: input
14+
input: input,
15+
reject: false
1516
});
16-
return c.catch(err => err);
1717
};
1818
};
1919

@@ -23,7 +23,7 @@ const fixBootstrap = fixture => fix.bootstrap(fixture, __dirname);
2323
test('should throw when called without [input]', async () => {
2424
const cwd = await gitBootstrap('fixtures/default');
2525
const actual = await cli([], {cwd})();
26-
expect(actual.code).toBe(1);
26+
expect(actual.exitCode).toBe(1);
2727
});
2828

2929
test('should reprint input from stdin', async () => {
@@ -57,7 +57,7 @@ test('should produce help for empty config', async () => {
5757
const cwd = await gitBootstrap('fixtures/empty');
5858
const actual = await cli([], {cwd})('foo: bar');
5959
expect(actual.stdout).toContain('Please add rules');
60-
expect(actual.code).toBe(1);
60+
expect(actual.exitCode).toBe(1);
6161
});
6262

6363
test('should produce help for problems', async () => {
@@ -66,7 +66,7 @@ test('should produce help for problems', async () => {
6666
expect(actual.stdout).toContain(
6767
'Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint'
6868
);
69-
expect(actual.code).toBe(1);
69+
expect(actual.exitCode).toBe(1);
7070
});
7171

7272
test('should produce help for problems with correct helpurl', async () => {
@@ -78,57 +78,57 @@ test('should produce help for problems with correct helpurl', async () => {
7878
expect(actual.stdout).toContain(
7979
'Get help: https://github.com/conventional-changelog/commitlint/#testhelpurl'
8080
);
81-
expect(actual.code).toBe(1);
81+
expect(actual.exitCode).toBe(1);
8282
});
8383

8484
test('should fail for input from stdin without rules', async () => {
8585
const cwd = await gitBootstrap('fixtures/empty');
8686
const actual = await cli([], {cwd})('foo: bar');
87-
expect(actual.code).toBe(1);
87+
expect(actual.exitCode).toBe(1);
8888
});
8989

9090
test('should succeed for input from stdin with rules', async () => {
9191
const cwd = await gitBootstrap('fixtures/default');
9292
const actual = await cli([], {cwd})('type: bar');
93-
expect(actual.code).toBe(0);
93+
expect(actual.exitCode).toBe(0);
9494
});
9595

9696
test('should fail for input from stdin with rule from rc', async () => {
9797
const cwd = await gitBootstrap('fixtures/simple');
9898
const actual = await cli([], {cwd})('foo: bar');
9999
expect(actual.stdout).toContain('type must not be one of [foo]');
100-
expect(actual.code).toBe(1);
100+
expect(actual.exitCode).toBe(1);
101101
});
102102

103103
test('should work with --config option', async () => {
104104
const file = 'config/commitlint.config.js';
105105
const cwd = await gitBootstrap('fixtures/specify-config-file');
106106
const actual = await cli(['--config', file], {cwd})('foo: bar');
107107
expect(actual.stdout).toContain('type must not be one of [foo]');
108-
expect(actual.code).toBe(1);
108+
expect(actual.exitCode).toBe(1);
109109
});
110110

111111
test('should fail for input from stdin with rule from js', async () => {
112112
const cwd = await gitBootstrap('fixtures/extends-root');
113113
const actual = await cli(['--extends', './extended'], {cwd})('foo: bar');
114114
expect(actual.stdout).toContain('type must not be one of [foo]');
115-
expect(actual.code).toBe(1);
115+
expect(actual.exitCode).toBe(1);
116116
});
117117

118118
test('should produce no error output with --quiet flag', async () => {
119119
const cwd = await gitBootstrap('fixtures/simple');
120120
const actual = await cli(['--quiet'], {cwd})('foo: bar');
121121
expect(actual.stdout).toEqual('');
122122
expect(actual.stderr).toEqual('');
123-
expect(actual.code).toBe(1);
123+
expect(actual.exitCode).toBe(1);
124124
});
125125

126126
test('should produce no error output with -q flag', async () => {
127127
const cwd = await gitBootstrap('fixtures/simple');
128128
const actual = await cli(['-q'], {cwd})('foo: bar');
129129
expect(actual.stdout).toEqual('');
130130
expect(actual.stderr).toEqual('');
131-
expect(actual.code).toBe(1);
131+
expect(actual.exitCode).toBe(1);
132132
});
133133

134134
test('should work with husky commitmsg hook and git commit', async () => {
@@ -236,7 +236,7 @@ test('should allow reading of environment variables for edit file, succeeding if
236236
cwd,
237237
env: {variable: 'commit-msg-file'}
238238
})();
239-
expect(actual.code).toBe(0);
239+
expect(actual.exitCode).toBe(0);
240240
});
241241

242242
test('should allow reading of environment variables for edit file, failing if invalid', async () => {
@@ -249,15 +249,15 @@ test('should allow reading of environment variables for edit file, failing if in
249249
cwd,
250250
env: {variable: 'commit-msg-file'}
251251
})();
252-
expect(actual.code).toBe(1);
252+
expect(actual.exitCode).toBe(1);
253253
});
254254

255255
test('should pick up parser preset and fail accordingly', async () => {
256256
const cwd = await gitBootstrap('fixtures/parser-preset');
257257
const actual = await cli(['--parser-preset', './parser-preset'], {cwd})(
258258
'type(scope): subject'
259259
);
260-
expect(actual.code).toBe(1);
260+
expect(actual.exitCode).toBe(1);
261261
expect(actual.stdout).toContain('may not be empty');
262262
});
263263

@@ -266,39 +266,39 @@ test('should pick up parser preset and succeed accordingly', async () => {
266266
const actual = await cli(['--parser-preset', './parser-preset'], {cwd})(
267267
'----type(scope): subject'
268268
);
269-
expect(actual.code).toBe(0);
269+
expect(actual.exitCode).toBe(0);
270270
});
271271

272272
test('should pick up config from outside git repo and fail accordingly', async () => {
273273
const outer = await fixBootstrap('fixtures/outer-scope');
274274
const cwd = await git.init(path.join(outer, 'inner-scope'));
275275

276276
const actual = await cli([], {cwd})('inner: bar');
277-
expect(actual.code).toBe(1);
277+
expect(actual.exitCode).toBe(1);
278278
});
279279

280280
test('should pick up config from outside git repo and succeed accordingly', async () => {
281281
const outer = await fixBootstrap('fixtures/outer-scope');
282282
const cwd = await git.init(path.join(outer, 'inner-scope'));
283283

284284
const actual = await cli([], {cwd})('outer: bar');
285-
expect(actual.code).toBe(0);
285+
expect(actual.exitCode).toBe(0);
286286
});
287287

288288
test('should pick up config from inside git repo with precedence and succeed accordingly', async () => {
289289
const outer = await fixBootstrap('fixtures/inner-scope');
290290
const cwd = await git.init(path.join(outer, 'inner-scope'));
291291

292292
const actual = await cli([], {cwd})('inner: bar');
293-
expect(actual.code).toBe(0);
293+
expect(actual.exitCode).toBe(0);
294294
});
295295

296296
test('should pick up config from inside git repo with precedence and fail accordingly', async () => {
297297
const outer = await fixBootstrap('fixtures/inner-scope');
298298
const cwd = await git.init(path.join(outer, 'inner-scope'));
299299

300300
const actual = await cli([], {cwd})('outer: bar');
301-
expect(actual.code).toBe(1);
301+
expect(actual.exitCode).toBe(1);
302302
});
303303

304304
test('should handle --amend with signoff', async () => {
@@ -320,7 +320,7 @@ test('should handle --amend with signoff', async () => {
320320
test('should handle linting with issue prefixes', async () => {
321321
const cwd = await gitBootstrap('fixtures/issue-prefixes');
322322
const actual = await cli([], {cwd})('foobar REF-1');
323-
expect(actual.code).toBe(0);
323+
expect(actual.exitCode).toBe(0);
324324
}, 10000);
325325

326326
test('should print full commit message when input from stdin fails', async () => {
@@ -330,7 +330,7 @@ test('should print full commit message when input from stdin fails', async () =>
330330
const actual = await cli(['--color=false'], {cwd})(input);
331331

332332
expect(actual.stdout).toContain(input);
333-
expect(actual.code).toBe(1);
333+
expect(actual.exitCode).toBe(1);
334334
});
335335

336336
test('should not print commit message fully or partially when input succeeds', async () => {
@@ -341,7 +341,7 @@ test('should not print commit message fully or partially when input succeeds', a
341341

342342
expect(actual.stdout).not.toContain(message);
343343
expect(actual.stdout).not.toContain(message.split('\n')[0]);
344-
expect(actual.code).toBe(0);
344+
expect(actual.exitCode).toBe(0);
345345
});
346346

347347
test('should fail for invalid formatters from configuration', async () => {
@@ -352,37 +352,37 @@ test('should fail for invalid formatters from configuration', async () => {
352352
'Using format custom-formatter, but cannot find the module'
353353
);
354354
expect(actual.stdout).toEqual('');
355-
expect(actual.code).toBe(1);
355+
expect(actual.exitCode).toBe(1);
356356
});
357357

358358
test('should skip linting if message matches ignores config', async () => {
359359
const cwd = await gitBootstrap('fixtures/ignores');
360360
const actual = await cli([], {cwd})('WIP');
361-
expect(actual.code).toBe(0);
361+
expect(actual.exitCode).toBe(0);
362362
});
363363

364364
test('should not skip linting if message does not match ignores config', async () => {
365365
const cwd = await gitBootstrap('fixtures/ignores');
366366
const actual = await cli([], {cwd})('foo');
367-
expect(actual.code).toBe(1);
367+
expect(actual.exitCode).toBe(1);
368368
});
369369

370370
test('should not skip linting if defaultIgnores is false', async () => {
371371
const cwd = await gitBootstrap('fixtures/default-ignores-false');
372372
const actual = await cli([], {cwd})('fixup! foo: bar');
373-
expect(actual.code).toBe(1);
373+
expect(actual.exitCode).toBe(1);
374374
});
375375

376376
test('should skip linting if defaultIgnores is true', async () => {
377377
const cwd = await gitBootstrap('fixtures/default-ignores-true');
378378
const actual = await cli([], {cwd})('fixup! foo: bar');
379-
expect(actual.code).toBe(0);
379+
expect(actual.exitCode).toBe(0);
380380
});
381381

382382
test('should skip linting if defaultIgnores is unset', async () => {
383383
const cwd = await gitBootstrap('fixtures/default-ignores-unset');
384384
const actual = await cli([], {cwd})('fixup! foo: bar');
385-
expect(actual.code).toBe(0);
385+
expect(actual.exitCode).toBe(0);
386386
});
387387

388388
test('should fail for invalid formatters from flags', async () => {
@@ -393,7 +393,7 @@ test('should fail for invalid formatters from flags', async () => {
393393
'Using format through-flag, but cannot find the module'
394394
);
395395
expect(actual.stdout).toEqual('');
396-
expect(actual.code).toBe(1);
396+
expect(actual.exitCode).toBe(1);
397397
});
398398

399399
test('should work with absolute formatter path', async () => {
@@ -407,7 +407,7 @@ test('should work with absolute formatter path', async () => {
407407
);
408408

409409
expect(actual.stdout).toContain('custom-formatter-ok');
410-
expect(actual.code).toBe(0);
410+
expect(actual.exitCode).toBe(0);
411411
});
412412

413413
test('should work with relative formatter path', async () => {
@@ -420,7 +420,7 @@ test('should work with relative formatter path', async () => {
420420
);
421421

422422
expect(actual.stdout).toContain('custom-formatter-ok');
423-
expect(actual.code).toBe(0);
423+
expect(actual.exitCode).toBe(0);
424424
});
425425

426426
async function writePkg(payload, options) {

@commitlint/load/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"@commitlint/test": "8.2.0",
3838
"@commitlint/utils": "^8.3.4",
3939
"@types/lodash": "4.14.149",
40-
"execa": "0.11.0"
40+
"execa": "^3.4.0"
4141
},
4242
"dependencies": {
4343
"@commitlint/execute-rule": "^8.3.4",

@commitlint/prompt-cli/cli.test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ const bin = require.resolve('./cli.js');
55

66
const cli = (args, options) => {
77
return (input = '') => {
8-
const c = execa(bin, args, {
8+
return execa(bin, args, {
99
cwd: options.cwd,
1010
env: options.env,
11-
input: input
11+
input: input,
12+
reject: false
1213
});
13-
return c.catch(err => err);
1414
};
1515
};
1616

@commitlint/prompt-cli/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@
3636
},
3737
"dependencies": {
3838
"@commitlint/prompt": "^8.3.5",
39-
"execa": "0.11.0"
39+
"execa": "^3.4.0"
4040
}
4141
}

@commitlint/travis-cli/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,6 @@
5454
},
5555
"dependencies": {
5656
"@commitlint/cli": "^8.3.5",
57-
"execa": "0.11.0"
57+
"execa": "^3.4.0"
5858
}
5959
}

@commitlint/travis-cli/src/cli.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@ async function main() {
4242
// Restore stashed changes if any
4343
await pop();
4444

45+
const args = process.argv.slice(2);
46+
4547
// Lint all commits in TRAVIS_COMMIT_RANGE if available
4648
if (IS_PR && RANGE) {
4749
const [start, end] = RANGE.split('.').filter(Boolean);
48-
await lint(['--from', start, '--to', end]);
50+
await lint(['--from', start, '--to', end, ...args]);
4951
} else {
5052
const input = await log(COMMIT);
51-
await lint([], {input});
53+
await lint(args, {input});
5254
}
5355
}
5456

@commitlint/travis-cli/src/cli.test.js

+35-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ const validBaseEnv = {
1818
TRAVIS_PULL_REQUEST_SLUG: 'TRAVIS_PULL_REQUEST_SLUG'
1919
};
2020

21-
const cli = async (config = {}) => {
21+
const cli = async (config = {}, args = []) => {
2222
try {
23-
return await execa(bin, [], config);
23+
return await execa(bin, args, config);
2424
} catch (err) {
2525
throw new Error([err.stdout, err.stderr].join('\n'));
2626
}
@@ -98,6 +98,39 @@ test('should call git with expected args on pull_request', async () => {
9898
]);
9999
});
100100

101+
test('should call git with extra expected args on pull_request', async () => {
102+
const cwd = await git.clone(
103+
'https://github.com/conventional-changelog/commitlint.git',
104+
['--depth=10'],
105+
__dirname,
106+
TRAVIS_COMMITLINT_GIT_BIN
107+
);
108+
109+
const result = await cli(
110+
{
111+
cwd,
112+
env: {...validBaseEnv, TRAVIS_EVENT_TYPE: 'pull_request'}
113+
},
114+
['--config', './config/commitlint.config.js']
115+
);
116+
const invocations = await getInvocations(result.stdout);
117+
expect(invocations.length).toBe(3);
118+
119+
const [stash, branches, commilint] = invocations;
120+
121+
expect(stash).toEqual(['git', 'stash', '-k', '-u', '--quiet']);
122+
expect(branches).toEqual(['git', 'stash', 'pop', '--quiet']);
123+
expect(commilint).toEqual([
124+
'commitlint',
125+
'--from',
126+
'TRAVIS_COMMIT_A',
127+
'--to',
128+
'TRAVIS_COMMIT_B',
129+
'--config',
130+
'./config/commitlint.config.js'
131+
]);
132+
});
133+
101134
function getInvocations(stdout) {
102135
const matches = stdout.match(/[^[\]]+/g);
103136
const raw = Array.isArray(matches) ? matches : [];

0 commit comments

Comments
 (0)