diff --git a/tests/specs/openai/diff-fixtures/README.md b/tests/fixtures/README.md similarity index 100% rename from tests/specs/openai/diff-fixtures/README.md rename to tests/fixtures/README.md diff --git a/tests/specs/openai/diff-fixtures/chore.txt b/tests/fixtures/chore.diff similarity index 100% rename from tests/specs/openai/diff-fixtures/chore.txt rename to tests/fixtures/chore.diff diff --git a/tests/specs/openai/diff-fixtures/code-refactoring.txt b/tests/fixtures/code-refactoring.diff similarity index 100% rename from tests/specs/openai/diff-fixtures/code-refactoring.txt rename to tests/fixtures/code-refactoring.diff diff --git a/tests/specs/openai/diff-fixtures/code-style.txt b/tests/fixtures/code-style.diff similarity index 100% rename from tests/specs/openai/diff-fixtures/code-style.txt rename to tests/fixtures/code-style.diff diff --git a/tests/specs/openai/diff-fixtures/continous-integration.txt b/tests/fixtures/continous-integration.diff similarity index 100% rename from tests/specs/openai/diff-fixtures/continous-integration.txt rename to tests/fixtures/continous-integration.diff diff --git a/tests/specs/openai/diff-fixtures/deprecate-feature.txt b/tests/fixtures/deprecate-feature.diff similarity index 100% rename from tests/specs/openai/diff-fixtures/deprecate-feature.txt rename to tests/fixtures/deprecate-feature.diff diff --git a/tests/specs/openai/diff-fixtures/documentation-changes.txt b/tests/fixtures/documentation-changes.diff similarity index 100% rename from tests/specs/openai/diff-fixtures/documentation-changes.txt rename to tests/fixtures/documentation-changes.diff diff --git a/tests/specs/openai/diff-fixtures/fix-nullpointer-exception.txt b/tests/fixtures/fix-nullpointer-exception.diff similarity index 100% rename from tests/specs/openai/diff-fixtures/fix-nullpointer-exception.txt rename to tests/fixtures/fix-nullpointer-exception.diff diff --git a/tests/specs/openai/diff-fixtures/github-action-build-pipeline.txt b/tests/fixtures/github-action-build-pipeline.diff similarity index 100% rename from tests/specs/openai/diff-fixtures/github-action-build-pipeline.txt rename to tests/fixtures/github-action-build-pipeline.diff diff --git a/tests/specs/openai/diff-fixtures/new-feature.txt b/tests/fixtures/new-feature.diff similarity index 100% rename from tests/specs/openai/diff-fixtures/new-feature.txt rename to tests/fixtures/new-feature.diff diff --git a/tests/specs/openai/diff-fixtures/performance-improvement.txt b/tests/fixtures/performance-improvement.diff similarity index 100% rename from tests/specs/openai/diff-fixtures/performance-improvement.txt rename to tests/fixtures/performance-improvement.diff diff --git a/tests/specs/openai/diff-fixtures/remove-feature.txt b/tests/fixtures/remove-feature.diff similarity index 100% rename from tests/specs/openai/diff-fixtures/remove-feature.txt rename to tests/fixtures/remove-feature.diff diff --git a/tests/specs/openai/diff-fixtures/testing-react-application.txt b/tests/fixtures/testing-react-application.diff similarity index 100% rename from tests/specs/openai/diff-fixtures/testing-react-application.txt rename to tests/fixtures/testing-react-application.diff diff --git a/tests/specs/openai/conventional-commits.ts b/tests/specs/openai/conventional-commits.ts index 1fd537ee..b89255eb 100644 --- a/tests/specs/openai/conventional-commits.ts +++ b/tests/specs/openai/conventional-commits.ts @@ -1,11 +1,9 @@ -import { readFile } from 'fs/promises'; -import path from 'path'; -import { fileURLToPath } from 'url'; import { expect, testSuite } from 'manten'; import { generateCommitMessage, } from '../../../src/utils/openai.js'; import type { ValidConfig } from '../../../src/utils/config.js'; +import { getDiff } from '../../utils.js'; const { OPENAI_KEY } = process.env; @@ -19,7 +17,7 @@ export default testSuite(({ describe }) => { await test('Should not translate conventional commit type to Japanase when locale config is set to japanese', async () => { const japaneseConventionalCommitPattern = /(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\(.*\))?: [\u3000-\u303F\u3040-\u309F\u30A0-\u30FF\uFF00-\uFF9F\u4E00-\u9FAF\u3400-\u4DBF]/; - const gitDiff = await readDiffFromFile('new-feature.txt'); + const gitDiff = await getDiff('new-feature.diff'); const commitMessage = await runGenerateCommitMessage(gitDiff, { locale: 'ja', @@ -30,7 +28,7 @@ export default testSuite(({ describe }) => { }); await test('Should use "feat:" conventional commit when change relate to adding a new feature', async () => { - const gitDiff = await readDiffFromFile('new-feature.txt'); + const gitDiff = await getDiff('new-feature.diff'); const commitMessage = await runGenerateCommitMessage(gitDiff); @@ -40,7 +38,7 @@ export default testSuite(({ describe }) => { }); await test('Should use "refactor:" conventional commit when change relate to code refactoring', async () => { - const gitDiff = await readDiffFromFile('code-refactoring.txt'); + const gitDiff = await getDiff('code-refactoring.diff'); const commitMessage = await runGenerateCommitMessage(gitDiff); @@ -50,7 +48,7 @@ export default testSuite(({ describe }) => { }); await test('Should use "test:" conventional commit when change relate to testing a React application', async () => { - const gitDiff = await readDiffFromFile('testing-react-application.txt'); + const gitDiff = await getDiff('testing-react-application.diff'); const commitMessage = await runGenerateCommitMessage(gitDiff); @@ -60,8 +58,8 @@ export default testSuite(({ describe }) => { }); await test('Should use "build:" conventional commit when change relate to github action build pipeline', async () => { - const gitDiff = await readDiffFromFile( - 'github-action-build-pipeline.txt', + const gitDiff = await getDiff( + 'github-action-build-pipeline.diff', ); const commitMessage = await runGenerateCommitMessage(gitDiff); @@ -72,7 +70,7 @@ export default testSuite(({ describe }) => { }); await test('Should use "(ci|build):" conventional commit when change relate to continious integration', async () => { - const gitDiff = await readDiffFromFile('continous-integration.txt'); + const gitDiff = await getDiff('continous-integration.diff'); const commitMessage = await runGenerateCommitMessage(gitDiff); @@ -83,7 +81,7 @@ export default testSuite(({ describe }) => { }); await test('Should use "docs:" conventional commit when change relate to documentation changes', async () => { - const gitDiff = await readDiffFromFile('documentation-changes.txt'); + const gitDiff = await getDiff('documentation-changes.diff'); const commitMessage = await runGenerateCommitMessage(gitDiff); // should match "docs:" or "docs():" @@ -92,7 +90,7 @@ export default testSuite(({ describe }) => { }); await test('Should use "fix:" conventional commit when change relate to fixing code', async () => { - const gitDiff = await readDiffFromFile('fix-nullpointer-exception.txt'); + const gitDiff = await getDiff('fix-nullpointer-exception.diff'); const commitMessage = await runGenerateCommitMessage(gitDiff); // should match "fix:" or "fix():" @@ -102,7 +100,7 @@ export default testSuite(({ describe }) => { }); await test('Should use "style:" conventional commit when change relate to code style improvements', async () => { - const gitDiff = await readDiffFromFile('code-style.txt'); + const gitDiff = await getDiff('code-style.diff'); const commitMessage = await runGenerateCommitMessage(gitDiff); // should match "style:" or "style(