Skip to content

Commit 1e80f80

Browse files
committed
chore: move git test utils to seperate package
1 parent 8f35dae commit 1e80f80

File tree

8 files changed

+117
-27
lines changed

8 files changed

+117
-27
lines changed

@commitlint/core/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"license": "MIT",
6464
"devDependencies": {
6565
"@commitlint/utils": "^3.1.1",
66+
"@commitlint/test": "^3.1.1",
6667
"ava": "0.22.0",
6768
"babel-cli": "^6.26.0",
6869
"babel-preset-commitlint": "^3.2.0",

@commitlint/core/src/load.test.js

+17-17
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1+
import {git} from '@commitlint/test';
12
import test from 'ava';
23

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

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

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

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

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

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

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

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

6464
test('recursive extends', async t => {
65-
const cwd = await bootstrap('fixtures/recursive-extends');
65+
const cwd = await git.bootstrap('fixtures/recursive-extends');
6666
const actual = await load({}, {cwd});
6767
t.deepEqual(actual, {
6868
extends: ['./first-extended'],
@@ -75,7 +75,7 @@ test('recursive extends', async t => {
7575
});
7676

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

176176
t.deepEqual(actual, {

@commitlint/core/src/read.test.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
import {git} from '@commitlint/test';
12
import test from 'ava';
23
import execa from 'execa';
34
import * as sander from '@marionebl/sander';
45

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

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

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

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

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

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

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

5050
t.true(

@commitlint/test/package.json

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"name": "@commitlint/test",
3+
"version": "3.1.1",
4+
"description": "test utilities for @commitlint",
5+
"main": "lib/",
6+
"private": true,
7+
"scripts": {
8+
"pretest": "dep-check",
9+
"test": "ava -c 4",
10+
"build": "cross-env NODE_ENV=production babel src --out-dir lib --source-maps",
11+
"watch": "babel src --out-dir lib --watch --source-maps",
12+
"clean": "rimraf lib",
13+
"prepublish": "npm run build"
14+
},
15+
"ava": {
16+
"files": [
17+
"src/**/*.test.js",
18+
"!lib/**/*"
19+
],
20+
"source": [
21+
"src/**/*.js",
22+
"!lib/**/*"
23+
],
24+
"babel": "inherit",
25+
"require": [
26+
"babel-register"
27+
]
28+
},
29+
"babel": {
30+
"presets": [
31+
"babel-preset-commitlint"
32+
]
33+
},
34+
"xo": false,
35+
"engines": {
36+
"node": ">=4"
37+
},
38+
"repository": {
39+
"type": "git",
40+
"url": "https://github.com/marionebl/commitlint.git"
41+
},
42+
"bugs": {
43+
"url": "https://github.com/marionebl/commitlint/issues"
44+
},
45+
"homepage": "https://github.com/marionebl/commitlint#readme",
46+
"keywords": [
47+
"conventional-changelog",
48+
"commitlint",
49+
"cli"
50+
],
51+
"author": {
52+
"name": "Mario Nebl",
53+
"email": "[email protected]"
54+
},
55+
"license": "MIT",
56+
"dependencies": {
57+
"@marionebl/sander": "^0.6.1",
58+
"execa": "^0.8.0",
59+
"pkg-dir": "^2.0.0"
60+
},
61+
"devDependencies": {
62+
"@commitlint/utils": "^3.1.1",
63+
"ava": "0.22.0",
64+
"babel-cli": "^6.26.0",
65+
"babel-preset-commitlint": "^3.2.0",
66+
"babel-register": "^6.26.0",
67+
"cross-env": "^5.0.1",
68+
"rimraf": "2.6.1"
69+
}
70+
}

@commitlint/core/src/test-git.js renamed to @commitlint/test/src/git.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@ import crypto from 'crypto';
22
import os from 'os';
33
import path from 'path';
44

5-
import execa from 'execa';
65
import * as sander from '@marionebl/sander';
6+
import execa from 'execa';
7+
import pkgDir from 'pkg-dir';
78

89
export {bootstrap, clone};
910

10-
const PKG_ROOT = path.join(__dirname, '..');
11-
1211
async function bootstrap(fixture) {
1312
const cwd = path.join(os.tmpdir(), rand());
1413

1514
if (typeof fixture !== 'undefined') {
16-
await sander.copydir(PKG_ROOT, fixture).to(cwd);
15+
await sander.copydir(await pkgDir(), fixture).to(cwd);
1716
}
1817

1918
await execa('git', ['init', cwd]);

@commitlint/test/src/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import * as git from './git';
2+
3+
export {git};

@commitlint/test/src/index.test.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import test from 'ava';
2+
import * as u from '.';
3+
4+
test('exports a git namespace', t => {
5+
t.is(typeof u.git, 'object');
6+
});
7+
8+
test('git namespace has bootstrap', t => {
9+
t.is(typeof u.git.bootstrap, 'function');
10+
});
11+
12+
test('git namespace has clone', t => {
13+
t.is(typeof u.git.clone, 'function');
14+
});

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131
"ignores": [
3232
"@commitlint/**/lib/**",
3333
"@commitlint/**/node_modules"
34-
]
34+
],
35+
"rules": {
36+
"import/prefer-default-export": "off"
37+
}
3538
},
3639
"engines": {
3740
"node": ">=4"

0 commit comments

Comments
 (0)