Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: AI-commands tests with pnpm #31250

Merged
merged 3 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions packages/ai-commands/babel.config.js

This file was deleted.

15 changes: 0 additions & 15 deletions packages/ai-commands/jest.config.js

This file was deleted.

12 changes: 3 additions & 9 deletions packages/ai-commands/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"preinstall": "npx only-allow pnpm",
"clean": "rimraf node_modules",
"typecheck": "tsc --noEmit",
"test": "jest"
"test": "vitest"
},
"dependencies": {
"@serafin/schema-builder": "^0.18.5",
Expand All @@ -23,21 +23,15 @@
},
"devDependencies": {
"@ai-sdk/openai": "^0.0.72",
"@babel/core": "^7.23.6",
"@babel/preset-env": "^7.23.6",
"@jest/globals": "^29.7.0",
"@types/common-tags": "^1.8.4",
"api-types": "workspace:*",
"babel-jest": "^29.7.0",
"babel-plugin-transform-import-meta": "^2.2.1",
"chalk": "^5.3.0",
"dotenv": "^16.3.1",
"jest": "^29.7.0",
"libpg-query": "15.2.0",
"mdast-util-from-markdown": "^2.0.0",
"sql-formatter": "^15.0.2",
"ts-jest": "^29.1.1",
"tsconfig": "workspace:*",
"typescript": "~5.5.0"
"typescript": "~5.5.0",
"vitest": "^2.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`debug fix order of operations 1`] = `
exports[`debug > fix order of operations 1`] = `
"create table departments (
id bigint primary key generated always as identity,
name text
Expand All @@ -14,7 +14,7 @@ create table employees (
);"
`;

exports[`debug fix typos 1`] = `
exports[`debug > fix typos 1`] = `
"select
*
from
Expand Down
7 changes: 4 additions & 3 deletions packages/ai-commands/src/sql/functions.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { describe, expect, test } from '@jest/globals'
import { codeBlock } from 'common-tags'
import OpenAI from 'openai'
import { describe, expect, test } from 'vitest'

import { formatSql } from '../../test/util'
import { debugSql, titleSql } from './functions'

const openAiKey = process.env.OPENAI_API_KEY
const openai = new OpenAI({ apiKey: openAiKey })

describe('debug', () => {
test.concurrent('fix order of operations', async () => {
test.concurrent('fix order of operations', async ({ expect }) => {
const { sql } = await debugSql(
openai,
'relation "departments" does not exist',
Expand All @@ -30,7 +31,7 @@ describe('debug', () => {
expect(formatSql(sql)).toMatchSnapshot()
})

test.concurrent('fix typos', async () => {
test.concurrent('fix typos', async ({ expect }) => {
const { sql, solution } = await debugSql(
openai,
'syntax error at or near "fromm"',
Expand Down
3 changes: 2 additions & 1 deletion packages/ai-commands/src/sql/rls.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, expect, test } from '@jest/globals'
import { codeBlock } from 'common-tags'
import OpenAI from 'openai'
import { describe, expect, test } from 'vitest'

import {
assertAndRenderColumn,
assertAndUnwrapNode,
Expand Down
16 changes: 9 additions & 7 deletions packages/ai-commands/test/extensions.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
declare module 'expect' {
interface AsymmetricMatchers {
toMatchCriteria(criteria: string): void
}
interface Matchers<R> {
toMatchCriteria(criteria: string): R
}
import 'vitest'

interface CustomMatchers<R = unknown> {
toMatchCriteria(criteria: string): R
}

declare module 'vitest' {
interface Assertion<T = any> extends CustomMatchers<T> {}
interface AsymmetricMatchersContaining extends CustomMatchers {}
}
8 changes: 4 additions & 4 deletions packages/ai-commands/test/extensions.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { expect } from '@jest/globals'
import { expect } from 'vitest'
import { codeBlock } from 'common-tags'
import OpenAI from 'openai'

const openAiKey = process.env.OPENAI_API_KEY
const openai = new OpenAI({ apiKey: openAiKey })

expect.extend({
async toMatchCriteria(received: string, criteria: string) {
const openAiKey = process.env.OPENAI_API_KEY
const openai = new OpenAI({ apiKey: openAiKey })

const model = 'gpt-4o-2024-05-13'

const completionResponse = await openai.chat.completions.create({
Expand Down
11 changes: 11 additions & 0 deletions packages/ai-commands/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/// <reference types="vitest" />

import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
environment: 'node',
testTimeout: 30000,
setupFiles: ['./vitest.setup.ts'],
},
})
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { config } from 'dotenv'
import { statSync } from 'fs'
import './test/extensions'

if (!process.env.CI) {
// Use keys from studio .env.local for local tests
Expand Down
Loading
Loading