fix(hook): Windows support (#176)

This commit is contained in:
hiroki osame
2023-04-02 05:54:11 -04:00
committed by GitHub
parent f6d43f242c
commit 225558394b
6 changed files with 107 additions and 23 deletions

View File

@@ -3,4 +3,5 @@ import { describe } from 'manten';
describe('aicommits', ({ runTestSuite }) => {
runTestSuite(import('./specs/cli/index.js'));
runTestSuite(import('./specs/config.js'));
runTestSuite(import('./specs/git-hook.js'));
});

View File

@@ -1,7 +1,5 @@
import { testSuite, expect } from 'manten';
import { createFixture, createGit } from '../../utils.js';
const { OPENAI_KEY } = process.env;
import { createFixture, createGit, files } from '../../utils.js';
export default testSuite(({ describe }) => {
if (process.platform === 'win32') {
@@ -10,17 +8,12 @@ export default testSuite(({ describe }) => {
return;
}
if (!OPENAI_KEY) {
if (!process.env.OPENAI_KEY) {
console.warn('⚠️ process.env.OPENAI_KEY is necessary to run these tests. Skipping...');
return;
}
describe('CLI', async ({ test, describe }) => {
const files = {
'.aicommits': `OPENAI_KEY=${OPENAI_KEY}`,
'data.json': 'Lorem ipsum dolor sit amet '.repeat(10),
} as const;
test('Excludes files', async () => {
const { fixture, aicommits } = await createFixture(files);
const git = await createGit(fixture.path);

40
tests/specs/git-hook.ts Normal file
View File

@@ -0,0 +1,40 @@
import { testSuite, expect } from 'manten';
import { createFixture, createGit, files } from '../utils.js';
export default testSuite(({ describe }) => {
describe('Git hook', ({ test }) => {
test('errors when not in Git repo', async () => {
const { fixture, aicommits } = await createFixture(files);
const { exitCode, stderr } = await aicommits(['hook', 'install'], {
reject: false,
});
expect(exitCode).toBe(1);
expect(stderr).toMatch('The current directory must be a Git repository');
await fixture.rm();
});
test('Commits', async () => {
const { fixture, aicommits } = await createFixture(files);
const git = await createGit(fixture.path);
const { stdout } = await aicommits(['hook', 'install']);
expect(stdout).toMatch('Hook installed');
await git('add', ['data.json']);
await git('commit', ['--no-edit'], {
env: {
HOME: fixture.path,
USERPROFILE: fixture.path,
},
});
const { stdout: commitMessage } = await git('log', ['--pretty=%B']);
console.log('Committed with:', commitMessage);
expect(commitMessage.startsWith('# ')).not.toBe(true);
await fixture.rm();
});
});
});

View File

@@ -72,3 +72,8 @@ export const createFixture = async (
aicommits,
};
};
export const files = Object.freeze({
'.aicommits': `OPENAI_KEY=${process.env.OPENAI_KEY}`,
'data.json': 'Lorem ipsum dolor sit amet '.repeat(10),
});