test: refactor fixtures
This commit is contained in:
@@ -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(<scope>):"
|
||||
@@ -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(<scope>):"
|
||||
@@ -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(<style>):"
|
||||
@@ -111,7 +109,7 @@ export default testSuite(({ describe }) => {
|
||||
});
|
||||
|
||||
await test('Should use "chore:" conventional commit when change relate to a chore or maintenance', async () => {
|
||||
const gitDiff = await readDiffFromFile('chore.txt');
|
||||
const gitDiff = await getDiff('chore.diff');
|
||||
const commitMessage = await runGenerateCommitMessage(gitDiff);
|
||||
|
||||
// should match "chore:" or "chore(<style>):"
|
||||
@@ -121,7 +119,7 @@ export default testSuite(({ describe }) => {
|
||||
});
|
||||
|
||||
await test('Should use "perf:" conventional commit when change relate to a performance improvement', async () => {
|
||||
const gitDiff = await readDiffFromFile('performance-improvement.txt');
|
||||
const gitDiff = await getDiff('performance-improvement.diff');
|
||||
const commitMessage = await runGenerateCommitMessage(gitDiff);
|
||||
|
||||
// should match "perf:" or "perf(<style>):"
|
||||
@@ -143,19 +141,5 @@ export default testSuite(({ describe }) => {
|
||||
|
||||
return commitMessages[0];
|
||||
}
|
||||
|
||||
/*
|
||||
* See ./diffs/README.md in order to generate diff files
|
||||
*/
|
||||
async function readDiffFromFile(filename: string): Promise<string> {
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
const gitDiff = await readFile(
|
||||
path.resolve(__dirname, `./diff-fixtures/${filename}`),
|
||||
'utf8',
|
||||
);
|
||||
|
||||
return gitDiff;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import path from 'path';
|
||||
import fs from 'fs/promises';
|
||||
import { execa, execaNode, type Options } from 'execa';
|
||||
import {
|
||||
createFixture as createFixtureBase,
|
||||
@@ -83,3 +84,9 @@ export const assertOpenAiToken = () => {
|
||||
throw new Error('⚠️ process.env.OPENAI_KEY is necessary to run these tests. Skipping...');
|
||||
}
|
||||
};
|
||||
|
||||
// See ./diffs/README.md in order to generate diff files
|
||||
export const getDiff = async (diffName: string): Promise<string> => fs.readFile(
|
||||
new URL(`fixtures/${diffName}`, import.meta.url),
|
||||
'utf8',
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user