1- import { runCommand } from "@oclif/test" ;
21import { describe , it , beforeAll , afterAll , afterEach , expect } from "vitest" ;
32import Sinon from "sinon" ;
4- import { BaseCommand } from "../../dist/cli/base-command.js" ;
3+ import { clearPlebbitRpcConnectOverride , setPlebbitRpcConnectOverride } from "../helpers/plebbit-test-overrides.js" ;
4+ import { runCliCommand } from "../helpers/run-cli.js" ;
55
66describe ( "bitsocial community get" , ( ) => {
77 const sandbox = Sinon . createSandbox ( ) ;
@@ -20,25 +20,27 @@ describe("bitsocial community get", () => {
2020 getSubplebbit : getSubplebbitFake ,
2121 destroy : destroyFake
2222 } ) ;
23- //@ts -expect-error
24- sandbox . replace ( BaseCommand . prototype , "_connectToPlebbitRpc" , plebbitInstanceFake ) ;
23+ setPlebbitRpcConnectOverride ( plebbitInstanceFake ) ;
2524 } ) ;
2625
2726 afterEach ( ( ) => {
2827 getSubplebbitFake . resetHistory ( ) ;
2928 destroyFake . resetHistory ( ) ;
3029 } ) ;
3130
32- afterAll ( ( ) => sandbox . restore ( ) ) ;
31+ afterAll ( ( ) => {
32+ clearPlebbitRpcConnectOverride ( ) ;
33+ sandbox . restore ( ) ;
34+ } ) ;
3335
3436 it ( "Outputs community json and keeps posts first" , async ( ) => {
35- const result = await runCommand ( "community get plebbit.eth" , process . cwd ( ) , { stripAnsi : true } ) ;
37+ const { result, stdout } = await runCliCommand ( "community get plebbit.eth" ) ;
3638
3739 expect ( result . error ) . toBeUndefined ( ) ;
3840 expect ( getSubplebbitFake . calledOnceWith ( { address : "plebbit.eth" } ) ) . toBe ( true ) ;
3941 expect ( destroyFake . calledOnce ) . toBe ( true ) ;
4042
41- const output = result . stdout . trim ( ) ;
43+ const output = stdout . trim ( ) ;
4244 const parsed = JSON . parse ( output ) ;
4345 expect ( parsed ) . toEqual ( fakeCommunity ) ;
4446
0 commit comments