Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable alternative config formats #83

Merged
merged 4 commits into from
Oct 3, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: consolidate dev dependencies
marionebl committed Oct 3, 2017
commit a1c36a3b21cd24f306a864e29a15238513a99c3f
10 changes: 4 additions & 6 deletions @commitlint/core/package.json
Original file line number Diff line number Diff line change
@@ -64,10 +64,10 @@
"devDependencies": {
"@commitlint/utils": "^3.1.1",
"ansi-styles": "3.1.0",
"ava": "0.18.2",
"babel-cli": "^6.18.0",
"ava": "0.22.0",
"babel-cli": "^6.26.0",
"babel-preset-commitlint": "^3.2.0",
"babel-register": "6.24.1",
"babel-register": "^6.26.0",
"cross-env": "^5.0.1",
"denodeify": "1.2.1",
"dependency-check": "2.7.0",
@@ -78,11 +78,10 @@
"nyc": "10.3.2",
"path-exists": "3.0.0",
"resolve-from": "3.0.0",
"sander": "^0.6.0",
"rimraf": "2.6.1",
"xo": "0.18.2"
},
"dependencies": {
"@marionebl/sander": "^0.6.1",
"babel-runtime": "^6.23.0",
"chalk": "^2.0.1",
"conventional-changelog-angular": "^1.3.3",
@@ -92,7 +91,6 @@
"franc": "^2.0.0",
"git-raw-commits": "^1.1.2",
"lodash": "^4.17.4",
"mz": "^2.6.0",
"path-exists": "^3.0.0",
"pos": "^0.4.2",
"rc": "^1.1.7",
14 changes: 8 additions & 6 deletions @commitlint/core/src/library/parse.test.js
Original file line number Diff line number Diff line change
@@ -2,12 +2,14 @@ import importFrom from 'import-from';
import test from 'ava';
import parse from './parse';

test('throws when called without params', t => {
t.throws(parse(), /Expected a raw commit/);
test('throws when called without params', async t => {
const error = await t.throws(parse());
t.is(error.message, 'Expected a raw commit');
});

test('throws when called with empty message', t => {
t.throws(parse(''), /Expected a raw commit/);
test('throws when called with empty message', async t => {
const error = await t.throws(parse());
t.is(error.message, 'Expected a raw commit');
});

test('returns object with raw message', async t => {
@@ -16,10 +18,10 @@ test('returns object with raw message', async t => {
t.is(actual.raw, message);
});

test('calls parser with message and passed options', t => {
test('calls parser with message and passed options', async t => {
const message = 'message';

parse(message, m => {
await parse(message, m => {
t.is(message, m);
return {};
});
10 changes: 6 additions & 4 deletions @commitlint/core/src/lint.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import test from 'ava';
import lint from './lint';

test('throws without params', t => {
t.throws(lint());
test('throws without params', async t => {
const error = await t.throws(lint());
t.is(error.message, 'Expected a raw commit');
});

test('throws with empty message', t => {
t.throws(lint(''));
test('throws with empty message', async t => {
const error = await t.throws(lint(''));
t.is(error.message, 'Expected a raw commit');
});

test('positive on stub message and no rule', async t => {
70 changes: 39 additions & 31 deletions @commitlint/core/src/load.test.js
Original file line number Diff line number Diff line change
@@ -3,30 +3,22 @@ import crypto from 'crypto';
import path from 'path';
import test from 'ava';
import exists from 'path-exists';
import rimraf from 'rimraf';
import execa from 'execa';
import denodeify from 'denodeify';
import * as sander from 'sander';
import * as sander from '@marionebl/sander';

import load from './load';

const rm = denodeify(rimraf);

test.beforeEach(async t => {
t.context.repos = [await initRepository()];
t.context.repo = await initRepository();
});

test.afterEach.always(async t => {
try {
await Promise.all(t.context.repos.map(async repo => cleanRepository(repo)));
t.context.repos = [];
} catch (err) {
console.log({err});
}
await cleanRepository(t.context.repo);
});

test.serial('extends-empty should have no rules', async t => {
const [repo] = t.context.repos;
const {repo} = t.context;

await sander
.copydir(path.join(repo.previous, 'fixtures/extends-empty'))
.to(repo.directory);
@@ -36,7 +28,8 @@ test.serial('extends-empty should have no rules', async t => {
});

test.serial('uses seed as configured', async t => {
const [repo] = t.context.repos;
const {repo} = t.context;

await sander
.copydir(path.join(repo.previous, 'fixtures/extends-empty'))
.to(repo.directory);
@@ -46,14 +39,16 @@ test.serial('uses seed as configured', async t => {
});

test.serial('uses seed with parserPreset', async t => {
const [repo] = t.context.repos;
const {repo} = t.context;

await sander
.copydir(path.join(repo.previous, 'fixtures/parser-preset'))
.to(repo.directory);

const {parserPreset: actual} = await load({
parserPreset: './conventional-changelog-custom'
});

t.is(actual.name, './conventional-changelog-custom');
t.deepEqual(actual.opts, {
parserOpts: {
@@ -63,16 +58,18 @@ test.serial('uses seed with parserPreset', async t => {
});

test.serial('invalid extend should throw', async t => {
const [repo] = t.context.repos;
const {repo} = t.context;

await sander
.copydir(path.join(repo.previous, 'fixtures/extends-invalid'))
.to(repo.directory);

t.throws(load());
await t.throws(load());
});

test.serial('empty file should have no rules', async t => {
const [repo] = t.context.repos;
const {repo} = t.context;

await sander
.copydir(path.join(repo.previous, 'fixtures/empty-object-file'))
.to(repo.directory);
@@ -82,7 +79,8 @@ test.serial('empty file should have no rules', async t => {
});

test.serial('empty file should extend nothing', async t => {
const [repo] = t.context.repos;
const {repo} = t.context;

await sander
.copydir(path.join(repo.previous, 'fixtures/empty-file'))
.to(repo.directory);
@@ -92,7 +90,8 @@ test.serial('empty file should extend nothing', async t => {
});

test.serial('recursive extends', async t => {
const [repo] = t.context.repos;
const {repo} = t.context;

await sander
.copydir(path.join(repo.previous, 'fixtures/recursive-extends'))
.to(repo.directory);
@@ -109,7 +108,8 @@ test.serial('recursive extends', async t => {
});

test.serial('recursive extends with json file', async t => {
const [repo] = t.context.repos;
const {repo} = t.context;

await sander
.copydir(path.join(repo.previous, 'fixtures/recursive-extends-json'))
.to(repo.directory);
@@ -126,7 +126,8 @@ test.serial('recursive extends with json file', async t => {
});

test.serial('recursive extends with yaml file', async t => {
const [repo] = t.context.repos;
const {repo} = t.context;

await sander
.copydir(path.join(repo.previous, 'fixtures/recursive-extends-yaml'))
.to(repo.directory);
@@ -143,7 +144,8 @@ test.serial('recursive extends with yaml file', async t => {
});

test.serial('recursive extends with js file', async t => {
const [repo] = t.context.repos;
const {repo} = t.context;

await sander
.copydir(path.join(repo.previous, 'fixtures/recursive-extends-js'))
.to(repo.directory);
@@ -160,7 +162,8 @@ test.serial('recursive extends with js file', async t => {
});

test.serial('recursive extends with package.json file', async t => {
const [repo] = t.context.repos;
const {repo} = t.context;

await sander
.copydir(path.join(repo.previous, 'fixtures/recursive-extends-package'))
.to(repo.directory);
@@ -179,7 +182,7 @@ test.serial('recursive extends with package.json file', async t => {
test.serial(
'parser preset overwrites completely instead of merging',
async t => {
const [repo] = t.context.repos;
const {repo} = t.context;

await sander
.copydir(path.join(repo.previous, 'fixtures/parser-preset-override'))
@@ -198,11 +201,12 @@ test.serial(
);

test.serial('recursive extends with parserPreset', async t => {
const [repo] = t.context.repos;
const {repo} = t.context;

await sander
.copydir(path.join(repo.previous, 'fixtures/recursive-parser-preset'))
.to(repo.directory);

await sander
.copydir(path.join(repo.previous, 'node_modules'))
.to(path.join('node_modules'));
@@ -218,7 +222,8 @@ test.serial('recursive extends with parserPreset', async t => {
});

test.serial('ignores unknow keys', async t => {
const [repo] = t.context.repos;
const {repo} = t.context;

await sander
.copydir(path.join(repo.previous, 'fixtures/trash-file'))
.to(repo.directory);
@@ -234,7 +239,8 @@ test.serial('ignores unknow keys', async t => {
});

test.serial('ignores unknow keys recursively', async t => {
const [repo] = t.context.repos;
const {repo} = t.context;

await sander
.copydir(path.join(repo.previous, 'fixtures/trash-extend'))
.to(repo.directory);
@@ -250,7 +256,8 @@ test.serial('ignores unknow keys recursively', async t => {
});

test.serial('supports legacy .conventional-changelog-lintrc', async t => {
const [repo] = t.context.repos;
const {repo} = t.context;

await sander
.copydir(path.join(repo.previous, 'fixtures/legacy'))
.to(repo.directory);
@@ -267,7 +274,8 @@ test.serial('supports legacy .conventional-changelog-lintrc', async t => {
test.serial(
'commitlint.config.js overrides .conventional-changelog-lintrc',
async t => {
const [repo] = t.context.repos;
const {repo} = t.context;

await sander
.copydir(path.join(repo.previous, 'fixtures/overriden-legacy'))
.to(repo.directory);
@@ -302,7 +310,7 @@ async function cleanRepository(repo) {
}

if (await exists(repo.directory)) {
await rm(repo.directory);
await sander.rimraf(repo.directory);
}
}

2 changes: 1 addition & 1 deletion @commitlint/core/src/read.js
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ import path from 'path';
import exists from 'path-exists';
import up from 'find-up';
import gitRawCommits from 'git-raw-commits';
import {readFile} from 'mz/fs';
import {readFile} from '@marionebl/sander';

export default getCommitMessages;

23 changes: 11 additions & 12 deletions @commitlint/core/src/read.test.js
Original file line number Diff line number Diff line change
@@ -3,17 +3,13 @@ import crypto from 'crypto';
import {join} from 'path';

import test from 'ava';
import denodeify from 'denodeify';
import execa from 'execa';
import {mkdir, writeFile} from 'mz/fs';
import exists from 'path-exists';
import rimraf from 'rimraf';
import * as sander from '@marionebl/sander';

import pkg from '../package';
import read from './read';

const rm = denodeify(rimraf);

test.beforeEach(async t => {
t.context.repos = [await initRepository()];
});
@@ -28,7 +24,7 @@ test.afterEach.always(async t => {
});

test.serial('get edit commit message from git root', async t => {
await writeFile('alpha.txt', 'alpha');
await sander.writeFile('alpha.txt', 'alpha');
await execa('git', ['add', '.']);
await execa('git', ['commit', '-m', 'alpha']);
const expected = ['alpha\n\n'];
@@ -37,7 +33,7 @@ test.serial('get edit commit message from git root', async t => {
});

test.serial('get history commit messages', async t => {
await writeFile('alpha.txt', 'alpha');
await sander.writeFile('alpha.txt', 'alpha');
await execa('git', ['add', 'alpha.txt']);
await execa('git', ['commit', '-m', 'alpha']);
await execa('git', ['rm', 'alpha.txt']);
@@ -49,8 +45,8 @@ test.serial('get history commit messages', async t => {
});

test.serial('get edit commit message from git subdirectory', async t => {
await mkdir('beta');
await writeFile('beta/beta.txt', 'beta');
await sander.mkdir('beta');
await sander.writeFile('beta/beta.txt', 'beta');
process.chdir('beta');
await execa('git', ['add', '.']);
await execa('git', ['commit', '-m', 'beta']);
@@ -63,7 +59,7 @@ test.serial('get edit commit message from git subdirectory', async t => {
test.serial('get history commit messages from shallow clone', async t => {
const [repo] = t.context.repos;

await writeFile('alpha.txt', 'alpha');
await sander.writeFile('alpha.txt', 'alpha');
await execa('git', ['add', 'alpha.txt']);
await execa('git', ['commit', '-m', 'alpha']);

@@ -107,10 +103,13 @@ async function cleanRepository(repo) {
}

if (await exists(repo.directory)) {
await rm(repo.directory);
await sander.rimraf(repo.directory);
}
}

function rand() {
return crypto.randomBytes(Math.ceil(6)).toString('hex').slice(0, 12);
return crypto
.randomBytes(Math.ceil(6))
.toString('hex')
.slice(0, 12);
}