Skip to content

Commit

Permalink
test: Add test case for generateCommitMessage function
Browse files Browse the repository at this point in the history
Add a new test case in the openai.spec.ts file to test the generateCommitMessage function. The test generates the git diff message and logs it for testing purposes.
  • Loading branch information
ThijSlim committed Mar 22, 2023
1 parent 9182111 commit 57860f9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion tests/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe } from 'manten';

describe('aicommits', ({ runTestSuite }) => {
runTestSuite(import('./specs/openai.spec.js'));
// runTestSuite(import('./specs/cli.spec.js'));
// runTestSuite(import('./specs/config.spec.js'));
runTestSuite(import('./specs/openai.spec.js'));
});
24 changes: 10 additions & 14 deletions tests/specs/openai.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ import { CommitMessage, generateCommitMessage } from '../../src/utils/openai.js'
const { OPENAI_KEY } = process.env;

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');
return;
}

if (!OPENAI_KEY) {
console.warn('⚠️ process.env.OPENAI_KEY is necessary to run these tests. Skipping...');
return;
Expand All @@ -37,24 +31,26 @@ export default testSuite(({ describe }) => {
role: 'system',
content: systemPrompt,
},
{
role: 'assistant',
content: 'I want you to output only the git diff',
},
{
role: 'user',
content: typeOfChanges,
},
],
temperature: 0.7,
top_p: 1,
frequency_penalty: 0,
presence_penalty: 0,
stream: false,
n: 1,
});

if (!completion.data.choices[0].message) {
const gitDiffMessage = completion.data.choices[0].message;

if (!gitDiffMessage) {
throw new Error('Failed to generate git diff for test');
}

return completion.data.choices[0].message.content;
console.log(gitDiffMessage);

return gitDiffMessage.content;
}

async function runGenerateCommitMessage(gitDiff: string)
Expand Down

0 comments on commit 57860f9

Please sign in to comment.