refactor: Use ESM (#8358)
* wip * wip * fix * clean up * Update tsconfig.json * Update activitypub.ts * wip
This commit is contained in:
@ -2,7 +2,7 @@ process.env.NODE_ENV = 'test';
|
||||
|
||||
import rndstr from 'rndstr';
|
||||
import * as assert from 'assert';
|
||||
import { initTestDb } from './utils';
|
||||
import { initTestDb } from './utils.js';
|
||||
|
||||
describe('ActivityPub', () => {
|
||||
before(async () => {
|
||||
@ -33,8 +33,8 @@ describe('ActivityPub', () => {
|
||||
};
|
||||
|
||||
it('Minimum Actor', async () => {
|
||||
const { MockResolver } = await import('./misc/mock-resolver');
|
||||
const { createPerson } = await import('../src/remote/activitypub/models/person');
|
||||
const { MockResolver } = await import('./misc/mock-resolver.js');
|
||||
const { createPerson } = await import('../src/remote/activitypub/models/person.js');
|
||||
|
||||
const resolver = new MockResolver();
|
||||
resolver._register(actor.id, actor);
|
||||
@ -47,8 +47,8 @@ describe('ActivityPub', () => {
|
||||
});
|
||||
|
||||
it('Minimum Note', async () => {
|
||||
const { MockResolver } = await import('./misc/mock-resolver');
|
||||
const { createNote } = await import('../src/remote/activitypub/models/note');
|
||||
const { MockResolver } = await import('./misc/mock-resolver.js');
|
||||
const { createNote } = await import('../src/remote/activitypub/models/note.js');
|
||||
|
||||
const resolver = new MockResolver();
|
||||
resolver._register(actor.id, actor);
|
||||
@ -80,8 +80,8 @@ describe('ActivityPub', () => {
|
||||
};
|
||||
|
||||
it('Actor', async () => {
|
||||
const { MockResolver } = await import('./misc/mock-resolver');
|
||||
const { createPerson } = await import('../src/remote/activitypub/models/person');
|
||||
const { MockResolver } = await import('./misc/mock-resolver.js');
|
||||
const { createPerson } = await import('../src/remote/activitypub/models/person.js');
|
||||
|
||||
const resolver = new MockResolver();
|
||||
resolver._register(actor.id, actor);
|
||||
|
@ -1,7 +1,7 @@
|
||||
import * as assert from 'assert';
|
||||
import { genRsaKeyPair } from '../src/misc/gen-key-pair';
|
||||
import { createSignedPost, createSignedGet } from '../src/remote/activitypub/ap-request';
|
||||
const httpSignature = require('http-signature');
|
||||
import { genRsaKeyPair } from '../src/misc/gen-key-pair.js';
|
||||
import { createSignedPost, createSignedGet } from '../src/remote/activitypub/ap-request.js';
|
||||
import httpSignature from 'http-signature';
|
||||
|
||||
export const buildParsedSignature = (signingString: string, signature: string, algorithm: string) => {
|
||||
return {
|
||||
|
@ -2,7 +2,7 @@ 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';
|
||||
import { async, signup, request, post, startServer, shutdownServer } from './utils.js';
|
||||
|
||||
describe('API visibility', () => {
|
||||
let p: childProcess.ChildProcess;
|
||||
|
@ -2,7 +2,7 @@ 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';
|
||||
import { async, signup, request, post, react, uploadFile, startServer, shutdownServer } from './utils.js';
|
||||
|
||||
describe('API', () => {
|
||||
let p: childProcess.ChildProcess;
|
||||
|
@ -2,7 +2,7 @@ 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';
|
||||
import { async, signup, request, post, startServer, shutdownServer } from './utils.js';
|
||||
|
||||
describe('Block', () => {
|
||||
let p: childProcess.ChildProcess;
|
||||
|
@ -2,15 +2,15 @@ process.env.NODE_ENV = 'test';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import * as lolex from '@sinonjs/fake-timers';
|
||||
import { async, initTestDb } from './utils';
|
||||
import TestChart from '../src/services/chart/charts/test';
|
||||
import TestGroupedChart from '../src/services/chart/charts/test-grouped';
|
||||
import TestUniqueChart from '../src/services/chart/charts/test-unique';
|
||||
import TestIntersectionChart from '../src/services/chart/charts/test-intersection';
|
||||
import * as _TestChart from '../src/services/chart/charts/entities/test';
|
||||
import * as _TestGroupedChart from '../src/services/chart/charts/entities/test-grouped';
|
||||
import * as _TestUniqueChart from '../src/services/chart/charts/entities/test-unique';
|
||||
import * as _TestIntersectionChart from '../src/services/chart/charts/entities/test-intersection';
|
||||
import { async, initTestDb } from './utils.js';
|
||||
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 * as _TestChart from '../src/services/chart/charts/entities/test.js';
|
||||
import * as _TestGroupedChart from '../src/services/chart/charts/entities/test-grouped.js';
|
||||
import * as _TestUniqueChart from '../src/services/chart/charts/entities/test-unique.js';
|
||||
import * as _TestIntersectionChart from '../src/services/chart/charts/entities/test-intersection.js';
|
||||
|
||||
describe('Chart', () => {
|
||||
let testChart: TestChart;
|
||||
|
@ -3,7 +3,7 @@ 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';
|
||||
import { async, signup, request, post, react, uploadFile, startServer, shutdownServer } from './utils.js';
|
||||
|
||||
describe('API: Endpoints', () => {
|
||||
let p: childProcess.ChildProcess;
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as assert from 'assert';
|
||||
|
||||
import { extractMentions } from '../src/misc/extract-mentions';
|
||||
import { extractMentions } from '../src/misc/extract-mentions.js';
|
||||
import { parse } from 'mfm-js';
|
||||
|
||||
describe('Extract mentions', () => {
|
||||
|
@ -2,7 +2,7 @@ process.env.NODE_ENV = 'test';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import * as childProcess from 'child_process';
|
||||
import { async, startServer, signup, post, request, simpleGet, port, shutdownServer } from './utils';
|
||||
import { async, startServer, signup, post, request, simpleGet, port, shutdownServer } from './utils.js';
|
||||
import * as openapi from '@redocly/openapi-core';
|
||||
|
||||
// Request Accept
|
||||
|
@ -2,7 +2,7 @@ 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';
|
||||
import { async, signup, request, post, react, connectStream, startServer, shutdownServer, simpleGet } from './utils.js';
|
||||
|
||||
describe('FF visibility', () => {
|
||||
let p: childProcess.ChildProcess;
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as assert from 'assert';
|
||||
import { async } from './utils';
|
||||
import { getFileInfo } from '../src/misc/get-file-info';
|
||||
import { async } from './utils.js';
|
||||
import { getFileInfo } from '../src/misc/get-file-info.js';
|
||||
|
||||
describe('Get file info', () => {
|
||||
it('Empty file', async (async () => {
|
||||
|
37
packages/backend/test/loader.js
Normal file
37
packages/backend/test/loader.js
Normal file
@ -0,0 +1,37 @@
|
||||
import path from 'path'
|
||||
import typescript from 'typescript'
|
||||
import { createMatchPath } from 'tsconfig-paths'
|
||||
import { resolve as BaseResolve, getFormat, transformSource } from 'ts-node/esm'
|
||||
|
||||
const { readConfigFile, parseJsonConfigFileContent, sys } = typescript
|
||||
|
||||
const __dirname = path.dirname(new URL(import.meta.url).pathname)
|
||||
|
||||
const configFile = readConfigFile('./test/tsconfig.json', sys.readFile)
|
||||
if (typeof configFile.error !== 'undefined') {
|
||||
throw new Error(`Failed to load tsconfig: ${configFile.error}`)
|
||||
}
|
||||
|
||||
const { options } = parseJsonConfigFileContent(
|
||||
configFile.config,
|
||||
{
|
||||
fileExists: sys.fileExists,
|
||||
readFile: sys.readFile,
|
||||
readDirectory: sys.readDirectory,
|
||||
useCaseSensitiveFileNames: true,
|
||||
},
|
||||
__dirname
|
||||
)
|
||||
|
||||
export { getFormat, transformSource } // こいつらはそのまま使ってほしいので re-export する
|
||||
|
||||
const matchPath = createMatchPath(options.baseUrl, options.paths)
|
||||
|
||||
export async function resolve(specifier, context, defaultResolve) {
|
||||
const matchedSpecifier = matchPath(specifier.replace('.js', '.ts'))
|
||||
return BaseResolve( // ts-node/esm の resolve に tsconfig-paths で解決したパスを渡す
|
||||
matchedSpecifier ? `${matchedSpecifier}.ts` : specifier,
|
||||
context,
|
||||
defaultResolve
|
||||
)
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
import * as assert from 'assert';
|
||||
import * as mfm from 'mfm-js';
|
||||
|
||||
import { toHtml } from '../src/mfm/to-html';
|
||||
import { fromHtml } from '../src/mfm/from-html';
|
||||
import { toHtml } from '../src/mfm/to-html.js';
|
||||
import { fromHtml } from '../src/mfm/from-html.js';
|
||||
|
||||
describe('toHtml', () => {
|
||||
it('br', () => {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import Resolver from '../../src/remote/activitypub/resolver';
|
||||
import { IObject } from '../../src/remote/activitypub/type';
|
||||
import Resolver from '../../src/remote/activitypub/resolver.js';
|
||||
import { IObject } from '../../src/remote/activitypub/type.js';
|
||||
|
||||
type MockResponse = {
|
||||
type: string;
|
||||
|
@ -2,7 +2,7 @@ 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';
|
||||
import { async, signup, request, post, react, connectStream, startServer, shutdownServer } from './utils.js';
|
||||
|
||||
describe('Mute', () => {
|
||||
let p: childProcess.ChildProcess;
|
||||
|
@ -2,8 +2,8 @@ process.env.NODE_ENV = 'test';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import * as childProcess from 'child_process';
|
||||
import { async, signup, request, post, uploadFile, startServer, shutdownServer, initTestDb } from './utils';
|
||||
import { Note } from '../src/models/entities/note';
|
||||
import { async, signup, request, post, uploadFile, startServer, shutdownServer, initTestDb } from './utils.js';
|
||||
import { Note } from '../src/models/entities/note.js';
|
||||
|
||||
describe('Note', () => {
|
||||
let p: childProcess.ChildProcess;
|
||||
|
@ -1,5 +1,5 @@
|
||||
import * as assert from 'assert';
|
||||
import { just, nothing } from '../../src/prelude/maybe';
|
||||
import { just, nothing } from '../../src/prelude/maybe.js';
|
||||
|
||||
describe('just', () => {
|
||||
it('has a value', () => {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import * as assert from 'assert';
|
||||
import { query } from '../../src/prelude/url';
|
||||
import { query } from '../../src/prelude/url.js';
|
||||
|
||||
describe('url', () => {
|
||||
it('query', () => {
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
import * as assert from 'assert';
|
||||
|
||||
import { toDbReaction } from '../src/misc/reaction-lib';
|
||||
import { toDbReaction } from '../src/misc/reaction-lib.js';
|
||||
|
||||
describe('toDbReaction', async () => {
|
||||
it('既存の文字列リアクションはそのまま', async () => {
|
||||
|
@ -2,8 +2,8 @@ process.env.NODE_ENV = 'test';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import * as childProcess from 'child_process';
|
||||
import { connectStream, signup, request, post, startServer, shutdownServer, initTestDb } from './utils';
|
||||
import { Following } from '../src/models/entities/following';
|
||||
import { connectStream, signup, request, post, startServer, shutdownServer, initTestDb } from './utils.js';
|
||||
import { Following } from '../src/models/entities/following.js';
|
||||
|
||||
describe('Streaming', () => {
|
||||
let p: childProcess.ChildProcess;
|
||||
|
@ -2,7 +2,7 @@ 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';
|
||||
import { async, signup, request, post, react, connectStream, startServer, shutdownServer } from './utils.js';
|
||||
|
||||
describe('Note thread mute', () => {
|
||||
let p: childProcess.ChildProcess;
|
||||
|
@ -10,7 +10,7 @@
|
||||
"declaration": false,
|
||||
"sourceMap": true,
|
||||
"target": "es2017",
|
||||
"module": "commonjs",
|
||||
"module": "es2020",
|
||||
"moduleResolution": "node",
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"removeComments": false,
|
||||
|
@ -2,7 +2,7 @@ process.env.NODE_ENV = 'test';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import * as childProcess from 'child_process';
|
||||
import { async, signup, request, post, uploadFile, startServer, shutdownServer } from './utils';
|
||||
import { async, signup, request, post, uploadFile, startServer, shutdownServer } from './utils.js';
|
||||
|
||||
describe('users/notes', () => {
|
||||
let p: childProcess.ChildProcess;
|
||||
|
@ -1,14 +1,14 @@
|
||||
import * as fs from 'fs';
|
||||
import * as fs from 'node:fs';
|
||||
import * as WebSocket from 'ws';
|
||||
import * as misskey from 'misskey-js';
|
||||
import fetch from 'node-fetch';
|
||||
const FormData = require('form-data');
|
||||
import FormData from 'form-data';
|
||||
import * as childProcess from 'child_process';
|
||||
import * as http from 'http';
|
||||
import loadConfig from '../src/config/load';
|
||||
import loadConfig from '../src/config/load.js';
|
||||
import { SIGKILL } from 'constants';
|
||||
import { createConnection, getConnection } from 'typeorm';
|
||||
import { entities } from '../src/db/postgre';
|
||||
import { entities } from '../src/db/postgre.js';
|
||||
|
||||
const config = loadConfig();
|
||||
export const port = config.port;
|
||||
|
Reference in New Issue
Block a user