diff --git a/packages/backend/.mocharc.json b/packages/backend/.mocharc.json index f836f9e90..cfc511621 100644 --- a/packages/backend/.mocharc.json +++ b/packages/backend/.mocharc.json @@ -1,8 +1,6 @@ { - "extension": ["ts","js","cjs","mjs"], "node-option": [ - "experimental-specifier-resolution=node", - "loader=./test/loader.js" + "experimental-specifier-resolution=node" ], "slow": 1000, "timeout": 30000, diff --git a/packages/backend/package.json b/packages/backend/package.json index 097f6ee73..4dcc72456 100644 --- a/packages/backend/package.json +++ b/packages/backend/package.json @@ -8,10 +8,10 @@ "build": "tsc -p tsconfig.json || echo done. && tsc-alias -p tsconfig.json", "watch": "node watch.mjs", "lint": "tsc --noEmit --skipLibCheck && eslint src --ext .ts", - "mocha": "cross-env NODE_ENV=test TS_NODE_FILES=true TS_NODE_TRANSPILE_ONLY=true TS_NODE_PROJECT=\"./test/tsconfig.json\" mocha", + "mocha": "NODE_ENV=test mocha", "migrate": "npx typeorm migration:run -d ormconfig.js", "start": "node --experimental-json-modules ./built/index.js", - "start:test": "cross-env NODE_ENV=test node --experimental-json-modules ./built/index.js", + "start:test": "NODE_ENV=test node --experimental-json-modules ./built/index.js", "test": "npm run mocha" }, "dependencies": { @@ -164,7 +164,6 @@ "@types/ws": "8.5.3", "@typescript-eslint/eslint-plugin": "^5.46.1", "@typescript-eslint/parser": "^5.46.1", - "cross-env": "7.0.3", "eslint": "^8.29.0", "eslint-plugin-foundkey-custom-rules": "file:../shared/custom-rules", "eslint-plugin-import": "^2.26.0", diff --git a/packages/backend/test/activitypub.ts b/packages/backend/test/activitypub.mjs similarity index 80% rename from packages/backend/test/activitypub.ts rename to packages/backend/test/activitypub.mjs index 6ce9c7c8e..844b2dbb1 100644 --- a/packages/backend/test/activitypub.ts +++ b/packages/backend/test/activitypub.mjs @@ -1,11 +1,11 @@ process.env.NODE_ENV = 'test'; import * as assert from 'assert'; -import { initDb } from '../src/db/postgre.js'; -import { initTestDb } from './utils.js'; +import { initDb } from '../built/db/postgre.js'; +import { initTestDb } from './utils.mjs'; -function rndstr(length): string { +function rndstr(length) { const chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; const chars_len = 62; @@ -52,8 +52,8 @@ describe('ActivityPub', () => { }; it('Minimum Actor', async () => { - const { MockResolver } = await import('./misc/mock-resolver.js'); - const { createPerson } = await import('../src/remote/activitypub/models/person.js'); + const { MockResolver } = await import('./misc/mock-resolver.mjs'); + const { createPerson } = await import('../built/remote/activitypub/models/person.js'); const resolver = new MockResolver(); resolver._register(actor.id, actor); @@ -66,8 +66,8 @@ describe('ActivityPub', () => { }); it('Minimum Note', async () => { - const { MockResolver } = await import('./misc/mock-resolver.js'); - const { createNote } = await import('../src/remote/activitypub/models/note.js'); + const { MockResolver } = await import('./misc/mock-resolver.mjs'); + const { createNote } = await import('../built/remote/activitypub/models/note.js'); const resolver = new MockResolver(); resolver._register(actor.id, actor); @@ -99,8 +99,8 @@ describe('ActivityPub', () => { }; it('Actor', async () => { - const { MockResolver } = await import('./misc/mock-resolver.js'); - const { createPerson } = await import('../src/remote/activitypub/models/person.js'); + const { MockResolver } = await import('./misc/mock-resolver.mjs'); + const { createPerson } = await import('../built/remote/activitypub/models/person.js'); const resolver = new MockResolver(); resolver._register(actor.id, actor); diff --git a/packages/backend/test/ap-request.ts b/packages/backend/test/ap-request.mjs similarity index 86% rename from packages/backend/test/ap-request.ts rename to packages/backend/test/ap-request.mjs index 744b2f2c9..8b5fecfa9 100644 --- a/packages/backend/test/ap-request.ts +++ b/packages/backend/test/ap-request.mjs @@ -1,9 +1,9 @@ import * as assert from 'assert'; import httpSignature from '@peertube/http-signature'; -import { genRsaKeyPair } from '../src/misc/gen-key-pair.js'; -import { createSignedPost, createSignedGet } from '../src/remote/activitypub/ap-request.js'; +import { genRsaKeyPair } from '../built/misc/gen-key-pair.js'; +import { createSignedPost, createSignedGet } from '../built/remote/activitypub/ap-request.js'; -export const buildParsedSignature = (signingString: string, signature: string, algorithm: string) => { +export const buildParsedSignature = (signingString, signature, algorithm) => { return { scheme: 'Signature', params: { diff --git a/packages/backend/test/api-visibility.ts b/packages/backend/test/api-visibility.mjs similarity index 94% rename from packages/backend/test/api-visibility.ts rename to packages/backend/test/api-visibility.mjs index 18da1d0c9..941661297 100644 --- a/packages/backend/test/api-visibility.ts +++ b/packages/backend/test/api-visibility.mjs @@ -2,12 +2,12 @@ process.env.NODE_ENV = 'test'; import * as assert from 'assert'; import * as childProcess from 'child_process'; -import { async, signup, request, post, startServer, shutdownServer } from './utils.js'; +import { async, signup, request, post, startServer, shutdownServer } from './utils.mjs'; describe('API visibility', function() { this.timeout(20*60*1000); - let p: childProcess.ChildProcess; + let p; before(async () => { p = await startServer(); @@ -20,48 +20,48 @@ describe('API visibility', function() { describe('Note visibility', async () => { //#region vars /** protagonist */ - let alice: any; + let alice; /** follower */ - let follower: any; + let follower; /** non-follower */ - let other: any; + let other; /** non-follower who has been replied to or mentioned */ - let target: any; + let target; /** actor for which a specified visibility was set */ - let target2: any; + let target2; /** public-post */ - let pub: any; + let pub; /** home-post */ - let home: any; + let home; /** followers-post */ - let fol: any; + let fol; /** specified-post */ - let spe: any; + let spe; /** public-reply to target's post */ - let pubR: any; + let pubR; /** home-reply to target's post */ - let homeR: any; + let homeR; /** followers-reply to target's post */ - let folR: any; + let folR; /** specified-reply to target's post */ - let speR: any; + let speR; /** public-mention to target */ - let pubM: any; + let pubM; /** home-mention to target */ - let homeM: any; + let homeM; /** followers-mention to target */ - let folM: any; + let folM; /** specified-mention to target */ - let speM: any; + let speM; /** reply target post */ - let tgt: any; + let tgt; //#endregion - const show = async (noteId: any, by: any) => { + const show = async (noteId, by) => { return await request('/notes/show', { noteId, }, by); @@ -412,21 +412,21 @@ describe('API visibility', function() { it('[TL] public post on author home TL', async(async () => { const res = await request('/notes/timeline', { limit: 100 }, alice); assert.strictEqual(res.status, 200); - const notes = res.body.filter((n: any) => n.id == pub.id); + const notes = res.body.filter((n) => n.id == pub.id); assert.strictEqual(notes[0].text, 'x'); })); it('[TL] public post absent from non-follower home TL', async(async () => { const res = await request('/notes/timeline', { limit: 100 }, other); assert.strictEqual(res.status, 200); - const notes = res.body.filter((n: any) => n.id == pub.id); + const notes = res.body.filter((n) => n.id == pub.id); assert.strictEqual(notes.length, 0); })); it('[TL] followers post on follower home TL', async(async () => { const res = await request('/notes/timeline', { limit: 100 }, follower); assert.strictEqual(res.status, 200); - const notes = res.body.filter((n: any) => n.id == fol.id); + const notes = res.body.filter((n) => n.id == fol.id); assert.strictEqual(notes[0].text, 'x'); })); //#endregion @@ -435,21 +435,21 @@ describe('API visibility', function() { it('[TL] followers reply on follower reply TL', async(async () => { const res = await request('/notes/replies', { noteId: tgt.id, limit: 100 }, follower); assert.strictEqual(res.status, 200); - const notes = res.body.filter((n: any) => n.id == folR.id); + const notes = res.body.filter((n) => n.id == folR.id); assert.strictEqual(notes[0].text, 'x'); })); it('[TL] followers reply absent from not replied to non-follower reply TL', async(async () => { const res = await request('/notes/replies', { noteId: tgt.id, limit: 100 }, other); assert.strictEqual(res.status, 200); - const notes = res.body.filter((n: any) => n.id == folR.id); + const notes = res.body.filter((n) => n.id == folR.id); assert.strictEqual(notes.length, 0); })); it('[TL] followers reply on replied to actor reply TL', async(async () => { const res = await request('/notes/replies', { noteId: tgt.id, limit: 100 }, target); assert.strictEqual(res.status, 200); - const notes = res.body.filter((n: any) => n.id == folR.id); + const notes = res.body.filter((n) => n.id == folR.id); assert.strictEqual(notes[0].text, 'x'); })); //#endregion @@ -458,14 +458,14 @@ describe('API visibility', function() { it('[TL] followers reply on replied to non-follower mention TL', async(async () => { const res = await request('/notes/mentions', { limit: 100 }, target); assert.strictEqual(res.status, 200); - const notes = res.body.filter((n: any) => n.id == folR.id); + const notes = res.body.filter((n) => n.id == folR.id); assert.strictEqual(notes[0].text, 'x'); })); it('[TL] followers mention on mentioned non-follower mention TL', async(async () => { const res = await request('/notes/mentions', { limit: 100 }, target); assert.strictEqual(res.status, 200); - const notes = res.body.filter((n: any) => n.id == folM.id); + const notes = res.body.filter((n) => n.id == folM.id); assert.strictEqual(notes[0].text, '@target x'); })); //#endregion diff --git a/packages/backend/test/api.ts b/packages/backend/test/api.mjs similarity index 94% rename from packages/backend/test/api.ts rename to packages/backend/test/api.mjs index 8bcef2ea2..7c5b7e0b2 100644 --- a/packages/backend/test/api.ts +++ b/packages/backend/test/api.mjs @@ -2,15 +2,13 @@ process.env.NODE_ENV = 'test'; import * as assert from 'assert'; import * as childProcess from 'child_process'; -import { async, signup, request, post, react, uploadFile, startServer, shutdownServer } from './utils.js'; +import { async, signup, request, post, react, uploadFile, startServer, shutdownServer } from './utils.mjs'; describe('API', function() { this.timeout(20*60*1000); - let p: childProcess.ChildProcess; - let alice: any; - let bob: any; - let carol: any; + let p; + let alice, bob, carol; before(async () => { p = await startServer(); diff --git a/packages/backend/test/block.ts b/packages/backend/test/block.mjs similarity index 86% rename from packages/backend/test/block.ts rename to packages/backend/test/block.mjs index b01096e80..ed5cf2170 100644 --- a/packages/backend/test/block.ts +++ b/packages/backend/test/block.mjs @@ -2,17 +2,15 @@ process.env.NODE_ENV = 'test'; import * as assert from 'assert'; import * as childProcess from 'child_process'; -import { async, signup, request, post, startServer, shutdownServer } from './utils.js'; +import { async, signup, request, post, startServer, shutdownServer } from './utils.mjs'; describe('Block', function() { this.timeout(20*60*1000); - let p: childProcess.ChildProcess; + let p; // alice blocks bob - let alice: any; - let bob: any; - let carol: any; + let alice, bob, carol; before(async () => { p = await startServer(); @@ -80,8 +78,8 @@ describe('Block', function() { assert.strictEqual(res.status, 200); assert.strictEqual(Array.isArray(res.body), true); - assert.strictEqual(res.body.some((note: any) => note.id === aliceNote.id), false); - assert.strictEqual(res.body.some((note: any) => note.id === bobNote.id), true); - assert.strictEqual(res.body.some((note: any) => note.id === carolNote.id), true); + assert.strictEqual(res.body.some((note) => note.id === aliceNote.id), false); + assert.strictEqual(res.body.some((note) => note.id === bobNote.id), true); + assert.strictEqual(res.body.some((note) => note.id === carolNote.id), true); })); }); diff --git a/packages/backend/test/chart.ts b/packages/backend/test/chart.mjs similarity index 95% rename from packages/backend/test/chart.ts rename to packages/backend/test/chart.mjs index ac0844679..70874df16 100644 --- a/packages/backend/test/chart.ts +++ b/packages/backend/test/chart.mjs @@ -2,18 +2,14 @@ process.env.NODE_ENV = 'test'; import * as assert from 'assert'; import * as lolex from '@sinonjs/fake-timers'; -import TestChart from '../src/services/chart/charts/test.js'; -import TestGroupedChart from '../src/services/chart/charts/test-grouped.js'; -import TestUniqueChart from '../src/services/chart/charts/test-unique.js'; -import TestIntersectionChart from '../src/services/chart/charts/test-intersection.js'; -import { initDb } from '../src/db/postgre.js'; +import TestChart from '../built/services/chart/charts/test.js'; +import TestGroupedChart from '../built/services/chart/charts/test-grouped.js'; +import TestUniqueChart from '../built/services/chart/charts/test-unique.js'; +import TestIntersectionChart from '../built/services/chart/charts/test-intersection.js'; +import { initDb } from '../built/db/postgre.js'; describe('Chart', () => { - let testChart: TestChart; - let testGroupedChart: TestGroupedChart; - let testUniqueChart: TestUniqueChart; - let testIntersectionChart: TestIntersectionChart; - let clock: lolex.InstalledClock; + let testChart, testGroupedChart, testUniqueChart, testIntersectionChart, clock; beforeEach(async () => { await initDb(true); diff --git a/packages/backend/test/docker-compose.yml b/packages/backend/test/docker-compose.yml deleted file mode 100644 index 5f95bec4c..000000000 --- a/packages/backend/test/docker-compose.yml +++ /dev/null @@ -1,15 +0,0 @@ -version: "3" - -services: - redistest: - image: redis:6 - ports: - - "127.0.0.1:56312:6379" - - dbtest: - image: postgres:13 - ports: - - "127.0.0.1:54312:5432" - environment: - POSTGRES_DB: "test-misskey" - POSTGRES_HOST_AUTH_METHOD: trust diff --git a/packages/backend/test/endpoints.ts b/packages/backend/test/endpoints.mjs similarity index 99% rename from packages/backend/test/endpoints.ts rename to packages/backend/test/endpoints.mjs index 2aedc25f2..40bb91ed7 100644 --- a/packages/backend/test/endpoints.ts +++ b/packages/backend/test/endpoints.mjs @@ -3,13 +3,12 @@ process.env.NODE_ENV = 'test'; import * as assert from 'assert'; import * as childProcess from 'child_process'; -import { async, signup, request, post, react, uploadFile, startServer, shutdownServer } from './utils.js'; +import { async, signup, request, post, react, uploadFile, startServer, shutdownServer } from './utils.mjs'; describe('API: Endpoints', () => { - let p: childProcess.ChildProcess; - let alice: any; - let bob: any; - let carol: any; + let p; + + let alice, bob, carol; before(async () => { p = await startServer(); diff --git a/packages/backend/test/extract-mentions.ts b/packages/backend/test/extract-mentions.mjs similarity index 81% rename from packages/backend/test/extract-mentions.ts rename to packages/backend/test/extract-mentions.mjs index 85afb098d..2512ac868 100644 --- a/packages/backend/test/extract-mentions.ts +++ b/packages/backend/test/extract-mentions.mjs @@ -1,11 +1,11 @@ import * as assert from 'assert'; import { parse } from 'mfm-js'; -import { extractMentions } from '../src/misc/extract-mentions.js'; +import { extractMentions } from '../built/misc/extract-mentions.js'; describe('Extract mentions', () => { it('simple', () => { - const ast = parse('@foo @bar @baz')!; + const ast = parse('@foo @bar @baz'); const mentions = extractMentions(ast); assert.deepStrictEqual(mentions, [{ username: 'foo', @@ -23,7 +23,7 @@ describe('Extract mentions', () => { }); it('nested', () => { - const ast = parse('@foo **@bar** @baz')!; + const ast = parse('@foo **@bar** @baz'); const mentions = extractMentions(ast); assert.deepStrictEqual(mentions, [{ username: 'foo', diff --git a/packages/backend/test/fetch-resource.ts b/packages/backend/test/fetch-resource.mjs similarity index 98% rename from packages/backend/test/fetch-resource.ts rename to packages/backend/test/fetch-resource.mjs index ba1bf54a9..ad135bcec 100644 --- a/packages/backend/test/fetch-resource.ts +++ b/packages/backend/test/fetch-resource.mjs @@ -3,7 +3,7 @@ process.env.NODE_ENV = 'test'; import * as assert from 'assert'; import * as childProcess from 'child_process'; import * as openapi from '@redocly/openapi-core'; -import { async, startServer, signup, post, request, simpleGet, port, shutdownServer } from './utils.js'; +import { async, startServer, signup, post, request, simpleGet, port, shutdownServer } from './utils.mjs'; // Request Accept const ONLY_AP = 'application/activity+json'; @@ -19,10 +19,9 @@ const HTML = 'text/html; charset=utf-8'; describe('Fetch resource', function() { this.timeout(20*60*1000); - let p: childProcess.ChildProcess; + let p; - let alice: any; - let alicesPost: any; + let alice, alicesPost; before(async () => { p = await startServer(); diff --git a/packages/backend/test/ff-visibility.ts b/packages/backend/test/ff-visibility.mjs similarity index 96% rename from packages/backend/test/ff-visibility.ts rename to packages/backend/test/ff-visibility.mjs index d71464a39..96126b072 100644 --- a/packages/backend/test/ff-visibility.ts +++ b/packages/backend/test/ff-visibility.mjs @@ -2,16 +2,14 @@ process.env.NODE_ENV = 'test'; import * as assert from 'assert'; import * as childProcess from 'child_process'; -import { async, signup, request, post, react, connectStream, startServer, shutdownServer, simpleGet } from './utils.js'; +import { async, signup, request, post, react, connectStream, startServer, shutdownServer, simpleGet } from './utils.mjs'; describe('FF visibility', function() { this.timeout(20*60*1000); - let p: childProcess.ChildProcess; + let p; - let alice: any; - let bob: any; - let follower: any; + let alice, bob, follower; before(async () => { p = await startServer(); diff --git a/packages/backend/test/get-file-info.ts b/packages/backend/test/get-file-info.mjs similarity index 87% rename from packages/backend/test/get-file-info.ts rename to packages/backend/test/get-file-info.mjs index 7ce98db50..8aa6dd6f0 100644 --- a/packages/backend/test/get-file-info.ts +++ b/packages/backend/test/get-file-info.mjs @@ -1,8 +1,8 @@ import * as assert from 'assert'; import { fileURLToPath } from 'node:url'; import { dirname } from 'node:path'; -import { getFileInfo } from '../src/misc/get-file-info.js'; -import { async } from './utils.js'; +import { getFileInfo } from '../built/misc/get-file-info.js'; +import { async } from './utils.mjs'; const _filename = fileURLToPath(import.meta.url); const _dirname = dirname(_filename); @@ -10,7 +10,7 @@ const _dirname = dirname(_filename); describe('Get file info', () => { it('Empty file', async (async () => { const path = `${_dirname}/resources/emptyfile`; - const info = await getFileInfo(path) as any; + const info = await getFileInfo(path); delete info.warnings; delete info.blurhash; assert.deepStrictEqual(info, { @@ -28,7 +28,7 @@ describe('Get file info', () => { it('Generic JPEG', async (async () => { const path = `${_dirname}/resources/Lenna.jpg`; - const info = await getFileInfo(path) as any; + const info = await getFileInfo(path); delete info.warnings; delete info.blurhash; assert.deepStrictEqual(info, { @@ -46,7 +46,7 @@ describe('Get file info', () => { it('Generic APNG', async (async () => { const path = `${_dirname}/resources/anime.png`; - const info = await getFileInfo(path) as any; + const info = await getFileInfo(path); delete info.warnings; delete info.blurhash; assert.deepStrictEqual(info, { @@ -64,7 +64,7 @@ describe('Get file info', () => { it('Generic AGIF', async (async () => { const path = `${_dirname}/resources/anime.gif`; - const info = await getFileInfo(path) as any; + const info = await getFileInfo(path); delete info.warnings; delete info.blurhash; assert.deepStrictEqual(info, { @@ -82,7 +82,7 @@ describe('Get file info', () => { it('PNG with alpha', async (async () => { const path = `${_dirname}/resources/with-alpha.png`; - const info = await getFileInfo(path) as any; + const info = await getFileInfo(path); delete info.warnings; delete info.blurhash; assert.deepStrictEqual(info, { @@ -100,7 +100,7 @@ describe('Get file info', () => { it('Generic SVG', async (async () => { const path = `${_dirname}/resources/image.svg`; - const info = await getFileInfo(path) as any; + const info = await getFileInfo(path); delete info.warnings; delete info.blurhash; assert.deepStrictEqual(info, { @@ -119,7 +119,7 @@ describe('Get file info', () => { it('SVG with XML definition', async (async () => { // https://github.com/misskey-dev/misskey/issues/4413 const path = `${_dirname}/resources/with-xml-def.svg`; - const info = await getFileInfo(path) as any; + const info = await getFileInfo(path); delete info.warnings; delete info.blurhash; assert.deepStrictEqual(info, { @@ -137,7 +137,7 @@ describe('Get file info', () => { it('Dimension limit', async (async () => { const path = `${_dirname}/resources/25000x25000.png`; - const info = await getFileInfo(path) as any; + const info = await getFileInfo(path); delete info.warnings; delete info.blurhash; assert.deepStrictEqual(info, { @@ -155,7 +155,7 @@ describe('Get file info', () => { it('Rotate JPEG', async (async () => { const path = `${_dirname}/resources/rotate.jpg`; - const info = await getFileInfo(path) as any; + const info = await getFileInfo(path); delete info.warnings; delete info.blurhash; assert.deepStrictEqual(info, { diff --git a/packages/backend/test/loader.js b/packages/backend/test/loader.js deleted file mode 100644 index 6b21587e3..000000000 --- a/packages/backend/test/loader.js +++ /dev/null @@ -1,34 +0,0 @@ -/** - * ts-node/esmローダーに投げる前にpath mappingを解決する - * 参考 - * - https://github.com/TypeStrong/ts-node/discussions/1450#discussioncomment-1806115 - * - https://nodejs.org/api/esm.html#loaders - * ※ https://github.com/TypeStrong/ts-node/pull/1585 が取り込まれたらこのカスタムローダーは必要なくなる - */ - -import { resolve as resolveTs, load } from 'ts-node/esm'; -import { loadConfig, createMatchPath } from 'tsconfig-paths'; -import { pathToFileURL } from 'url'; - -const tsconfig = loadConfig(); -const matchPath = createMatchPath(tsconfig.absoluteBaseUrl, tsconfig.paths); - -export function resolve(specifier, ctx, defaultResolve) { - let resolvedSpecifier; - if (specifier.endsWith('.js')) { - // maybe transpiled - const specifierWithoutExtension = specifier.substring(0, specifier.length - '.js'.length); - const matchedSpecifier = matchPath(specifierWithoutExtension); - if (matchedSpecifier) { - resolvedSpecifier = pathToFileURL(`${matchedSpecifier}.js`).href; - } - } else { - const matchedSpecifier = matchPath(specifier); - if (matchedSpecifier) { - resolvedSpecifier = pathToFileURL(matchedSpecifier).href; - } - } - return resolveTs(resolvedSpecifier ?? specifier, ctx, defaultResolve); -} - -export { load }; diff --git a/packages/backend/test/mfm.ts b/packages/backend/test/mfm.mjs similarity index 96% rename from packages/backend/test/mfm.ts rename to packages/backend/test/mfm.mjs index 5b9e47414..8ccf30911 100644 --- a/packages/backend/test/mfm.ts +++ b/packages/backend/test/mfm.mjs @@ -1,7 +1,7 @@ import * as assert from 'assert'; -import { toHtml } from '../src/mfm/to-html.js'; -import { fromHtml } from '../src/mfm/from-html.js'; +import { toHtml } from '../built/mfm/to-html.js'; +import { fromHtml } from '../built/mfm/from-html.js'; describe('toHtml', () => { it('br', async () => { diff --git a/packages/backend/test/misc/mock-resolver.ts b/packages/backend/test/misc/mock-resolver.mjs similarity index 50% rename from packages/backend/test/misc/mock-resolver.ts rename to packages/backend/test/misc/mock-resolver.mjs index 75b80e98c..d74bc36a7 100644 --- a/packages/backend/test/misc/mock-resolver.ts +++ b/packages/backend/test/misc/mock-resolver.mjs @@ -1,21 +1,16 @@ -import { Resolver } from '../../src/remote/activitypub/resolver.js'; -import { IObject } from '../../src/remote/activitypub/type.js'; - -type MockResponse = { - type: string; - content: string; -}; +import { Resolver } from '../../built/remote/activitypub/resolver.js'; export class MockResolver extends Resolver { - private _rs = new Map(); - public async _register(uri: string, content: string | Record, type = 'application/activity+json') { + _rs = new Map(); + + async _register(uri, content, type = 'application/activity+json') { this._rs.set(uri, { type, content: typeof content === 'string' ? content : JSON.stringify(content), }); } - public async resolve(value: string | IObject): Promise { + async resolve(value) { if (typeof value !== 'string') return value; const r = this._rs.get(value); diff --git a/packages/backend/test/mute.ts b/packages/backend/test/mute.mjs similarity index 78% rename from packages/backend/test/mute.ts rename to packages/backend/test/mute.mjs index 178018eea..539f7dc3a 100644 --- a/packages/backend/test/mute.ts +++ b/packages/backend/test/mute.mjs @@ -2,17 +2,15 @@ process.env.NODE_ENV = 'test'; import * as assert from 'assert'; import * as childProcess from 'child_process'; -import { async, signup, request, post, react, startServer, shutdownServer, waitFire } from './utils.js'; +import { async, signup, request, post, react, startServer, shutdownServer, waitFire } from './utils.mjs'; describe('Mute', function() { this.timeout(20*60*1000); - let p: childProcess.ChildProcess; + let p; // alice mutes carol - let alice: any; - let bob: any; - let carol: any; + let alice, bob, carol; before(async () => { p = await startServer(); @@ -41,8 +39,8 @@ describe('Mute', function() { assert.strictEqual(res.status, 200); assert.strictEqual(Array.isArray(res.body), true); - assert.strictEqual(res.body.some((note: any) => note.id === bobNote.id), true); - assert.strictEqual(res.body.some((note: any) => note.id === carolNote.id), false); + assert.strictEqual(res.body.some((note) => note.id === bobNote.id), true); + assert.strictEqual(res.body.some((note) => note.id === carolNote.id), false); })); it('ミュートしているユーザーからメンションされても、hasUnreadMentions が true にならない', async(async () => { @@ -86,9 +84,9 @@ describe('Mute', function() { assert.strictEqual(res.status, 200); assert.strictEqual(Array.isArray(res.body), true); - assert.strictEqual(res.body.some((note: any) => note.id === aliceNote.id), true); - assert.strictEqual(res.body.some((note: any) => note.id === bobNote.id), true); - assert.strictEqual(res.body.some((note: any) => note.id === carolNote.id), false); + assert.strictEqual(res.body.some((note) => note.id === aliceNote.id), true); + assert.strictEqual(res.body.some((note) => note.id === bobNote.id), true); + assert.strictEqual(res.body.some((note) => note.id === carolNote.id), false); })); it('タイムラインにミュートしているユーザーの投稿のRenoteが含まれない', async(async () => { @@ -102,9 +100,9 @@ describe('Mute', function() { assert.strictEqual(res.status, 200); assert.strictEqual(Array.isArray(res.body), true); - assert.strictEqual(res.body.some((note: any) => note.id === aliceNote.id), true); - assert.strictEqual(res.body.some((note: any) => note.id === bobNote.id), false); - assert.strictEqual(res.body.some((note: any) => note.id === carolNote.id), false); + assert.strictEqual(res.body.some((note) => note.id === aliceNote.id), true); + assert.strictEqual(res.body.some((note) => note.id === bobNote.id), false); + assert.strictEqual(res.body.some((note) => note.id === carolNote.id), false); })); }); @@ -118,8 +116,8 @@ describe('Mute', function() { assert.strictEqual(res.status, 200); assert.strictEqual(Array.isArray(res.body), true); - assert.strictEqual(res.body.some((notification: any) => notification.userId === bob.id), true); - assert.strictEqual(res.body.some((notification: any) => notification.userId === carol.id), false); + assert.strictEqual(res.body.some((notification) => notification.userId === bob.id), true); + assert.strictEqual(res.body.some((notification) => notification.userId === carol.id), false); })); }); }); diff --git a/packages/backend/test/note.ts b/packages/backend/test/note.mjs similarity index 98% rename from packages/backend/test/note.ts rename to packages/backend/test/note.mjs index 0f10f5ff9..f9a66c465 100644 --- a/packages/backend/test/note.ts +++ b/packages/backend/test/note.mjs @@ -2,17 +2,16 @@ process.env.NODE_ENV = 'test'; import * as assert from 'assert'; import * as childProcess from 'child_process'; -import { Note } from '../src/models/entities/note.js'; -import { async, signup, request, post, uploadUrl, startServer, shutdownServer, initTestDb, api } from './utils.js'; +import { Note } from '../built/models/entities/note.js'; +import { async, signup, request, post, uploadUrl, startServer, shutdownServer, initTestDb, api } from './utils.mjs'; describe('Note', function() { this.timeout(20*60*1000); - let p: childProcess.ChildProcess; - let Notes: any; + let p; + let Notes; - let alice: any; - let bob: any; + let alice, bob; before(async () => { p = await startServer(); diff --git a/packages/backend/test/prelude/url.ts b/packages/backend/test/prelude/url.mjs similarity index 82% rename from packages/backend/test/prelude/url.ts rename to packages/backend/test/prelude/url.mjs index df102c8df..66879ce30 100644 --- a/packages/backend/test/prelude/url.ts +++ b/packages/backend/test/prelude/url.mjs @@ -1,5 +1,5 @@ import * as assert from 'assert'; -import { query } from '../../src/prelude/url.js'; +import { query } from '../../built/prelude/url.js'; describe('url', () => { it('query', () => { diff --git a/packages/backend/test/reaction-lib.ts b/packages/backend/test/reaction-lib.ts deleted file mode 100644 index 7c61dc76c..000000000 --- a/packages/backend/test/reaction-lib.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -import * as assert from 'assert'; - -import { toDbReaction } from '../src/misc/reaction-lib.js'; - -describe('toDbReaction', async () => { - it('既存の文字列リアクションはそのまま', async () => { - assert.strictEqual(await toDbReaction('like'), 'like'); - }); - - it('Unicodeプリンは寿司化不能とするため文字列化しない', async () => { - assert.strictEqual(await toDbReaction('🍮'), '🍮'); - }); - - it('プリン以外の既存のリアクションは文字列化する like', async () => { - assert.strictEqual(await toDbReaction('👍'), 'like'); - }); - - it('プリン以外の既存のリアクションは文字列化する love', async () => { - assert.strictEqual(await toDbReaction('❤️'), 'love'); - }); - - it('プリン以外の既存のリアクションは文字列化する love 異体字セレクタなし', async () => { - assert.strictEqual(await toDbReaction('❤'), 'love'); - }); - - it('プリン以外の既存のリアクションは文字列化する laugh', async () => { - assert.strictEqual(await toDbReaction('😆'), 'laugh'); - }); - - it('プリン以外の既存のリアクションは文字列化する hmm', async () => { - assert.strictEqual(await toDbReaction('🤔'), 'hmm'); - }); - - it('プリン以外の既存のリアクションは文字列化する surprise', async () => { - assert.strictEqual(await toDbReaction('😮'), 'surprise'); - }); - - it('プリン以外の既存のリアクションは文字列化する congrats', async () => { - assert.strictEqual(await toDbReaction('🎉'), 'congrats'); - }); - - it('プリン以外の既存のリアクションは文字列化する angry', async () => { - assert.strictEqual(await toDbReaction('💢'), 'angry'); - }); - - it('プリン以外の既存のリアクションは文字列化する confused', async () => { - assert.strictEqual(await toDbReaction('😥'), 'confused'); - }); - - it('プリン以外の既存のリアクションは文字列化する rip', async () => { - assert.strictEqual(await toDbReaction('😇'), 'rip'); - }); - - it('それ以外はUnicodeのまま', async () => { - assert.strictEqual(await toDbReaction('🍅'), '🍅'); - }); - - it('異体字セレクタ除去', async () => { - assert.strictEqual(await toDbReaction('㊗️'), '㊗'); - }); - - it('異体字セレクタ除去 必要なし', async () => { - assert.strictEqual(await toDbReaction('㊗'), '㊗'); - }); - - it('fallback - undefined', async () => { - assert.strictEqual(await toDbReaction(undefined), 'like'); - }); - - it('fallback - null', async () => { - assert.strictEqual(await toDbReaction(null), 'like'); - }); - - it('fallback - empty', async () => { - assert.strictEqual(await toDbReaction(''), 'like'); - }); - - it('fallback - unknown', async () => { - assert.strictEqual(await toDbReaction('unknown'), 'like'); - }); -}); -*/ diff --git a/packages/backend/test/services/blocking.ts b/packages/backend/test/services/blocking.mjs similarity index 67% rename from packages/backend/test/services/blocking.ts rename to packages/backend/test/services/blocking.mjs index 122e8126e..f0e39772b 100644 --- a/packages/backend/test/services/blocking.ts +++ b/packages/backend/test/services/blocking.mjs @@ -3,17 +3,15 @@ process.env.NODE_ENV = 'test'; import * as assert from 'assert'; import * as childProcess from 'child_process'; import * as sinon from 'sinon'; -import { async, signup, startServer, shutdownServer, initTestDb } from '../utils.js'; +import { async, signup, startServer, shutdownServer, initTestDb } from '../utils.mjs'; describe('Creating a block activity', function() { this.timeout(20*60*1000); - let p: childProcess.ChildProcess; + let p; // alice blocks bob - let alice: any; - let bob: any; - let carol: any; + let alice, bob, carol; before(async () => { await initTestDb(); @@ -34,10 +32,10 @@ describe('Creating a block activity', function() { }); it('Should federate blocks normally', async(async () => { - const createBlock = (await import('../../src/services/blocking/create')).default; - const deleteBlock = (await import('../../src/services/blocking/delete')).default; + const createBlock = (await import('../../built/services/blocking/create')).default; + const deleteBlock = (await import('../../built/services/blocking/delete')).default; - const queues = await import('../../src/queue/index'); + const queues = await import('../../built/queue/index'); const spy = sinon.spy(queues, 'deliver'); await createBlock(alice, bob); assert(spy.calledOnce); @@ -46,12 +44,12 @@ describe('Creating a block activity', function() { })); it('Should not federate blocks if federateBlocks is false', async () => { - const createBlock = (await import('../../src/services/blocking/create')).default; - const deleteBlock = (await import('../../src/services/blocking/delete')).default; + const createBlock = (await import('../../built/services/blocking/create')).default; + const deleteBlock = (await import('../../built/services/blocking/delete')).default; alice.federateBlocks = true; - const queues = await import('../../src/queue/index'); + const queues = await import('../../built/queue/index'); const spy = sinon.spy(queues, 'deliver'); await createBlock(alice, carol); await deleteBlock(alice, carol); diff --git a/packages/backend/test/streaming.ts b/packages/backend/test/streaming.mjs similarity index 96% rename from packages/backend/test/streaming.ts rename to packages/backend/test/streaming.mjs index ad326703d..830dd91d7 100644 --- a/packages/backend/test/streaming.ts +++ b/packages/backend/test/streaming.mjs @@ -2,14 +2,14 @@ process.env.NODE_ENV = 'test'; import * as assert from 'assert'; import * as childProcess from 'child_process'; -import { Following } from '../src/models/entities/following.js'; -import { connectStream, signup, api, post, startServer, shutdownServer, initTestDb, waitFire } from './utils.js'; +import { Following } from '../built/models/entities/following.js'; +import { connectStream, signup, api, post, startServer, shutdownServer, initTestDb, waitFire } from './utils.mjs'; describe('Streaming', () => { - let p: childProcess.ChildProcess; - let Followings: any; + let p; + let Followings; - const follow = async (follower: any, followee: any) => { + const follow = async (follower, followee) => { await Followings.save({ id: 'a', createdAt: new Date(), @@ -28,16 +28,12 @@ describe('Streaming', () => { this.timeout(20*60*1000); // Local users - let ayano: any; - let kyoko: any; - let chitose: any; + let ayano, kyoko, chitose; // Remote users - let akari: any; - let chinatsu: any; + let akari, chinatsu; - let kyokoNote: any; - let list: any; + let kyokoNote, list; before(async () => { p = await startServer(); @@ -388,7 +384,7 @@ describe('Streaming', () => { }); describe('Hashtag Timeline', () => { - it('指定したハッシュタグの投稿が流れる', () => new Promise(async done => { + it('指定したハッシュタグの投稿が流れる', () => new Promise(async done => { const ws = await connectStream(chitose, 'hashtag', ({ type, body }) => { if (type == 'note') { assert.deepStrictEqual(body.text, '#foo'); @@ -406,7 +402,7 @@ describe('Streaming', () => { }); })); - it('指定したハッシュタグの投稿が流れる (AND)', () => new Promise(async done => { + it('指定したハッシュタグの投稿が流れる (AND)', () => new Promise(async done => { let fooCount = 0; let barCount = 0; let fooBarCount = 0; @@ -444,7 +440,7 @@ describe('Streaming', () => { }, 3000); })); - it('指定したハッシュタグの投稿が流れる (OR)', () => new Promise(async done => { + it('指定したハッシュタグの投稿が流れる (OR)', () => new Promise(async done => { let fooCount = 0; let barCount = 0; let fooBarCount = 0; @@ -490,7 +486,7 @@ describe('Streaming', () => { }, 3000); })); - it('指定したハッシュタグの投稿が流れる (AND + OR)', () => new Promise(async done => { + it('指定したハッシュタグの投稿が流れる (AND + OR)', () => new Promise(async done => { let fooCount = 0; let barCount = 0; let fooBarCount = 0; diff --git a/packages/backend/test/thread-mute.ts b/packages/backend/test/thread-mute.mjs similarity index 84% rename from packages/backend/test/thread-mute.ts rename to packages/backend/test/thread-mute.mjs index d4ca80af6..aa2b4679d 100644 --- a/packages/backend/test/thread-mute.ts +++ b/packages/backend/test/thread-mute.mjs @@ -2,16 +2,14 @@ process.env.NODE_ENV = 'test'; import * as assert from 'assert'; import * as childProcess from 'child_process'; -import { async, signup, request, post, react, connectStream, startServer, shutdownServer } from './utils.js'; +import { async, signup, request, post, react, connectStream, startServer, shutdownServer } from './utils.mjs'; describe('Note thread mute', function() { this.timeout(20*60*1000); - let p: childProcess.ChildProcess; + let p; - let alice: any; - let bob: any; - let carol: any; + let alice, bob, carol; before(async () => { p = await startServer(); @@ -37,9 +35,9 @@ describe('Note thread mute', function() { assert.strictEqual(res.status, 200); assert.strictEqual(Array.isArray(res.body), true); - assert.strictEqual(res.body.some((note: any) => note.id === bobNote.id), false); - assert.strictEqual(res.body.some((note: any) => note.id === carolReply.id), false); - assert.strictEqual(res.body.some((note: any) => note.id === carolReplyWithoutMention.id), false); + assert.strictEqual(res.body.some((note) => note.id === bobNote.id), false); + assert.strictEqual(res.body.some((note) => note.id === carolReply.id), false); + assert.strictEqual(res.body.some((note) => note.id === carolReplyWithoutMention.id), false); })); it('ミュートしているスレッドからメンションされても、hasUnreadMentions が true にならない', async(async () => { @@ -97,8 +95,8 @@ describe('Note thread mute', function() { assert.strictEqual(res.status, 200); assert.strictEqual(Array.isArray(res.body), true); - assert.strictEqual(res.body.some((notification: any) => notification.note.id === carolReply.id), false); - assert.strictEqual(res.body.some((notification: any) => notification.note.id === carolReplyWithoutMention.id), false); + assert.strictEqual(res.body.some((notification) => notification.note.id === carolReply.id), false); + assert.strictEqual(res.body.some((notification) => notification.note.id === carolReplyWithoutMention.id), false); // NOTE: bobの投稿はスレッドミュート前に行われたため通知に含まれていてもよい })); diff --git a/packages/backend/test/tsconfig.json b/packages/backend/test/tsconfig.json deleted file mode 100644 index 3f9020d46..000000000 --- a/packages/backend/test/tsconfig.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "compilerOptions": { - "allowJs": true, - "noEmitOnError": false, - "noImplicitAny": true, - "noImplicitReturns": true, - "noUnusedParameters": false, - "noUnusedLocals": true, - "noFallthroughCasesInSwitch": true, - "declaration": false, - "sourceMap": true, - "target": "es2017", - "module": "es2020", - "moduleResolution": "node", - "allowSyntheticDefaultImports": true, - "removeComments": false, - "noLib": false, - "strict": true, - "strictNullChecks": true, - "strictPropertyInitialization": false, - "experimentalDecorators": true, - "emitDecoratorMetadata": true, - "resolveJsonModule": true, - "isolatedModules": true, - "baseUrl": "./", - "paths": { - "@/*": ["../src/*"] - }, - "typeRoots": [ - "../node_modules/@types", - "../src/@types" - ], - "lib": [ - "esnext" - ] - }, - "compileOnSave": false, - "include": [ - "./**/*.ts" - ] -} diff --git a/packages/backend/test/user-notes.ts b/packages/backend/test/user-notes.mjs similarity index 73% rename from packages/backend/test/user-notes.ts rename to packages/backend/test/user-notes.mjs index 9d11d2304..4a0e87c27 100644 --- a/packages/backend/test/user-notes.ts +++ b/packages/backend/test/user-notes.mjs @@ -2,17 +2,14 @@ process.env.NODE_ENV = 'test'; import * as assert from 'assert'; import * as childProcess from 'child_process'; -import { async, signup, request, post, uploadUrl, startServer, shutdownServer } from './utils.js'; +import { async, signup, request, post, uploadUrl, startServer, shutdownServer } from './utils.mjs'; describe('users/notes', function() { this.timeout(20*60*1000); - let p: childProcess.ChildProcess; + let p; - let alice: any; - let jpgNote: any; - let pngNote: any; - let jpgPngNote: any; + let alice, jpgNote, pngNote, jpgPngNote; before(async () => { p = await startServer(); @@ -43,8 +40,8 @@ describe('users/notes', function() { assert.strictEqual(res.status, 200); assert.strictEqual(Array.isArray(res.body), true); assert.strictEqual(res.body.length, 2); - assert.strictEqual(res.body.some((note: any) => note.id === jpgNote.id), true); - assert.strictEqual(res.body.some((note: any) => note.id === jpgPngNote.id), true); + assert.strictEqual(res.body.some((note) => note.id === jpgNote.id), true); + assert.strictEqual(res.body.some((note) => note.id === jpgPngNote.id), true); })); it('ファイルタイプ指定 (jpg or png)', async(async () => { @@ -56,8 +53,8 @@ describe('users/notes', function() { assert.strictEqual(res.status, 200); assert.strictEqual(Array.isArray(res.body), true); assert.strictEqual(res.body.length, 3); - assert.strictEqual(res.body.some((note: any) => note.id === jpgNote.id), true); - assert.strictEqual(res.body.some((note: any) => note.id === pngNote.id), true); - assert.strictEqual(res.body.some((note: any) => note.id === jpgPngNote.id), true); + assert.strictEqual(res.body.some((note) => note.id === jpgNote.id), true); + assert.strictEqual(res.body.some((note) => note.id === pngNote.id), true); + assert.strictEqual(res.body.some((note) => note.id === jpgPngNote.id), true); })); }); diff --git a/packages/backend/test/utils.ts b/packages/backend/test/utils.mjs similarity index 74% rename from packages/backend/test/utils.ts rename to packages/backend/test/utils.mjs index 64a3b8b8b..e0af3ac46 100644 --- a/packages/backend/test/utils.ts +++ b/packages/backend/test/utils.mjs @@ -10,8 +10,8 @@ import * as foundkey from 'foundkey-js'; import fetch from 'node-fetch'; import FormData from 'form-data'; import { DataSource } from 'typeorm'; -import { loadConfig } from '../src/config/load.js'; -import { entities } from '../src/db/postgre.js'; +import { loadConfig } from '../built/config/load.js'; +import { entities } from '../built/db/postgre.js'; import got from 'got'; const _filename = fileURLToPath(import.meta.url); @@ -20,20 +20,20 @@ const _dirname = dirname(_filename); const config = loadConfig(); export const port = config.port; -export const async = (fn: Function) => (done: Function) => { +export const async = (fn) => (done) => { fn().then(() => { done(); - }, (err: Error) => { + }, (err) => { done(err); }); }; -export const api = async (endpoint: string, params: any, me?: any) => { +export const api = async (endpoint, params, me) => { endpoint = endpoint.replace(/^\//, ''); const auth = me ? { authorization: `Bearer ${me.token}` } : {}; - const res = await got(`http://localhost:${port}/api/${endpoint}`, { + const res = await got(`http://localhost:${port}/api/${endpoint}`, { method: 'POST', headers: { 'Content-Type': 'application/json', @@ -63,7 +63,7 @@ export const api = async (endpoint: string, params: any, me?: any) => { }; }; -export const request = async (endpoint: string, params: any, me?: any): Promise<{ body: any, status: number }> => { +export const request = async (endpoint, params, me) => { const auth = me ? { authorization: `Bearer ${me.token}` } : {}; const res = await fetch(`http://localhost:${port}/api${endpoint}`, { @@ -83,7 +83,7 @@ export const request = async (endpoint: string, params: any, me?: any): Promise< }; }; -export const signup = async (params?: any): Promise => { +export const signup = async (params) => { const q = Object.assign({ username: 'test', password: 'test', @@ -94,7 +94,7 @@ export const signup = async (params?: any): Promise => { return res.body; }; -export const post = async (user: any, params?: foundkey.Endpoints['notes/create']['req']): Promise => { +export const post = async (user, params) => { const q = Object.assign({ text: 'test', }, params); @@ -104,7 +104,7 @@ export const post = async (user: any, params?: foundkey.Endpoints['notes/create' return res.body ? res.body.createdNote : null; }; -export const react = async (user: any, note: any, reaction: string): Promise => { +export const react = async (user, note, reaction) => { await api('notes/reactions/create', { noteId: note.id, reaction: reaction, @@ -116,10 +116,10 @@ export const react = async (user: any, note: any, reaction: string): Promise => { +export const uploadFile = async (user, _path) => { const absPath = _path == null ? `${_dirname}/resources/Lenna.jpg` : path.isAbsolute(_path) ? _path : `${_dirname}/resources/${_path}`; - const formData = new FormData() as any; + const formData = new FormData(); formData.append('i', user.token); formData.append('file', fs.createReadStream(absPath)); formData.append('force', 'true'); @@ -137,8 +137,8 @@ export const uploadFile = async (user: any, _path?: string): Promise => { return body; }; -export const uploadUrl = async (user: any, url: string) => { - let file: any; +export const uploadUrl = async (user, url) => { + let file; const ws = await connectStream(user, 'main', (msg) => { if (msg.type === 'driveFileCreated') { @@ -157,7 +157,7 @@ export const uploadUrl = async (user: any, url: string) => { return file; }; -export function connectStream(user: any, channel: string, listener: (message: Record) => any, params?: any): Promise { +export function connectStream(user, channel, listener, params) { return new Promise((res, rej) => { const ws = new WebSocket(`ws://localhost:${port}/streaming?i=${user.token}`); @@ -184,11 +184,11 @@ export function connectStream(user: any, channel: string, listener: (message: Re }); } -export const waitFire = async (user: any, channel: string, trgr: () => any, cond: (msg: Record) => boolean, params?: any) => { - return new Promise(async (res, rej) => { - let timer: NodeJS.Timeout; +export const waitFire = async (user, channel, trgr, cond, params) => { + return new Promise(async (res, rej) => { + let timer; - let ws: WebSocket; + let ws; try { ws = await connectStream(user, channel, msg => { if (cond(msg)) { @@ -201,7 +201,7 @@ export const waitFire = async (user: any, channel: string, trgr: () => any, cond rej(e); } - if (!ws!) return; + if (!ws) return; timer = setTimeout(() => { ws.close(); @@ -218,7 +218,7 @@ export const waitFire = async (user: any, channel: string, trgr: () => any, cond }) }; -export const simpleGet = async (path: string, accept = '*/*'): Promise<{ status?: number, type?: string, location?: string }> => { +export const simpleGet = async (path, accept = '*/*') => { // node-fetchだと3xxを取れない return await new Promise((resolve, reject) => { const req = http.request(`http://localhost:${port}${path}`, { @@ -226,7 +226,7 @@ export const simpleGet = async (path: string, accept = '*/*'): Promise<{ status? Accept: accept, }, }, res => { - if (res.statusCode! >= 400) { + if (res.statusCode >= 400) { reject(res); } else { resolve({ @@ -241,8 +241,8 @@ export const simpleGet = async (path: string, accept = '*/*'): Promise<{ status? }); }; -export function launchServer(callbackSpawnedProcess: (p: childProcess.ChildProcess) => void, moreProcess: () => Promise = async () => {}) { - return (done: (err?: Error) => any) => { +export function launchServer(callbackSpawnedProcess, moreProcess = async () => {}) { + return (done) => { const p = childProcess.spawn('node', [_dirname + '/../index.js'], { stdio: ['inherit', 'inherit', 'inherit', 'ipc'], env: { NODE_ENV: 'test', PATH: process.env.PATH }, @@ -254,7 +254,7 @@ export function launchServer(callbackSpawnedProcess: (p: childProcess.ChildProce }; } -export async function initTestDb(justBorrow = false, initEntities?: any[]) { +export async function initTestDb(justBorrow = false, initEntities) { if (process.env.NODE_ENV !== 'test') throw 'NODE_ENV is not a test'; const db = new DataSource({ @@ -274,7 +274,7 @@ export async function initTestDb(justBorrow = false, initEntities?: any[]) { return db; } -export function startServer(timeout = 60 * 1000): Promise { +export function startServer(timeout = 60 * 1000) { return new Promise((res, rej) => { const t = setTimeout(() => { p.kill(SIGKILL); @@ -297,7 +297,7 @@ export function startServer(timeout = 60 * 1000): Promise { const t = setTimeout(() => { p.kill(SIGKILL); @@ -313,8 +313,8 @@ export function shutdownServer(p: childProcess.ChildProcess, timeout = 20 * 1000 }); } -export function sleep(msec: number) { - return new Promise(res => { +export function sleep(msec) { + return new Promise(res => { setTimeout(() => { res(); }, msec);