Skip to content

Commit

Permalink
test(rules): migrate read tests from ava to jest
Browse files Browse the repository at this point in the history
  • Loading branch information
armano2 committed Jan 26, 2020
1 parent 10556ec commit cddbf09
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 32 deletions.
22 changes: 0 additions & 22 deletions @commitlint/read/package.json
Expand Up @@ -11,29 +11,8 @@
"deps": "dep-check",
"pkg": "pkg-check --skip-import",
"start": "concurrently \"ava -c 4 --verbose --watch\" \"yarn run watch\"",
"test": "ava -c 4 --verbose",
"watch": "babel src --out-dir lib --watch --source-maps"
},
"ava": {
"files": [
"src/**/*.test.js",
"!lib/**/*"
],
"source": [
"src/**/*.js",
"!lib/**/*"
],
"babel": {
"testOptions": {
"presets": [
"babel-preset-commitlint"
]
}
},
"require": [
"@babel/register"
]
},
"babel": {
"presets": [
"babel-preset-commitlint"
Expand Down Expand Up @@ -67,7 +46,6 @@
"@babel/register": "7.7.7",
"@commitlint/test": "8.2.0",
"@commitlint/utils": "^8.3.4",
"ava": "2.4.0",
"babel-preset-commitlint": "^8.2.0",
"concurrently": "3.6.1",
"cross-env": "6.0.3",
Expand Down
17 changes: 8 additions & 9 deletions @commitlint/read/src/index.test.js
@@ -1,32 +1,31 @@
import {git} from '@commitlint/test';
import test from 'ava';
import execa from 'execa';
import * as sander from '@marionebl/sander';

import read from '.';

test('get edit commit message specified by the `edit` flag', async t => {
test('get edit commit message specified by the `edit` flag', async () => {
const cwd = await git.bootstrap();

await sander.writeFile(cwd, 'commit-msg-file', 'foo');

const expected = ['foo\n'];
const actual = await read({edit: 'commit-msg-file', cwd});
t.deepEqual(actual, expected);
expect(actual).toEqual(expected);
});

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

await sander.writeFile(cwd, 'alpha.txt', 'alpha');
await execa('git', ['add', '.'], {cwd});
await execa('git', ['commit', '-m', 'alpha'], {cwd});
const expected = ['alpha\n\n'];
const actual = await read({edit: true, cwd});
t.deepEqual(actual, expected);
expect(actual).toEqual(expected);
});

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

const expected = ['remove alpha\n\n', 'alpha\n\n'];
const actual = await read({cwd});
t.deepEqual(actual, expected);
expect(actual).toEqual(expected);
});

test('get edit commit message from git subdirectory', async t => {
test('get edit commit message from git subdirectory', async () => {
const cwd = await git.bootstrap();
await sander.mkdir(cwd, 'beta');
await sander.writeFile(cwd, 'beta/beta.txt', 'beta');
Expand All @@ -49,5 +48,5 @@ test('get edit commit message from git subdirectory', async t => {

const expected = ['beta\n\n'];
const actual = await read({edit: true, cwd});
t.deepEqual(actual, expected);
expect(actual).toEqual(expected);
});
6 changes: 5 additions & 1 deletion jest.config.js
Expand Up @@ -2,5 +2,9 @@ module.exports = {
preset: 'ts-jest/presets/js-with-babel',
testEnvironment: 'node',
testRegex: undefined,
testMatch: ['**/*.test.ts?(x)', '**/@commitlint/rules/src/*.test.js?(x)']
testMatch: [
'**/*.test.ts?(x)',
'**/@commitlint/rules/src/*.test.js?(x)',
'**/@commitlint/read/src/*.test.js?(x)'
]
};

0 comments on commit cddbf09

Please sign in to comment.