forked from mirrors/misskey
chore(backend): remove jsdom completely (#16893)
* wip * Update utils.ts * Update fetch-resource.ts * Update exports.ts * Update oauth.ts
This commit is contained in:
@@ -201,7 +201,6 @@
|
||||
"@types/http-link-header": "1.0.7",
|
||||
"@types/jest": "29.5.14",
|
||||
"@types/js-yaml": "4.0.9",
|
||||
"@types/jsdom": "21.1.7",
|
||||
"@types/jsonld": "1.5.15",
|
||||
"@types/jsrsasign": "10.5.15",
|
||||
"@types/mime-types": "2.1.4",
|
||||
@@ -236,7 +235,6 @@
|
||||
"fkill": "9.0.0",
|
||||
"jest": "29.7.0",
|
||||
"jest-mock": "29.7.0",
|
||||
"jsdom": "26.1.0",
|
||||
"nodemon": "3.1.11",
|
||||
"pid-port": "1.0.2",
|
||||
"simple-oauth2": "5.1.0",
|
||||
|
||||
@@ -16,7 +16,7 @@ describe('export-clips', () => {
|
||||
let bob: misskey.entities.SignupResponse;
|
||||
|
||||
// XXX: Any better way to get the result?
|
||||
async function pollFirstDriveFile() {
|
||||
async function pollFirstDriveFile(): Promise<any> {
|
||||
while (true) {
|
||||
const files = (await api('drive/files', {}, alice)).body;
|
||||
if (!files.length) {
|
||||
|
||||
@@ -73,7 +73,7 @@ describe('Webリソース', () => {
|
||||
};
|
||||
|
||||
const metaTag = (res: SimpleGetResponse, key: string, superkey = 'name'): string => {
|
||||
return res.body.window.document.querySelector('meta[' + superkey + '="' + key + '"]')?.content;
|
||||
return res.body.querySelector('meta[' + superkey + '="' + key + '"]')?.attributes.content;
|
||||
};
|
||||
|
||||
beforeAll(async () => {
|
||||
|
||||
@@ -19,7 +19,7 @@ import {
|
||||
ResourceOwnerPassword,
|
||||
} from 'simple-oauth2';
|
||||
import pkceChallenge from 'pkce-challenge';
|
||||
import { JSDOM } from 'jsdom';
|
||||
import * as htmlParser from 'node-html-parser';
|
||||
import Fastify, { type FastifyInstance, type FastifyReply } from 'fastify';
|
||||
import { api, port, sendEnvUpdateRequest, signup } from '../utils.js';
|
||||
import type * as misskey from 'misskey-js';
|
||||
@@ -73,11 +73,11 @@ const clientConfig: ModuleOptions<'client_id'> = {
|
||||
};
|
||||
|
||||
function getMeta(html: string): { transactionId: string | undefined, clientName: string | undefined, clientLogo: string | undefined } {
|
||||
const fragment = JSDOM.fragment(html);
|
||||
const doc = htmlParser.parse(`<div>${html}</div>`);
|
||||
return {
|
||||
transactionId: fragment.querySelector<HTMLMetaElement>('meta[name="misskey:oauth:transaction-id"]')?.content,
|
||||
clientName: fragment.querySelector<HTMLMetaElement>('meta[name="misskey:oauth:client-name"]')?.content,
|
||||
clientLogo: fragment.querySelector<HTMLMetaElement>('meta[name="misskey:oauth:client-logo"]')?.content,
|
||||
transactionId: doc.querySelector('meta[name="misskey:oauth:transaction-id"]')?.attributes.content,
|
||||
clientName: doc.querySelector('meta[name="misskey:oauth:client-name"]')?.attributes.content,
|
||||
clientLogo: doc.querySelector('meta[name="misskey:oauth:client-logo"]')?.attributes.content,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ function assertIndirectError(response: Response, error: string): void {
|
||||
async function assertDirectError(response: Response, status: number, error: string): Promise<void> {
|
||||
assert.strictEqual(response.status, status);
|
||||
|
||||
const data = await response.json();
|
||||
const data = await response.json() as any;
|
||||
assert.strictEqual(data.error, error);
|
||||
}
|
||||
|
||||
@@ -704,7 +704,7 @@ describe('OAuth', () => {
|
||||
const response = await fetch(new URL('.well-known/oauth-authorization-server', host));
|
||||
assert.strictEqual(response.status, 200);
|
||||
|
||||
const body = await response.json();
|
||||
const body = await response.json() as any;
|
||||
assert.strictEqual(body.issuer, 'http://misskey.local');
|
||||
assert.ok(body.scopes_supported.includes('write:notes'));
|
||||
});
|
||||
|
||||
@@ -10,8 +10,8 @@ import { randomUUID } from 'node:crypto';
|
||||
import { inspect } from 'node:util';
|
||||
import WebSocket, { ClientOptions } from 'ws';
|
||||
import fetch, { File, RequestInit, type Headers } from 'node-fetch';
|
||||
import * as htmlParser from 'node-html-parser';
|
||||
import { DataSource } from 'typeorm';
|
||||
import { JSDOM } from 'jsdom';
|
||||
import { type Response } from 'node-fetch';
|
||||
import Fastify from 'fastify';
|
||||
import { entities } from '../src/postgres.js';
|
||||
@@ -468,7 +468,7 @@ export function makeStreamCatcher<T>(
|
||||
|
||||
export type SimpleGetResponse = {
|
||||
status: number,
|
||||
body: any | JSDOM | null,
|
||||
body: any | null,
|
||||
type: string | null,
|
||||
location: string | null
|
||||
};
|
||||
@@ -499,7 +499,7 @@ export const simpleGet = async (path: string, accept = '*/*', cookie: any = unde
|
||||
|
||||
const body =
|
||||
jsonTypes.includes(res.headers.get('content-type') ?? '') ? await res.json() :
|
||||
htmlTypes.includes(res.headers.get('content-type') ?? '') ? new JSDOM(await res.text()) :
|
||||
htmlTypes.includes(res.headers.get('content-type') ?? '') ? htmlParser.parse(await res.text()) :
|
||||
await bodyExtractor(res);
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user