From 1e80f8043ac4c5ce4219c241d63c65d312b97f36 Mon Sep 17 00:00:00 2001 From: Mario Nebl Date: Mon, 9 Oct 2017 11:53:50 +0200 Subject: [PATCH] chore: move git test utils to seperate package --- @commitlint/core/package.json | 1 + @commitlint/core/src/load.test.js | 34 ++++----- @commitlint/core/src/read.test.js | 10 +-- @commitlint/test/package.json | 70 +++++++++++++++++++ .../{core/src/test-git.js => test/src/git.js} | 7 +- @commitlint/test/src/index.js | 3 + @commitlint/test/src/index.test.js | 14 ++++ package.json | 5 +- 8 files changed, 117 insertions(+), 27 deletions(-) create mode 100644 @commitlint/test/package.json rename @commitlint/{core/src/test-git.js => test/src/git.js} (90%) create mode 100644 @commitlint/test/src/index.js create mode 100644 @commitlint/test/src/index.test.js diff --git a/@commitlint/core/package.json b/@commitlint/core/package.json index 084f266d7a..90c5d0aeb0 100644 --- a/@commitlint/core/package.json +++ b/@commitlint/core/package.json @@ -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", diff --git a/@commitlint/core/src/load.test.js b/@commitlint/core/src/load.test.js index 7c51f1790b..4538f9dfdc 100644 --- a/@commitlint/core/src/load.test.js +++ b/@commitlint/core/src/load.test.js @@ -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' @@ -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'], @@ -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'], @@ -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, { @@ -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, { @@ -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, { @@ -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, { @@ -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'); @@ -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'); @@ -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, { @@ -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, { diff --git a/@commitlint/core/src/read.test.js b/@commitlint/core/src/read.test.js index d38b3ff56d..958074d735 100644 --- a/@commitlint/core/src/read.test.js +++ b/@commitlint/core/src/read.test.js @@ -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}); @@ -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}); @@ -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'); @@ -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( diff --git a/@commitlint/test/package.json b/@commitlint/test/package.json new file mode 100644 index 0000000000..d64ab151ea --- /dev/null +++ b/@commitlint/test/package.json @@ -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" + } +} diff --git a/@commitlint/core/src/test-git.js b/@commitlint/test/src/git.js similarity index 90% rename from @commitlint/core/src/test-git.js rename to @commitlint/test/src/git.js index b593db958b..8d535b9950 100644 --- a/@commitlint/core/src/test-git.js +++ b/@commitlint/test/src/git.js @@ -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]); diff --git a/@commitlint/test/src/index.js b/@commitlint/test/src/index.js new file mode 100644 index 0000000000..e6c1e6ba74 --- /dev/null +++ b/@commitlint/test/src/index.js @@ -0,0 +1,3 @@ +import * as git from './git'; + +export {git}; diff --git a/@commitlint/test/src/index.test.js b/@commitlint/test/src/index.test.js new file mode 100644 index 0000000000..a56b32c973 --- /dev/null +++ b/@commitlint/test/src/index.test.js @@ -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'); +}); diff --git a/package.json b/package.json index 0cb27ee194..b0b3e428b9 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,10 @@ "ignores": [ "@commitlint/**/lib/**", "@commitlint/**/node_modules" - ] + ], + "rules": { + "import/prefer-default-export": "off" + } }, "engines": { "node": ">=4"