1- import * as mf from "@hongminhee/deno-mock-fetch" ;
21import { assertEquals } from "@std/assert" ;
2+ import fetchMock from "fetch-mock" ;
33import { test } from "../testing/mod.ts" ;
44import {
55 getNodeInfo ,
@@ -19,20 +19,17 @@ import type {
1919} from "./types.ts" ;
2020
2121test ( "getNodeInfo()" , async ( t ) => {
22- mf . install ( ) ;
22+ fetchMock . spyGlobal ( ) ;
2323
24- mf . mock ( "GET@/.well-known/nodeinfo" , ( req ) => {
25- assertEquals ( new URL ( req . url ) . host , "example.com" ) ;
26- return new Response (
27- JSON . stringify ( {
28- links : [
29- {
30- rel : "http://nodeinfo.diaspora.software/ns/schema/2.1" ,
31- href : "https://example.com/nodeinfo/2.1" ,
32- } ,
33- ] ,
34- } ) ,
35- ) ;
24+ fetchMock . get ( "https://example.com/.well-known/nodeinfo" , {
25+ body : {
26+ links : [
27+ {
28+ rel : "http://nodeinfo.diaspora.software/ns/schema/2.1" ,
29+ href : "https://example.com/nodeinfo/2.1" ,
30+ } ,
31+ ] ,
32+ } ,
3633 } ) ;
3734
3835 const rawExpected = {
@@ -41,17 +38,8 @@ test("getNodeInfo()", async (t) => {
4138 usage : { users : { } , localPosts : 123 , localComments : 456 } ,
4239 } ;
4340
44- mf . mock ( "GET@/nodeinfo/2.1" , ( req ) => {
45- assertEquals ( new URL ( req . url ) . host , "example.com" ) ;
46- return new Response (
47- JSON . stringify ( rawExpected ) ,
48- ) ;
49- } ) ;
50-
51- mf . mock ( "GET@/404" , ( req ) => {
52- assertEquals ( new URL ( req . url ) . host , "example.com" ) ;
53- return new Response ( null , { status : 404 } ) ;
54- } ) ;
41+ fetchMock . get ( "https://example.com/nodeinfo/2.1" , { body : rawExpected } ) ;
42+ fetchMock . get ( "https://example.com/404" , { status : 404 } ) ;
5543
5644 const expected : NodeInfo = {
5745 software : {
@@ -78,21 +66,19 @@ test("getNodeInfo()", async (t) => {
7866 assertEquals ( info , expected ) ;
7967 } ) ;
8068
81- mf . mock ( "GET@/.well-known/nodeinfo" , ( req ) => {
82- assertEquals ( new URL ( req . url ) . host , "example.com" ) ;
83- return new Response ( JSON . stringify ( {
84- links : [ ] ,
85- } ) ) ;
69+ fetchMock . removeRoutes ( ) ;
70+ fetchMock . get ( "https://example.com/.well-known/nodeinfo" , {
71+ body : { links : [ ] } ,
8672 } ) ;
8773
8874 await t . step ( "indirect: no links" , async ( ) => {
8975 const info = await getNodeInfo ( "https://example.com/" ) ;
9076 assertEquals ( info , undefined ) ;
9177 } ) ;
9278
93- mf . mock ( "GET@/.well-known/nodeinfo" , ( req ) => {
94- assertEquals ( new URL ( req . url ) . host , " example.com" ) ;
95- return new Response ( null , { status : 404 } ) ;
79+ fetchMock . removeRoutes ( ) ;
80+ fetchMock . get ( "https:// example.com/.well-known/nodeinfo" , {
81+ status : 404 ,
9682 } ) ;
9783
9884 await t . step ( "indirect: 404" , async ( ) => {
@@ -113,7 +99,7 @@ test("getNodeInfo()", async (t) => {
11399 assertEquals ( info2 , undefined ) ;
114100 } ) ;
115101
116- mf . uninstall ( ) ;
102+ fetchMock . hardReset ( ) ;
117103} ) ;
118104
119105test ( "parseNodeInfo()" , ( ) => {
0 commit comments