From 75eee29a4ea4ffd5dc864f8d3034a0a17c507b43 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Sat, 8 Apr 2023 19:39:16 +0900 Subject: [PATCH] test: create token assertion --- tests/specs/cli/commits.ts | 12 +++++++----- tests/specs/git-hook.ts | 9 ++++++++- tests/utils.ts | 6 ++++++ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/tests/specs/cli/commits.ts b/tests/specs/cli/commits.ts index efc70dc3..4662827a 100644 --- a/tests/specs/cli/commits.ts +++ b/tests/specs/cli/commits.ts @@ -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') { @@ -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 () => { diff --git a/tests/specs/git-hook.ts b/tests/specs/git-hook.ts index d2c05bf2..004cb3a3 100644 --- a/tests/specs/git-hook.ts +++ b/tests/specs/git-hook.ts @@ -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'], { diff --git a/tests/utils.ts b/tests/utils.ts index ee5aeba8..12df58f2 100644 --- a/tests/utils.ts +++ b/tests/utils.ts @@ -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...'); + } +};