Skip to content

Commit

Permalink
Merge branch 'master' into fix/utils
Browse files Browse the repository at this point in the history
  • Loading branch information
armano2 committed Feb 9, 2020
2 parents 89edcaa + f74e036 commit 2fb2a7d
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 134 deletions.
2 changes: 1 addition & 1 deletion @commitlint/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"@commitlint/utils": "^8.3.4",
"babel-preset-commitlint": "^8.2.0",
"cross-env": "7.0.0",
"execa": "0.11.0",
"execa": "^3.4.0",
"fs-extra": "^8.1.0"
},
"dependencies": {
Expand Down
68 changes: 34 additions & 34 deletions @commitlint/cli/src/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ const bin = require.resolve('../lib/cli.js');

const cli = (args, options) => {
return (input = '') => {
const c = execa(bin, args, {
return execa(bin, args, {
cwd: options.cwd,
env: options.env,
input: input
input: input,
reject: false
});
return c.catch(err => err);
};
};

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

expect(actual.stdout).toContain(input);
expect(actual.code).toBe(1);
expect(actual.exitCode).toBe(1);
});

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

expect(actual.stdout).not.toContain(message);
expect(actual.stdout).not.toContain(message.split('\n')[0]);
expect(actual.code).toBe(0);
expect(actual.exitCode).toBe(0);
});

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

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

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

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

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

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

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

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

expect(actual.stdout).toContain('custom-formatter-ok');
expect(actual.code).toBe(0);
expect(actual.exitCode).toBe(0);
});

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

expect(actual.stdout).toContain('custom-formatter-ok');
expect(actual.code).toBe(0);
expect(actual.exitCode).toBe(0);
});

async function writePkg(payload, options) {
Expand Down
2 changes: 1 addition & 1 deletion @commitlint/load/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@commitlint/test": "8.2.0",
"@commitlint/utils": "^8.3.4",
"@types/lodash": "4.14.149",
"execa": "0.11.0"
"execa": "^3.4.0"
},
"dependencies": {
"@commitlint/execute-rule": "^8.3.4",
Expand Down
6 changes: 3 additions & 3 deletions @commitlint/prompt-cli/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ const bin = require.resolve('./cli.js');

const cli = (args, options) => {
return (input = '') => {
const c = execa(bin, args, {
return execa(bin, args, {
cwd: options.cwd,
env: options.env,
input: input
input: input,
reject: false
});
return c.catch(err => err);
};
};

Expand Down
2 changes: 1 addition & 1 deletion @commitlint/prompt-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@
},
"dependencies": {
"@commitlint/prompt": "^8.3.5",
"execa": "0.11.0"
"execa": "^3.4.0"
}
}
2 changes: 1 addition & 1 deletion @commitlint/travis-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@
},
"dependencies": {
"@commitlint/cli": "^8.3.5",
"execa": "0.11.0"
"execa": "^3.4.0"
}
}
6 changes: 4 additions & 2 deletions @commitlint/travis-cli/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ async function main() {
// Restore stashed changes if any
await pop();

const args = process.argv.slice(2);

// Lint all commits in TRAVIS_COMMIT_RANGE if available
if (IS_PR && RANGE) {
const [start, end] = RANGE.split('.').filter(Boolean);
await lint(['--from', start, '--to', end]);
await lint(['--from', start, '--to', end, ...args]);
} else {
const input = await log(COMMIT);
await lint([], {input});
await lint(args, {input});
}
}

Expand Down
37 changes: 35 additions & 2 deletions @commitlint/travis-cli/src/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ const validBaseEnv = {
TRAVIS_PULL_REQUEST_SLUG: 'TRAVIS_PULL_REQUEST_SLUG'
};

const cli = async (config = {}) => {
const cli = async (config = {}, args = []) => {
try {
return await execa(bin, [], config);
return await execa(bin, args, config);
} catch (err) {
throw new Error([err.stdout, err.stderr].join('\n'));
}
Expand Down Expand Up @@ -98,6 +98,39 @@ test('should call git with expected args on pull_request', async () => {
]);
});

test('should call git with extra expected args on pull_request', async () => {
const cwd = await git.clone(
'https://github.com/conventional-changelog/commitlint.git',
['--depth=10'],
__dirname,
TRAVIS_COMMITLINT_GIT_BIN
);

const result = await cli(
{
cwd,
env: {...validBaseEnv, TRAVIS_EVENT_TYPE: 'pull_request'}
},
['--config', './config/commitlint.config.js']
);
const invocations = await getInvocations(result.stdout);
expect(invocations.length).toBe(3);

const [stash, branches, commilint] = invocations;

expect(stash).toEqual(['git', 'stash', '-k', '-u', '--quiet']);
expect(branches).toEqual(['git', 'stash', 'pop', '--quiet']);
expect(commilint).toEqual([
'commitlint',
'--from',
'TRAVIS_COMMIT_A',
'--to',
'TRAVIS_COMMIT_B',
'--config',
'./config/commitlint.config.js'
]);
});

function getInvocations(stdout) {
const matches = stdout.match(/[^[\]]+/g);
const raw = Array.isArray(matches) ? matches : [];
Expand Down

0 comments on commit 2fb2a7d

Please sign in to comment.