Skip to content

Commit

Permalink
Refactor test files and fix linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
PrashamTrivedi committed Sep 13, 2024
1 parent c7dc7d7 commit e9d55ad
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion _tests_/gemini.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ describe('GeminiInference', () => {
})

const result = await geminiInference.inferDependency('{"dependencies": {}}', 'test', true, false)
expect(typeof result[Symbol.asyncIterator]).toBe('function')
expect(typeof (result as AsyncIterable<string>)[Symbol.asyncIterator]).toBe('function')

let streamedResult = ''
for await (const chunk of result as AsyncIterable<string>) {
Expand Down
34 changes: 21 additions & 13 deletions _tests_/openai.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import {describe, it, expect, vi, beforeEach, afterEach} from 'vitest'
import OpenAI from 'openai'
import OpenAIInferrence from "../openai.mjs"
import { Stream } from 'openai/streaming'
import {Stream} from 'openai/streaming'

// Mock OpenAI
vi.mock('openai')
Expand All @@ -11,15 +11,15 @@ vi.mock('openai')
vi.spyOn(console, 'log').mockImplementation(() => { })

// Mock Stream
class MockStream extends Stream<OpenAI.Chat.Completions.ChatCompletionChunk> {
private chunks: string[];
class MockStream {
private chunks: string[]
constructor(chunks: string[]) {
super();
this.chunks = chunks;

this.chunks = chunks
}
async *[Symbol.asyncIterator]() {
for (const chunk of this.chunks) {
yield { choices: [{ delta: { content: chunk } }] } as OpenAI.Chat.Completions.ChatCompletionChunk;
yield {choices: [{delta: {content: chunk}}]} as OpenAI.Chat.Completions.ChatCompletionChunk
}
}
}
Expand Down Expand Up @@ -175,7 +175,7 @@ describe('OpenAIInferrence', () => {
const result = await openAIInferrence.inferDependency('{"dependencies": {}}', 'test', true, false)
expect(result).toBeInstanceOf(Object)
expect(Symbol.asyncIterator in (result as any)).toBe(true)

let streamedContent = ''
for await (const chunk of result as AsyncIterable<string>) {
streamedContent += chunk
Expand Down Expand Up @@ -220,7 +220,7 @@ describe('OpenAIInferrence', () => {
const result = await openAIInferrence.inferCode('const x = 5;', true, false)
expect(result).toBeInstanceOf(Object)
expect(Symbol.asyncIterator in (result as any)).toBe(true)

let streamedContent = ''
for await (const chunk of result as AsyncIterable<string>) {
streamedContent += chunk
Expand Down Expand Up @@ -262,7 +262,7 @@ describe('OpenAIInferrence', () => {
const result = await openAIInferrence.inferInterestingCode('class AdvancedComponent { /* ... */ }', true, false)
expect(result).toBeInstanceOf(Object)
expect(Symbol.asyncIterator in (result as any)).toBe(true)

let streamedContent = ''
if (result) {
for await (const chunk of result as AsyncIterable<string>) {
Expand Down Expand Up @@ -339,8 +339,12 @@ describe('OpenAIInferrence', () => {

const result = await openAIInferrence.generateReadme('{}', '{}', '{}', true, false)
expect(result).toBeInstanceOf(Object)
expect(Symbol.asyncIterator in result).toBe(true)

if (result && typeof result !== 'string' && Symbol.asyncIterator in result) {
expect(Symbol.asyncIterator in result).toBe(true)
} else {
throw new Error('Result is not an AsyncIterable<string>')
}

let streamedContent = ''
for await (const chunk of result as AsyncIterable<string>) {
streamedContent += chunk
Expand Down Expand Up @@ -402,8 +406,12 @@ describe('OpenAIInferrence', () => {

const result = await openAIInferrence.generateMonorepoReadme('{}', true, false)
expect(result).toBeInstanceOf(Object)
expect(Symbol.asyncIterator in result).toBe(true)

if (result && typeof result !== 'string' && Symbol.asyncIterator in result) {
expect(Symbol.asyncIterator in result).toBe(true)
} else {
throw new Error('Result is not an AsyncIterable<string>')
}

let streamedContent = ''
for await (const chunk of result as AsyncIterable<string>) {
streamedContent += chunk
Expand Down

0 comments on commit e9d55ad

Please sign in to comment.