Skip to content

Commit

Permalink
chore: move git test utils to seperate package
Browse files Browse the repository at this point in the history
  • Loading branch information
marionebl committed Oct 9, 2017
1 parent 8f35dae commit 1e80f80
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 27 deletions.
1 change: 1 addition & 0 deletions @commitlint/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"license": "MIT",
"devDependencies": {
"@commitlint/utils": "^3.1.1",
"@commitlint/test": "^3.1.1",
"ava": "0.22.0",
"babel-cli": "^6.26.0",
"babel-preset-commitlint": "^3.2.0",
Expand Down
34 changes: 17 additions & 17 deletions @commitlint/core/src/load.test.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import {git} from '@commitlint/test';
import test from 'ava';

import {bootstrap} from './test-git';
import load from './load';

test('extends-empty should have no rules', async t => {
const cwd = await bootstrap('fixtures/extends-empty');
const cwd = await git.bootstrap('fixtures/extends-empty');
const actual = await load({}, {cwd});
t.deepEqual(actual.rules, {});
});

test('uses seed as configured', async t => {
const cwd = await bootstrap('fixtures/extends-empty');
const cwd = await git.bootstrap('fixtures/extends-empty');
const actual = await load({rules: {foo: 'bar'}}, {cwd});
t.is(actual.rules.foo, 'bar');
});

test('uses seed with parserPreset', async t => {
const cwd = await bootstrap('fixtures/parser-preset');
const cwd = await git.bootstrap('fixtures/parser-preset');
const {parserPreset: actual} = await load(
{
parserPreset: './conventional-changelog-custom'
Expand All @@ -33,24 +33,24 @@ test('uses seed with parserPreset', async t => {
});

test('invalid extend should throw', async t => {
const cwd = await bootstrap('fixtures/extends-invalid');
const cwd = await git.bootstrap('fixtures/extends-invalid');
await t.throws(load({}, {cwd}));
});

test('empty file should have no rules', async t => {
const cwd = await bootstrap('fixtures/empty-object-file');
const cwd = await git.bootstrap('fixtures/empty-object-file');
const actual = await load({}, {cwd});
t.deepEqual(actual.rules, {});
});

test('empty file should extend nothing', async t => {
const cwd = await bootstrap('fixtures/empty-file');
const cwd = await git.bootstrap('fixtures/empty-file');
const actual = await load({}, {cwd});
t.deepEqual(actual.extends, []);
});

test('respects cwd option', async t => {
const cwd = await bootstrap('fixtures/recursive-extends/first-extended');
const cwd = await git.bootstrap('fixtures/recursive-extends/first-extended');
const actual = await load({}, {cwd});
t.deepEqual(actual, {
extends: ['./second-extended'],
Expand All @@ -62,7 +62,7 @@ test('respects cwd option', async t => {
});

test('recursive extends', async t => {
const cwd = await bootstrap('fixtures/recursive-extends');
const cwd = await git.bootstrap('fixtures/recursive-extends');
const actual = await load({}, {cwd});
t.deepEqual(actual, {
extends: ['./first-extended'],
Expand All @@ -75,7 +75,7 @@ test('recursive extends', async t => {
});

test('recursive extends with json file', async t => {
const cwd = await bootstrap('fixtures/recursive-extends-json');
const cwd = await git.bootstrap('fixtures/recursive-extends-json');
const actual = await load({}, {cwd});

t.deepEqual(actual, {
Expand All @@ -89,7 +89,7 @@ test('recursive extends with json file', async t => {
});

test('recursive extends with yaml file', async t => {
const cwd = await bootstrap('fixtures/recursive-extends-yaml');
const cwd = await git.bootstrap('fixtures/recursive-extends-yaml');
const actual = await load({}, {cwd});

t.deepEqual(actual, {
Expand All @@ -103,7 +103,7 @@ test('recursive extends with yaml file', async t => {
});

test('recursive extends with js file', async t => {
const cwd = await bootstrap('fixtures/recursive-extends-js');
const cwd = await git.bootstrap('fixtures/recursive-extends-js');
const actual = await load({}, {cwd});

t.deepEqual(actual, {
Expand All @@ -117,7 +117,7 @@ test('recursive extends with js file', async t => {
});

test('recursive extends with package.json file', async t => {
const cwd = await bootstrap('fixtures/recursive-extends-package');
const cwd = await git.bootstrap('fixtures/recursive-extends-package');
const actual = await load({}, {cwd});

t.deepEqual(actual, {
Expand All @@ -131,7 +131,7 @@ test('recursive extends with package.json file', async t => {
});

test('parser preset overwrites completely instead of merging', async t => {
const cwd = await bootstrap('fixtures/parser-preset-override');
const cwd = await git.bootstrap('fixtures/parser-preset-override');
const actual = await load({}, {cwd});

t.is(actual.parserPreset.name, './custom');
Expand All @@ -145,7 +145,7 @@ test('parser preset overwrites completely instead of merging', async t => {
});

test('recursive extends with parserPreset', async t => {
const cwd = await bootstrap('fixtures/recursive-parser-preset');
const cwd = await git.bootstrap('fixtures/recursive-parser-preset');
const actual = await load({}, {cwd});

t.is(actual.parserPreset.name, './conventional-changelog-custom');
Expand All @@ -157,7 +157,7 @@ test('recursive extends with parserPreset', async t => {
});

test('ignores unknow keys', async t => {
const cwd = await bootstrap('fixtures/trash-file');
const cwd = await git.bootstrap('fixtures/trash-file');
const actual = await load({}, {cwd});

t.deepEqual(actual, {
Expand All @@ -170,7 +170,7 @@ test('ignores unknow keys', async t => {
});

test('ignores unknow keys recursively', async t => {
const cwd = await bootstrap('fixtures/trash-extend');
const cwd = await git.bootstrap('fixtures/trash-extend');
const actual = await load({}, {cwd});

t.deepEqual(actual, {
Expand Down
10 changes: 5 additions & 5 deletions @commitlint/core/src/read.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {git} from '@commitlint/test';
import test from 'ava';
import execa from 'execa';
import * as sander from '@marionebl/sander';

import pkg from '../package';
import {bootstrap, clone} from './test-git';
import read from './read';

test('get edit commit message from git root', async t => {
const cwd = await bootstrap();
const cwd = await git.bootstrap();

await sander.writeFile(cwd, 'alpha.txt', 'alpha');
await execa('git', ['add', '.'], {cwd});
Expand All @@ -18,7 +18,7 @@ test('get edit commit message from git root', async t => {
});

test('get history commit messages', async t => {
const cwd = await bootstrap();
const cwd = await git.bootstrap();
await sander.writeFile(cwd, 'alpha.txt', 'alpha');
await execa('git', ['add', 'alpha.txt'], {cwd});
await execa('git', ['commit', '-m', 'alpha'], {cwd});
Expand All @@ -31,7 +31,7 @@ test('get history commit messages', async t => {
});

test('get edit commit message from git subdirectory', async t => {
const cwd = await bootstrap();
const cwd = await git.bootstrap();
await sander.mkdir(cwd, 'beta');
await sander.writeFile(cwd, 'beta/beta.txt', 'beta');

Expand All @@ -44,7 +44,7 @@ test('get edit commit message from git subdirectory', async t => {
});

test('get history commit messages from shallow clone', async t => {
const cwd = await clone(pkg.repository.url, '--depth', '1');
const cwd = await git.clone(pkg.repository.url, '--depth', '1');
const err = await t.throws(read({from: 'master', cwd}));

t.true(
Expand Down
70 changes: 70 additions & 0 deletions @commitlint/test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"name": "@commitlint/test",
"version": "3.1.1",
"description": "test utilities for @commitlint",
"main": "lib/",
"private": true,
"scripts": {
"pretest": "dep-check",
"test": "ava -c 4",
"build": "cross-env NODE_ENV=production babel src --out-dir lib --source-maps",
"watch": "babel src --out-dir lib --watch --source-maps",
"clean": "rimraf lib",
"prepublish": "npm run build"
},
"ava": {
"files": [
"src/**/*.test.js",
"!lib/**/*"
],
"source": [
"src/**/*.js",
"!lib/**/*"
],
"babel": "inherit",
"require": [
"babel-register"
]
},
"babel": {
"presets": [
"babel-preset-commitlint"
]
},
"xo": false,
"engines": {
"node": ">=4"
},
"repository": {
"type": "git",
"url": "https://github.com/marionebl/commitlint.git"
},
"bugs": {
"url": "https://github.com/marionebl/commitlint/issues"
},
"homepage": "https://github.com/marionebl/commitlint#readme",
"keywords": [
"conventional-changelog",
"commitlint",
"cli"
],
"author": {
"name": "Mario Nebl",
"email": "hello@herebecode.com"
},
"license": "MIT",
"dependencies": {
"@marionebl/sander": "^0.6.1",
"execa": "^0.8.0",
"pkg-dir": "^2.0.0"
},
"devDependencies": {
"@commitlint/utils": "^3.1.1",
"ava": "0.22.0",
"babel-cli": "^6.26.0",
"babel-preset-commitlint": "^3.2.0",
"babel-register": "^6.26.0",
"cross-env": "^5.0.1",
"rimraf": "2.6.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@ import crypto from 'crypto';
import os from 'os';
import path from 'path';

import execa from 'execa';
import * as sander from '@marionebl/sander';
import execa from 'execa';
import pkgDir from 'pkg-dir';

export {bootstrap, clone};

const PKG_ROOT = path.join(__dirname, '..');

async function bootstrap(fixture) {
const cwd = path.join(os.tmpdir(), rand());

if (typeof fixture !== 'undefined') {
await sander.copydir(PKG_ROOT, fixture).to(cwd);
await sander.copydir(await pkgDir(), fixture).to(cwd);
}

await execa('git', ['init', cwd]);
Expand Down
3 changes: 3 additions & 0 deletions @commitlint/test/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import * as git from './git';

export {git};
14 changes: 14 additions & 0 deletions @commitlint/test/src/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import test from 'ava';
import * as u from '.';

test('exports a git namespace', t => {
t.is(typeof u.git, 'object');
});

test('git namespace has bootstrap', t => {
t.is(typeof u.git.bootstrap, 'function');
});

test('git namespace has clone', t => {
t.is(typeof u.git.clone, 'function');
});
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
"ignores": [
"@commitlint/**/lib/**",
"@commitlint/**/node_modules"
]
],
"rules": {
"import/prefer-default-export": "off"
}
},
"engines": {
"node": ">=4"
Expand Down

0 comments on commit 1e80f80

Please sign in to comment.