File tree Expand file tree Collapse file tree 3 files changed +63
-1
lines changed
packages/ai-vercel-adapter Expand file tree Collapse file tree 3 files changed +63
-1
lines changed Original file line number Diff line number Diff line change 1+ //@ts -ignore
2+ globalThis . __DEV__ = true ;
3+
4+ import { TextDecoder , TextEncoder } from "util" ;
5+ import "@testing-library/jest-dom" ;
6+
7+ global . TextEncoder ??= TextEncoder ;
8+ // @ts -ignore
9+ global . TextDecoder ??= TextDecoder ;
10+
11+ function fail ( reason = "fail was called in a test." ) {
12+ expect ( reason ) . toBe ( undefined ) ;
13+ }
14+
15+ // @ts -ignore
16+ globalThis . fail = fail ;
17+
18+ if ( ! Symbol . dispose ) {
19+ Object . defineProperty ( Symbol , "dispose" , {
20+ value : Symbol ( "dispose" ) ,
21+ } ) ;
22+ }
23+ if ( ! Symbol . asyncDispose ) {
24+ Object . defineProperty ( Symbol , "asyncDispose" , {
25+ value : Symbol ( "asyncDispose" ) ,
26+ } ) ;
27+ }
28+
29+ // not available in JSDOM 🙄
30+ global . structuredClone = ( val ) => JSON . parse ( JSON . stringify ( val ) ) ;
31+ global . ReadableStream ||= require ( "stream/web" ) . ReadableStream ;
32+ global . TransformStream ||= require ( "stream/web" ) . TransformStream ;
33+
34+ AbortSignal . timeout = ( ms ) => {
35+ const controller = new AbortController ( ) ;
36+ setTimeout (
37+ ( ) =>
38+ controller . abort (
39+ new DOMException ( "The operation timed out." , "TimeoutError" )
40+ ) ,
41+ ms
42+ ) ;
43+ return controller . signal ;
44+ } ;
Original file line number Diff line number Diff line change @@ -3,7 +3,8 @@ import { fileURLToPath } from "node:url";
33
44export default {
55 rootDir : "src" ,
6- preset : "ts-jest" ,
6+ preset : "ts-jest/presets/default-esm" ,
7+ extensionsToTreatAsEsm : [ ".ts" ] ,
78 testEnvironment : fileURLToPath (
89 import . meta. resolve ( "../../config/FixJSDOMEnvironment.js" )
910 ) ,
@@ -21,9 +22,16 @@ export default {
2122 {
2223 isolatedModules : true ,
2324 tsconfig : join ( import . meta. dirname , "tsconfig.json" ) ,
25+ useESM : true ,
2426 } ,
2527 ] ,
2628 } ,
29+ resolver : fileURLToPath (
30+ import . meta. resolve ( "../../src/config/jest/resolver.ts" )
31+ ) ,
32+ moduleNameMapper : {
33+ "^@apollo/client-ai$" : join ( import . meta. dirname , "../ai/src/index.ts" ) ,
34+ } ,
2735 transformIgnorePatterns : [ "/node_modules/(?!(rxjs)/)" ] ,
2836 prettierPath : null ,
2937 testMatch : [ "**/__tests__/**/*.test.ts" , "**/__tests__/**/*.test.tsx" ] ,
Original file line number Diff line number Diff line change 1+ import { VercelAIAdapter } from "../VercelAIAdapter.js" ;
2+
3+ describe ( "VercelAIAdapter" , ( ) => {
4+ it ( "should be able to be instantiated" , ( ) => {
5+ const adapter = new VercelAIAdapter ( {
6+ model : "gpt-4o-mini" ,
7+ } ) ;
8+ expect ( adapter ) . toBeInstanceOf ( VercelAIAdapter ) ;
9+ } ) ;
10+ } ) ;
You can’t perform that action at this time.
0 commit comments