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

test(read): migrate read tests from ava to jest #904

Merged
merged 2 commits into from Jan 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
});
5 changes: 4 additions & 1 deletion jest.config.js
Expand Up @@ -2,5 +2,8 @@ module.exports = {
preset: 'ts-jest/presets/js-with-babel',
testEnvironment: 'node',
testRegex: undefined,
testMatch: ['**/*.test.ts?(x)']
testMatch: [
'**/*.test.ts?(x)',
'**/@commitlint/read/src/*.test.js?(x)'
]
};