chore: AI-commands tests with pnpm (#31250)

* Remove jest and add vitest in its place. Refactor the jest setup into vitest.

* Modify the expect extensions to work with vitest.

* FIx the tests.
This commit is contained in:
Ivan Vasilov
2024-12-20 17:32:19 +01:00
committed by GitHub
parent 3045a76634
commit 8693222124
11 changed files with 83 additions and 1223 deletions

View File

@@ -1,4 +0,0 @@
module.exports = {
presets: [['@babel/preset-env', { targets: { node: 'current' } }]],
plugins: ['babel-plugin-transform-import-meta'],
}

View File

@@ -1,15 +0,0 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
transform: {
'^.+\\.ts?$': 'ts-jest',
'^.+\\.(js|jsx)$': 'babel-jest',
},
setupFiles: ['./test/setup.ts'],
setupFilesAfterEnv: ['./test/extensions.ts'],
testTimeout: 30000,
transformIgnorePatterns: [
'node_modules/(?!(mdast-.*|micromark|micromark-.*|unist-.*|decode-named-character-reference|character-entities|chalk)/)',
],
}

View File

@@ -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",
@@ -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"
}
}

View File

@@ -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
@@ -14,7 +14,7 @@ create table employees (
);"
`;
exports[`debug fix typos 1`] = `
exports[`debug > fix typos 1`] = `
"select
*
from

View File

@@ -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 { formatSql } from '../../test/util'
import { debugSql, titleSql } from './functions'
@@ -8,7 +9,7 @@ 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',
@@ -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"',

View File

@@ -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,

View File

@@ -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 {}
}

View File

@@ -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({

View File

@@ -0,0 +1,11 @@
/// <reference types="vitest" />
import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
environment: 'node',
testTimeout: 30000,
setupFiles: ['./vitest.setup.ts'],
},
})

View File

@@ -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

1223
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff