Skip to content

Commit

Permalink
test: create token assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber committed Apr 8, 2023
1 parent 9b24444 commit 75eee29
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
12 changes: 7 additions & 5 deletions tests/specs/cli/commits.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { testSuite, expect } from 'manten';
import { createFixture, createGit, files } from '../../utils.js';
import {
assertOpenAiToken,
createFixture,
createGit,
files,
} from '../../utils.js';

export default testSuite(({ describe }) => {
if (process.platform === 'win32') {
Expand All @@ -8,10 +13,7 @@ export default testSuite(({ describe }) => {
return;
}

if (!process.env.OPENAI_KEY) {
console.warn('⚠️ process.env.OPENAI_KEY is necessary to run these tests. Skipping...');
return;
}
assertOpenAiToken();

describe('CLI', async ({ test, describe }) => {
test('Excludes files', async () => {
Expand Down
9 changes: 8 additions & 1 deletion tests/specs/git-hook.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { testSuite, expect } from 'manten';
import { createFixture, createGit, files } from '../utils.js';
import {
assertOpenAiToken,
createFixture,
createGit,
files,
} from '../utils.js';

export default testSuite(({ describe }) => {
describe('Git hook', ({ test }) => {
assertOpenAiToken();

test('errors when not in Git repo', async () => {
const { fixture, aicommits } = await createFixture(files);
const { exitCode, stderr } = await aicommits(['hook', 'install'], {
Expand Down
6 changes: 6 additions & 0 deletions tests/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,9 @@ export const files = Object.freeze({
'.aicommits': `OPENAI_KEY=${process.env.OPENAI_KEY}`,
'data.json': 'Lorem ipsum dolor sit amet '.repeat(10),
});

export const assertOpenAiToken = () => {
if (!process.env.OPENAI_KEY) {
throw new Error('⚠️ process.env.OPENAI_KEY is necessary to run these tests. Skipping...');
}
};

0 comments on commit 75eee29

Please sign in to comment.