@@ -3,24 +3,34 @@ import { existsSync } from "node:fs";
33import fs from "node:fs/promises" ;
44import path from "node:path" ;
55
6+ import Redis from "ioredis" ;
67import NodeEnvironment from "jest-environment-node" ;
78
89import {
910 createOAuthAPIClient ,
1011 createRestAPIClient ,
1112 type mastodon ,
1213} from "../src" ;
13- import { TokenPoolFsImpl } from "./pools" ;
14- import { TokenFactoryDocker } from "./pools/token-factory-docker" ;
15- import { TokenRepositoryFs } from "./pools/token-repository-fs" ;
14+ import { TokenFactoryDocker , TokenPoolRedis } from "./pools" ;
1615import { createTootctl } from "./tootctl" ;
1716
1817class CustomEnvironment extends NodeEnvironment {
18+ redis ! : Redis ;
19+
1920 override async setup ( ) : Promise < void > {
2021 await super . setup ( ) ;
21- const misc = await this . createGlobals ( ) ;
22- this . global . __misc__ = misc ;
23- this . global . Symbol = Symbol ;
22+ this . redis = new Redis ( ) ;
23+ this . global . __misc__ = await this . createGlobals ( ) ;
24+
25+ /* eslint-disable @typescript-eslint/no-explicit-any */
26+ ( this . global . Symbol as any ) . dispose ??= Symbol ( "Symbol.dispose" ) ;
27+ ( this . global . Symbol as any ) . asyncDispose ??= Symbol ( "Symbol.asyncDispose" ) ;
28+ /* eslint-enable @typescript-eslint/no-explicit-any */
29+ }
30+
31+ override async teardown ( ) : Promise < void > {
32+ await super . teardown ( ) ;
33+ this . redis . disconnect ( ) ;
2434 }
2535
2636 private async createGlobals ( ) : Promise < typeof globalThis . __misc__ > {
@@ -33,15 +43,12 @@ class CustomEnvironment extends NodeEnvironment {
3343 }
3444
3545 const adminToken = await this . readAdminToken ( baseCacheDir ) ;
36- const repository = new TokenRepositoryFs (
37- path . join ( baseCacheDir , "tokens.json" ) ,
38- ) ;
3946 const container = process . env . MASTODON_CONTAINER ?? "mastodon" ;
40- const tootctl = createTootctl ( { container } ) ;
47+ const tootctl = createTootctl ( { container, compose : true } ) ;
4148 const oauth = createOAuthAPIClient ( { url } ) ;
4249 const app = await this . readApp ( baseCacheDir ) ;
4350 const factory = new TokenFactoryDocker ( tootctl , oauth , app ) ;
44- const tokenPool = new TokenPoolFsImpl ( repository , factory ) ;
51+ const tokenPool = new TokenPoolRedis ( this . redis , factory ) ;
4552
4653 return {
4754 url,
0 commit comments