formatting and fixed type error
This commit is contained in:
@@ -9,7 +9,9 @@ import {
|
||||
export default testSuite(({ describe }) => {
|
||||
if (process.platform === 'win32') {
|
||||
// https://github.com/nodejs/node/issues/31409
|
||||
console.warn('Skipping tests on Windows because Node.js spawn cant open TTYs');
|
||||
console.warn(
|
||||
'Skipping tests on Windows because Node.js spawn cant open TTYs'
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -21,10 +23,15 @@ export default testSuite(({ describe }) => {
|
||||
const git = await createGit(fixture.path);
|
||||
|
||||
await git('add', ['data.json']);
|
||||
const statusBefore = await git('status', ['--porcelain', '--untracked-files=no']);
|
||||
const statusBefore = await git('status', [
|
||||
'--porcelain',
|
||||
'--untracked-files=no',
|
||||
]);
|
||||
expect(statusBefore.stdout).toBe('A data.json');
|
||||
|
||||
const { stdout, exitCode } = await aicommits(['--exclude', 'data.json'], { reject: false });
|
||||
const { stdout, exitCode } = await aicommits(['--exclude', 'data.json'], {
|
||||
reject: false,
|
||||
});
|
||||
expect(exitCode).toBe(1);
|
||||
expect(stdout).toMatch('No staged changes found.');
|
||||
await fixture.rm();
|
||||
@@ -47,10 +54,15 @@ export default testSuite(({ describe }) => {
|
||||
|
||||
await committing;
|
||||
|
||||
const statusAfter = await git('status', ['--porcelain', '--untracked-files=no']);
|
||||
const statusAfter = await git('status', [
|
||||
'--porcelain',
|
||||
'--untracked-files=no',
|
||||
]);
|
||||
expect(statusAfter.stdout).toBe('');
|
||||
|
||||
const { stdout: commitMessage } = await git('log', ['--pretty=format:%s']);
|
||||
const { stdout: commitMessage } = await git('log', [
|
||||
'--pretty=format:%s',
|
||||
]);
|
||||
console.log({
|
||||
commitMessage,
|
||||
length: commitMessage.length,
|
||||
@@ -81,7 +93,9 @@ export default testSuite(({ describe }) => {
|
||||
|
||||
await committing;
|
||||
|
||||
const { stdout: commitMessage } = await git('log', ['--pretty=format:%s']);
|
||||
const { stdout: commitMessage } = await git('log', [
|
||||
'--pretty=format:%s',
|
||||
]);
|
||||
console.log({
|
||||
commitMessage,
|
||||
length: commitMessage.length,
|
||||
@@ -118,7 +132,10 @@ export default testSuite(({ describe }) => {
|
||||
const statusAfter = await git('status', ['--short']);
|
||||
expect(statusAfter.stdout).toBe('?? .aicommits');
|
||||
|
||||
const { stdout: commitMessage } = await git('log', ['-n1', '--pretty=format:%s']);
|
||||
const { stdout: commitMessage } = await git('log', [
|
||||
'-n1',
|
||||
'--pretty=format:%s',
|
||||
]);
|
||||
console.log({
|
||||
commitMessage,
|
||||
length: commitMessage.length,
|
||||
@@ -128,7 +145,9 @@ export default testSuite(({ describe }) => {
|
||||
await fixture.rm();
|
||||
});
|
||||
|
||||
test('Accepts --generate flag, overriding config', async ({ onTestFail }) => {
|
||||
test('Accepts --generate flag, overriding config', async ({
|
||||
onTestFail,
|
||||
}) => {
|
||||
const { fixture, aicommits } = await createFixture({
|
||||
...files,
|
||||
'.aicommits': `${files['.aicommits']}\ngenerate=4`,
|
||||
@@ -138,9 +157,7 @@ export default testSuite(({ describe }) => {
|
||||
await git('add', ['data.json']);
|
||||
|
||||
// Generate flag should override generate config
|
||||
const committing = aicommits([
|
||||
'--generate', '2',
|
||||
]);
|
||||
const committing = aicommits(['--generate', '2']);
|
||||
|
||||
// Hit enter to accept the commit message
|
||||
committing.stdout!.on('data', function onPrompt(buffer: Buffer) {
|
||||
@@ -158,10 +175,15 @@ export default testSuite(({ describe }) => {
|
||||
onTestFail(() => console.log({ stdout }));
|
||||
expect(countChoices).toBe(2);
|
||||
|
||||
const statusAfter = await git('status', ['--porcelain', '--untracked-files=no']);
|
||||
const statusAfter = await git('status', [
|
||||
'--porcelain',
|
||||
'--untracked-files=no',
|
||||
]);
|
||||
expect(statusAfter.stdout).toBe('');
|
||||
|
||||
const { stdout: commitMessage } = await git('log', ['--pretty=format:%s']);
|
||||
const { stdout: commitMessage } = await git('log', [
|
||||
'--pretty=format:%s',
|
||||
]);
|
||||
console.log({
|
||||
commitMessage,
|
||||
length: commitMessage.length,
|
||||
@@ -173,7 +195,8 @@ export default testSuite(({ describe }) => {
|
||||
|
||||
test('Generates Japanese commit message via locale config', async () => {
|
||||
// https://stackoverflow.com/a/15034560/911407
|
||||
const japanesePattern = /[\u3000-\u303F\u3040-\u309F\u30A0-\u30FF\uFF00-\uFF9F\u4E00-\u9FAF\u3400-\u4DBF]/;
|
||||
const japanesePattern =
|
||||
/[\u3000-\u303F\u3040-\u309F\u30A0-\u30FF\uFF00-\uFF9F\u4E00-\u9FAF\u3400-\u4DBF]/;
|
||||
|
||||
const { fixture, aicommits } = await createFixture({
|
||||
...files,
|
||||
@@ -195,10 +218,15 @@ export default testSuite(({ describe }) => {
|
||||
|
||||
await committing;
|
||||
|
||||
const statusAfter = await git('status', ['--porcelain', '--untracked-files=no']);
|
||||
const statusAfter = await git('status', [
|
||||
'--porcelain',
|
||||
'--untracked-files=no',
|
||||
]);
|
||||
expect(statusAfter.stdout).toBe('');
|
||||
|
||||
const { stdout: commitMessage } = await git('log', ['--pretty=format:%s']);
|
||||
const { stdout: commitMessage } = await git('log', [
|
||||
'--pretty=format:%s',
|
||||
]);
|
||||
console.log({
|
||||
commitMessage,
|
||||
length: commitMessage.length,
|
||||
@@ -211,7 +239,8 @@ export default testSuite(({ describe }) => {
|
||||
|
||||
describe('commit types', ({ test }) => {
|
||||
test('Should not use conventional commits by default', async () => {
|
||||
const conventionalCommitPattern = /(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test):\s/;
|
||||
const conventionalCommitPattern =
|
||||
/(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test):\s/;
|
||||
const { fixture, aicommits } = await createFixture({
|
||||
...files,
|
||||
});
|
||||
@@ -231,7 +260,10 @@ export default testSuite(({ describe }) => {
|
||||
|
||||
await committing;
|
||||
|
||||
const statusAfter = await git('status', ['--porcelain', '--untracked-files=no']);
|
||||
const statusAfter = await git('status', [
|
||||
'--porcelain',
|
||||
'--untracked-files=no',
|
||||
]);
|
||||
expect(statusAfter.stdout).toBe('');
|
||||
|
||||
const { stdout: commitMessage } = await git('log', ['--oneline']);
|
||||
@@ -242,7 +274,8 @@ export default testSuite(({ describe }) => {
|
||||
});
|
||||
|
||||
test('Conventional commits', async () => {
|
||||
const conventionalCommitPattern = /(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test):\s/;
|
||||
const conventionalCommitPattern =
|
||||
/(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test):\s/;
|
||||
const { fixture, aicommits } = await createFixture({
|
||||
...files,
|
||||
'.aicommits': `${files['.aicommits']}\ntype=conventional`,
|
||||
@@ -263,7 +296,10 @@ export default testSuite(({ describe }) => {
|
||||
|
||||
await committing;
|
||||
|
||||
const statusAfter = await git('status', ['--porcelain', '--untracked-files=no']);
|
||||
const statusAfter = await git('status', [
|
||||
'--porcelain',
|
||||
'--untracked-files=no',
|
||||
]);
|
||||
expect(statusAfter.stdout).toBe('');
|
||||
|
||||
const { stdout: commitMessage } = await git('log', ['--oneline']);
|
||||
@@ -274,7 +310,8 @@ export default testSuite(({ describe }) => {
|
||||
});
|
||||
|
||||
test('Accepts --type flag, overriding config', async () => {
|
||||
const conventionalCommitPattern = /(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test):\s/;
|
||||
const conventionalCommitPattern =
|
||||
/(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test):\s/;
|
||||
const { fixture, aicommits } = await createFixture({
|
||||
...files,
|
||||
'.aicommits': `${files['.aicommits']}\ntype=other`,
|
||||
@@ -284,9 +321,7 @@ export default testSuite(({ describe }) => {
|
||||
await git('add', ['data.json']);
|
||||
|
||||
// Generate flag should override generate config
|
||||
const committing = aicommits([
|
||||
'--type', 'conventional',
|
||||
]);
|
||||
const committing = aicommits(['--type', 'conventional']);
|
||||
|
||||
committing.stdout!.on('data', (buffer: Buffer) => {
|
||||
const stdout = buffer.toString();
|
||||
@@ -298,7 +333,10 @@ export default testSuite(({ describe }) => {
|
||||
|
||||
await committing;
|
||||
|
||||
const statusAfter = await git('status', ['--porcelain', '--untracked-files=no']);
|
||||
const statusAfter = await git('status', [
|
||||
'--porcelain',
|
||||
'--untracked-files=no',
|
||||
]);
|
||||
expect(statusAfter.stdout).toBe('');
|
||||
|
||||
const { stdout: commitMessage } = await git('log', ['--oneline']);
|
||||
@@ -309,7 +347,8 @@ export default testSuite(({ describe }) => {
|
||||
});
|
||||
|
||||
test('Accepts empty --type flag', async () => {
|
||||
const conventionalCommitPattern = /(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test):\s/;
|
||||
const conventionalCommitPattern =
|
||||
/(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test):\s/;
|
||||
const { fixture, aicommits } = await createFixture({
|
||||
...files,
|
||||
'.aicommits': `${files['.aicommits']}\ntype=conventional`,
|
||||
@@ -318,9 +357,7 @@ export default testSuite(({ describe }) => {
|
||||
|
||||
await git('add', ['data.json']);
|
||||
|
||||
const committing = aicommits([
|
||||
'--type', '',
|
||||
]);
|
||||
const committing = aicommits(['--type', '']);
|
||||
|
||||
committing.stdout!.on('data', (buffer: Buffer) => {
|
||||
const stdout = buffer.toString();
|
||||
@@ -332,7 +369,10 @@ export default testSuite(({ describe }) => {
|
||||
|
||||
await committing;
|
||||
|
||||
const statusAfter = await git('status', ['--porcelain', '--untracked-files=no']);
|
||||
const statusAfter = await git('status', [
|
||||
'--porcelain',
|
||||
'--untracked-files=no',
|
||||
]);
|
||||
expect(statusAfter.stdout).toBe('');
|
||||
|
||||
const { stdout: commitMessage } = await git('log', ['--oneline']);
|
||||
@@ -394,10 +434,15 @@ export default testSuite(({ describe }) => {
|
||||
|
||||
await committing;
|
||||
|
||||
const statusAfter = await git('status', ['--porcelain', '--untracked-files=no']);
|
||||
const statusAfter = await git('status', [
|
||||
'--porcelain',
|
||||
'--untracked-files=no',
|
||||
]);
|
||||
expect(statusAfter.stdout).toBe('');
|
||||
|
||||
const { stdout: commitMessage } = await git('log', ['--pretty=format:%s']);
|
||||
const { stdout: commitMessage } = await git('log', [
|
||||
'--pretty=format:%s',
|
||||
]);
|
||||
console.log({
|
||||
commitMessage,
|
||||
length: commitMessage.length,
|
||||
@@ -429,10 +474,15 @@ export default testSuite(({ describe }) => {
|
||||
|
||||
await committing;
|
||||
|
||||
const statusAfter = await git('status', ['--porcelain', '--untracked-files=no']);
|
||||
const statusAfter = await git('status', [
|
||||
'--porcelain',
|
||||
'--untracked-files=no',
|
||||
]);
|
||||
expect(statusAfter.stdout).toBe('');
|
||||
|
||||
const { stdout: commitMessage } = await git('log', ['--pretty=format:%s']);
|
||||
const { stdout: commitMessage } = await git('log', [
|
||||
'--pretty=format:%s',
|
||||
]);
|
||||
console.log({
|
||||
commitMessage,
|
||||
length: commitMessage.length,
|
||||
|
||||
@@ -17,7 +17,9 @@ export default testSuite(({ describe }) => {
|
||||
|
||||
const { stdout, exitCode } = await aicommits([], { reject: false });
|
||||
expect(exitCode).toBe(1);
|
||||
expect(stdout).toMatch('No staged changes found. Stage your changes manually, or automatically stage all changes with the `--all` flag.');
|
||||
expect(stdout).toMatch(
|
||||
'No staged changes found. Stage your changes manually, or automatically stage all changes with the `--all` flag.'
|
||||
);
|
||||
await fixture.rm();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user