summaryrefslogtreecommitdiff
path: root/packages/backend/test/utils.ts
diff options
context:
space:
mode:
authorおさむのひと <46447427+samunohito@users.noreply.github.com>2024-01-08 17:43:52 +0900
committerGitHub <noreply@github.com>2024-01-08 17:43:52 +0900
commit35ec41fc1eddd7ebf5552e6f0bceebfbfa077a21 (patch)
treed3bb804799399798c5c8d1d4654932c2d25d868e /packages/backend/test/utils.ts
parentfix(backend): `drive/files/update`におけるファイル名のバリデー... (diff)
downloadsharkey-35ec41fc1eddd7ebf5552e6f0bceebfbfa077a21.tar.gz
sharkey-35ec41fc1eddd7ebf5552e6f0bceebfbfa077a21.tar.bz2
sharkey-35ec41fc1eddd7ebf5552e6f0bceebfbfa077a21.zip
enhance(backend): テストの高速化 (#12939)
* enhance(backend): テストの高速化 * add ls * 自動的にマージされるようなので不要 * 起動方法を揃える * fix test
Diffstat (limited to 'packages/backend/test/utils.ts')
-rw-r--r--packages/backend/test/utils.ts49
1 files changed, 44 insertions, 5 deletions
diff --git a/packages/backend/test/utils.ts b/packages/backend/test/utils.ts
index 7c9428d476..2b232a0a5d 100644
--- a/packages/backend/test/utils.ts
+++ b/packages/backend/test/utils.ts
@@ -5,7 +5,7 @@
import * as assert from 'node:assert';
import { readFile } from 'node:fs/promises';
-import { isAbsolute, basename } from 'node:path';
+import { basename, isAbsolute } from 'node:path';
import { randomUUID } from 'node:crypto';
import { inspect } from 'node:util';
import WebSocket, { ClientOptions } from 'ws';
@@ -68,7 +68,11 @@ export const failedApiCall = async <T, >(request: ApiRequest, assertion: {
return res.body;
};
-const request = async (path: string, params: any, me?: UserToken): Promise<{ status: number, headers: Headers, body: any }> => {
+const request = async (path: string, params: any, me?: UserToken): Promise<{
+ status: number,
+ headers: Headers,
+ body: any
+}> => {
const bodyAuth: Record<string, string> = {};
const headers: Record<string, string> = {
'Content-Type': 'application/json',
@@ -275,7 +279,11 @@ interface UploadOptions {
* Upload file
* @param user User
*/
-export const uploadFile = async (user?: UserToken, { path, name, blob }: UploadOptions = {}): Promise<{ status: number, headers: Headers, body: misskey.Endpoints['drive/files/create']['res'] | null }> => {
+export const uploadFile = async (user?: UserToken, { path, name, blob }: UploadOptions = {}): Promise<{
+ status: number,
+ headers: Headers,
+ body: misskey.Endpoints['drive/files/create']['res'] | null
+}> => {
const absPath = path == null
? new URL('resources/Lenna.jpg', import.meta.url)
: isAbsolute(path.toString())
@@ -426,8 +434,8 @@ 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()) :
+ jsonTypes.includes(res.headers.get('content-type') ?? '') ? await res.json() :
+ htmlTypes.includes(res.headers.get('content-type') ?? '') ? new JSDOM(await res.text()) :
null;
return {
@@ -557,3 +565,34 @@ export function sleep(msec: number) {
}, msec);
});
}
+
+export async function sendEnvUpdateRequest(params: { key: string, value?: string }) {
+ const res = await fetch(
+ `http://localhost:${port + 1000}/env`,
+ {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify(params),
+ },
+ );
+
+ if (res.status !== 200) {
+ throw new Error('server env update failed.');
+ }
+}
+
+export async function sendEnvResetRequest() {
+ const res = await fetch(
+ `http://localhost:${port + 1000}/env-reset`,
+ {
+ method: 'POST',
+ body: JSON.stringify({}),
+ },
+ );
+
+ if (res.status !== 200) {
+ throw new Error('server env update failed.');
+ }
+}