File tree Expand file tree Collapse file tree 2 files changed +67
-0
lines changed Expand file tree Collapse file tree 2 files changed +67
-0
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 1+ import { AIAdapter } from "../AIAdapter.js" ;
2+
3+ class DerivedAdapter extends AIAdapter {
4+ constructor ( ) {
5+ super ( ) ;
6+ }
7+
8+ public generateObject ( prompt : string ) : Promise < any > {
9+ return Promise . resolve ( {
10+ data : null ,
11+ } ) ;
12+ }
13+ }
14+
15+ describe ( "AIAdapter derived class" , ( ) => {
16+ it ( "should be able to generate an object" , async ( ) => {
17+ const adapter = new DerivedAdapter ( ) ;
18+ const result = await adapter . generateObject ( "Hello, world!" ) ;
19+ expect ( result ) . toEqual ( {
20+ data : null ,
21+ } ) ;
22+ } ) ;
23+ } ) ;
You can’t perform that action at this time.
0 commit comments