ci: run tests (#145)
This commit is contained in:
5
tests/index.ts
Normal file
5
tests/index.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { describe } from 'manten';
|
||||
|
||||
describe('aicommits', ({ runTestSuite }) => {
|
||||
runTestSuite(import('./specs/config.js'));
|
||||
});
|
||||
55
tests/specs/config.ts
Normal file
55
tests/specs/config.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import fs from 'fs/promises';
|
||||
import path from 'path';
|
||||
import { testSuite, expect } from 'manten';
|
||||
import { createFixture } from 'fs-fixture';
|
||||
import { execaNode } from 'execa';
|
||||
|
||||
const aicommitsPath = path.resolve('./dist/cli.mjs');
|
||||
|
||||
export default testSuite(({ describe }) => {
|
||||
describe('config', async ({ test }) => {
|
||||
const fixture = await createFixture();
|
||||
const env = {
|
||||
// Linux
|
||||
HOME: fixture.path,
|
||||
|
||||
// Windows
|
||||
USERPROFILE: fixture.path,
|
||||
};
|
||||
const configPath = path.join(fixture.path, '.aicommits');
|
||||
const openAiToken = 'OPENAI_KEY=sk-abc';
|
||||
|
||||
test('set unknown config file', async () => {
|
||||
const { stderr } = await execaNode(aicommitsPath, ['config', 'set', 'UNKNOWN=1'], {
|
||||
env,
|
||||
reject: false,
|
||||
});
|
||||
|
||||
expect(stderr).toMatch('Invalid config property: UNKNOWN');
|
||||
});
|
||||
|
||||
test('set invalid OPENAI_KEY', async () => {
|
||||
const { stderr } = await execaNode(aicommitsPath, ['config', 'set', 'OPENAI_KEY=abc'], {
|
||||
env,
|
||||
reject: false,
|
||||
});
|
||||
|
||||
expect(stderr).toMatch('Invalid config property OPENAI_KEY: Must start with "sk-"');
|
||||
});
|
||||
|
||||
await test('set config file', async () => {
|
||||
await execaNode(aicommitsPath, ['config', 'set', openAiToken], { env });
|
||||
|
||||
const configFile = await fs.readFile(configPath, 'utf8');
|
||||
expect(configFile).toMatch(openAiToken);
|
||||
});
|
||||
|
||||
await test('get config file', async () => {
|
||||
const { stdout } = await execaNode(aicommitsPath, ['config', 'get', 'OPENAI_KEY'], { env });
|
||||
|
||||
expect(stdout).toBe(openAiToken);
|
||||
});
|
||||
|
||||
await fixture.rm();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user