Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
kakkokari-gtyih committed Nov 10, 2024
1 parent 64d9c2a commit ac1e0bc
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ will be ... ↓
```json
{
"title": "【アイドルマスター】「Stage Bye Stage」(歌:島村卯月、渋谷凛、本田未央)",
"icon": "https://www.youtube.com/s/desktop/28b0985e/img/favicon.ico",
"icon": "https://www.youtube.com/s/desktop/711fd789/img/logos/favicon.ico",
"description": "Website▶https://columbia.jp/idolmaster/Playlist▶https://www.youtube.com/playlist?list=PL83A2998CF3BBC86D2018年7月18日発売予定THE IDOLM@STER CINDERELLA GIRLS CG STAR...",
"thumbnail": "https://i.ytimg.com/vi/NMIEAhH_fTU/maxresdefault.jpg",
"player": {
Expand Down
3 changes: 3 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ export default {
// TODO: Use `--allowImportingTsExtensions` on TypeScript 5.0 so that we can
// directly import `.ts` files without this hack.
'^(\\.{1,2}/.*)\\.js$': '$1',

// Resolve @/foo/bar to `../../src/foo/bar`
'^@/(.*)\\.js$': '<rootDir>/src/$1',
},

// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
Expand Down
5 changes: 2 additions & 3 deletions src/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ export type GeneralScrapingOptions = {
contentLengthRequired?: boolean;
}

// eslint-disable-next-line import/no-default-export
export default async (_url: URL | string, opts?: GeneralScrapingOptions): Promise<Summary | null> => {
export async function parseGeneral(_url: URL | string, opts?: GeneralScrapingOptions): Promise<Summary | null> {
let lang = opts?.lang;
if (lang && !lang.match(/^[\w-]+(\s*,\s*[\w-]+)*$/)) lang = null;

Expand Down Expand Up @@ -279,4 +278,4 @@ export default async (_url: URL | string, opts?: GeneralScrapingOptions): Promis
sensitive,
activityPub,
};
};
}
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { got, type Agents as GotAgents } from 'got';
import type { FastifyInstance } from 'fastify';
import { SummalyResult } from '@/summary.js';
import { SummalyPlugin as _SummalyPlugin } from '@/iplugin.js';
import general, { GeneralScrapingOptions } from '@/general.js';
import { parseGeneral, type GeneralScrapingOptions } from '@/general.js';
import { DEFAULT_OPERATION_TIMEOUT, DEFAULT_RESPONSE_TIMEOUT, agent, setAgent } from '@/utils/got.js';
import { plugins as builtinPlugins } from '@/plugins/index.js';

Expand Down Expand Up @@ -125,7 +125,7 @@ export const summaly = async (url: string, options?: SummalyOptions): Promise<Su
};

// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
const summary = await (match ? match.summarize : general)(_url, scrapingOptions);
const summary = await (match ? match.summarize : parseGeneral)(_url, scrapingOptions);

if (summary == null) {
throw new Error('failed summarize');
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/branchio-deeplinks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import general, { GeneralScrapingOptions } from '@/general.js';
import { parseGeneral, type GeneralScrapingOptions } from '@/general.js';
import Summary from '@/summary.js';

export function test(url: URL): boolean {
Expand All @@ -12,5 +12,5 @@ export async function summarize(url: URL, opts?: GeneralScrapingOptions): Promis
// Web版に強制リダイレクトすることでbranch.ioの独自ページが開くのを防ぐ
url.searchParams.append('$web_only', 'true');

return await general(url, opts);
return await parseGeneral(url, opts);
}
8 changes: 4 additions & 4 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { fileURLToPath } from 'node:url';
import { Agent as httpAgent } from 'node:http';
import { Agent as httpsAgent } from 'node:https';
import { expect, test, describe, beforeEach, afterEach } from '@jest/globals';
import fastify from 'fastify';
import fastify, { type FastifyInstance } from 'fastify';
import { summaly } from '../src/index.js';
import { StatusError } from '../src/utils/status-error.js';

Expand All @@ -34,7 +34,7 @@ const host = `http://localhost:${port}`;
// Display detail of unhandled promise rejection
process.on('unhandledRejection', console.dir);

let app: ReturnType<typeof fastify> | null = null;
let app: FastifyInstance | null = null;

afterEach(async () => {
if (app) {
Expand Down Expand Up @@ -71,7 +71,7 @@ test('basic', async () => {
},
sitename: 'localhost:3060',
sensitive: false,
url: host,
url: host + '/',
activityPub: null,
});
});
Expand All @@ -83,7 +83,7 @@ test('Stage Bye Stage', async () => {
expect(summary).toEqual(
{
'title': '【アイドルマスター】「Stage Bye Stage」(歌:島村卯月、渋谷凛、本田未央)',
'icon': 'https://www.youtube.com/s/desktop/4feff1e2/img/favicon.ico',
'icon': 'https://www.youtube.com/s/desktop/711fd789/img/logos/favicon.ico',
'description': 'Website▶https://columbia.jp/idolmaster/Playlist▶https://www.youtube.com/playlist?list=PL83A2998CF3BBC86D2018年7月18日発売予定THE IDOLM@STER CINDERELLA GIRLS CG STAR...',
'thumbnail': 'https://i.ytimg.com/vi/NMIEAhH_fTU/maxresdefault.jpg',
'player': {
Expand Down
6 changes: 0 additions & 6 deletions test/tsconfig.json

This file was deleted.

7 changes: 5 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"emitDecoratorMetadata": true,
"resolveJsonModule": true,
"isolatedModules": true,
"rootDir": "./src",
"baseUrl": "./",
"paths": {
"@/*": [
Expand All @@ -44,6 +43,10 @@
},
"compileOnSave": false,
"include": [
"./src/**/*.ts"
"./src/**/*"
],
"exclude": [
"node_modules",
"test/**/*"
]
}

0 comments on commit ac1e0bc

Please sign in to comment.