summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorrinsuki <428rinsuki+git@gmail.com>2020-01-09 14:35:04 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2020-01-09 14:35:04 +0900
commit3ecb0ab1612e0887193140b1a2f8a77872a6fac1 (patch)
treed8592afad5c26ca26a6d9975a78478aee4db1c29 /test
parent11.37.1 (diff)
downloadsharkey-3ecb0ab1612e0887193140b1a2f8a77872a6fac1.tar.gz
sharkey-3ecb0ab1612e0887193140b1a2f8a77872a6fac1.tar.bz2
sharkey-3ecb0ab1612e0887193140b1a2f8a77872a6fac1.zip
Add GitHub Actions (#5522)
* add .github/workflows/nodejs.yml * fix * GitHub Actions: Node.js 8.xはサポートしない * add .github/workflows/docker.yml * Dockerビルドをキャッシュするように * Run test in github actions * 同リポジトリ内からのプルリクだと無駄に二回走るのを抑制 * 6925c00のdocker.ymlへの適応忘れ * fix .circleci/misskey/test.yml * test実行時にDBとかredisとか動かすように * fix * fix tests (#5544) * fix test * fix compile errors * PATH引き継ぎでchild_process.spawn時のENOENTを修正 * サーバー起動処理を共通化 * fix coding style * fd=4をipcに使うように * fix port * fix * fix ws port * #4033 にテストケースを追従 * fix? * fix?? * fix * fix * fix * maybe fix * fix * node 10.xサポートしてなかった * 11.10じゃないとだめだった * fix * remove chart test * fix * chart test復活 * fix * 一回一回コネクションを閉じる * Revert "一回一回コネクションを閉じる" This reverts commit 56e35cf4f83070744c8dd852f1a7075011d88828. * 一回一回sync→dropしてるのをやめてみる * fix * fix * … * キャッシュを切ってみる * add ts to require target * omg fix * Revert "キャッシュを切ってみる" This reverts commit 88161c59d2ea769ddf87143ba4fd4660a06afdf2. * done呼び忘れ * 実際の文字数リミットと違ってたので対応 * テストケースがバグってたので修正 * Revert "一回一回sync→dropしてるのをやめてみる" This reverts commit a9e543ba2eef790ac7a14ae8799b898765748e35. * fix * fix * fix * fix? * fix * chartのconnectionを分離する * fix * fix * fix tsconfig? * Revert "fix tsconfig?" This reverts commit ba9269eaf65507ff97ec1dd2e27260fb2cf0510b. * fix * TS_NODE_FILES を scripts の方で指定 * Windowsェ * Circle CIの実行条件をmasterへのpushのみに Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
Diffstat (limited to 'test')
-rw-r--r--test/api-visibility.ts27
-rw-r--r--test/chart.ts42
-rw-r--r--test/extract-mentions.ts4
-rw-r--r--test/mute.ts42
-rw-r--r--test/note.ts29
-rw-r--r--test/streaming.ts25
-rw-r--r--test/user-notes.ts48
-rw-r--r--test/utils.ts20
8 files changed, 103 insertions, 134 deletions
diff --git a/test/api-visibility.ts b/test/api-visibility.ts
index 1e263bef5b..47b222b165 100644
--- a/test/api-visibility.ts
+++ b/test/api-visibility.ts
@@ -16,20 +16,12 @@ process.env.NODE_ENV = 'test';
import * as assert from 'assert';
import * as childProcess from 'child_process';
-import { async, signup, request, post } from './utils';
+import { async, signup, request, post, launchServer } from './utils';
describe('API visibility', () => {
let p: childProcess.ChildProcess;
- before(done => {
- p = childProcess.spawn('node', [__dirname + '/../index.js'], {
- stdio: ['inherit', 'inherit', 'ipc'],
- env: { NODE_ENV: 'test' }
- });
- p.on('message', message => {
- if (message === 'ok') done();
- });
- });
+ before(launchServer(g => p = g));
after(() => {
p.kill();
@@ -45,6 +37,8 @@ describe('API visibility', () => {
let other: any;
/** 非フォロワーでもリプライやメンションをされた人 */
let target: any;
+ /** specified mentionでmentionを飛ばされる人 */
+ let target2: any;
/** public-post */
let pub: any;
@@ -90,6 +84,7 @@ describe('API visibility', () => {
follower = await signup({ username: 'follower' });
other = await signup({ username: 'other' });
target = await signup({ username: 'target' });
+ target2 = await signup({ username: 'target2' });
// follow alice <= follower
await request('/following/create', { userId: alice.id }, follower);
@@ -111,7 +106,7 @@ describe('API visibility', () => {
pubM = await post(alice, { text: '@target x', replyId: tgt.id, visibility: 'public' });
homeM = await post(alice, { text: '@target x', replyId: tgt.id, visibility: 'home' });
folM = await post(alice, { text: '@target x', replyId: tgt.id, visibility: 'followers' });
- speM = await post(alice, { text: '@target x', replyId: tgt.id, visibility: 'specified' });
+ speM = await post(alice, { text: '@target2 x', replyId: tgt.id, visibility: 'specified' });
//#endregion
});
@@ -376,9 +371,9 @@ describe('API visibility', () => {
assert.strictEqual(res.body.text, '@target x');
}));
- it('[show] followers-mentionを非フォロワーがメンションされていても見れない', async(async () => {
+ it('[show] followers-mentionをメンションされていれば非フォロワーでも見れる', async(async () => {
const res = await show(folM.id, target);
- assert.strictEqual(res.body.isHidden, true);
+ assert.strictEqual(res.body.text, '@target x');
}));
it('[show] followers-mentionをフォロワーが見れる', async(async () => {
@@ -399,16 +394,16 @@ describe('API visibility', () => {
// specified
it('[show] specified-mentionを自分が見れる', async(async () => {
const res = await show(speM.id, alice);
- assert.strictEqual(res.body.text, '@target x');
+ assert.strictEqual(res.body.text, '@target2 x');
}));
it('[show] specified-mentionを指定ユーザーが見れる', async(async () => {
const res = await show(speM.id, target);
- assert.strictEqual(res.body.text, '@target x');
+ assert.strictEqual(res.body.text, '@target2 x');
}));
it('[show] specified-mentionをされた人が指定されてなかったら見れない', async(async () => {
- const res = await show(speM.id, target);
+ const res = await show(speM.id, target2);
assert.strictEqual(res.body.isHidden, true);
}));
diff --git a/test/chart.ts b/test/chart.ts
index 98c501f91f..4f626ed9a2 100644
--- a/test/chart.ts
+++ b/test/chart.ts
@@ -17,14 +17,18 @@ process.env.NODE_ENV = 'test';
import * as assert from 'assert';
import * as lolex from 'lolex';
import { async } from './utils';
-import { getConnection, createConnection } from 'typeorm';
-const config = require('../built/config').default;
-const Chart = require('../built/services/chart/core').default;
-const _TestChart = require('../built/services/chart/charts/schemas/test');
-const _TestGroupedChart = require('../built/services/chart/charts/schemas/test-grouped');
-const _TestUniqueChart = require('../built/services/chart/charts/schemas/test-unique');
+import TestChart from '../src/services/chart/charts/classes/test';
+import TestGroupedChart from '../src/services/chart/charts/classes/test-grouped';
+import TestUniqueChart from '../src/services/chart/charts/classes/test-unique';
+import * as _TestChart from '../src/services/chart/charts/schemas/test';
+import * as _TestGroupedChart from '../src/services/chart/charts/schemas/test-grouped';
+import * as _TestUniqueChart from '../src/services/chart/charts/schemas/test-unique';
+import { Connection, getConnection, createConnection } from 'typeorm';
+import config from '../src/config';
+import Chart from '../src/services/chart/core';
+import { initDb } from '../src/db/postgre';
-function initDb() {
+function initChartDb() {
try {
const conn = getConnection();
return Promise.resolve(conn);
@@ -51,37 +55,37 @@ describe('Chart', () => {
let testChart: any;
let testGroupedChart: any;
let testUniqueChart: any;
- let connection: any;
let clock: lolex.InstalledClock<lolex.Clock>;
+ let connection: Connection;
before(done => {
- initDb().then(c => {
+ initChartDb().then(c => {
connection = c;
done();
});
});
+ after(async(async () => {
+ await connection.close();
+ await initDb(true, undefined, undefined, true);
+ }));
+
beforeEach(done => {
- const TestChart = require('../built/services/chart/charts/classes/test').default;
testChart = new TestChart();
-
- const TestGroupedChart = require('../built/services/chart/charts/classes/test-grouped').default;
testGroupedChart = new TestGroupedChart();
-
- const TestUniqueChart = require('../built/services/chart/charts/classes/test-unique').default;
testUniqueChart = new TestUniqueChart();
clock = lolex.install({
now: new Date('2000-01-01 00:00:00')
});
-
- connection.synchronize().then(done);
+ done();
});
- afterEach(done => {
+ afterEach(async(async () => {
clock.uninstall();
- connection.dropDatabase().then(done);
- });
+ await connection.dropDatabase();
+ await connection.synchronize();
+ }));
it('Can updates', async(async () => {
await testChart.increment();
diff --git a/test/extract-mentions.ts b/test/extract-mentions.ts
index a70926cbb1..00f736ae1c 100644
--- a/test/extract-mentions.ts
+++ b/test/extract-mentions.ts
@@ -5,7 +5,7 @@ import { parse } from '../src/mfm/parse';
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',
@@ -26,7 +26,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/test/mute.ts b/test/mute.ts
index 07c77f7623..1b1a8d7a51 100644
--- a/test/mute.ts
+++ b/test/mute.ts
@@ -16,7 +16,7 @@ process.env.NODE_ENV = 'test';
import * as assert from 'assert';
import * as childProcess from 'child_process';
-import { async, signup, request, post, react, connectStream } from './utils';
+import { async, signup, request, post, react, connectStream, launchServer } from './utils';
describe('Mute', () => {
let p: childProcess.ChildProcess;
@@ -26,21 +26,11 @@ describe('Mute', () => {
let bob: any;
let carol: any;
- before(done => {
- p = childProcess.spawn('node', [__dirname + '/../index.js'], {
- stdio: ['inherit', 'inherit', 'ipc'],
- env: { NODE_ENV: 'test' }
- });
- p.on('message', async message => {
- if (message === 'ok') {
- (p.channel as any).onread = () => {};
- alice = await signup({ username: 'alice' });
- bob = await signup({ username: 'bob' });
- carol = await signup({ username: 'carol' });
- done();
- }
- });
- });
+ before(launchServer(g => p = g, async () => {
+ alice = await signup({ username: 'alice' });
+ bob = await signup({ username: 'bob' });
+ carol = await signup({ username: 'carol' });
+ }));
after(() => {
p.kill();
@@ -62,8 +52,8 @@ describe('Mute', () => {
assert.strictEqual(res.status, 200);
assert.strictEqual(Array.isArray(res.body), true);
- assert.strictEqual(res.body.some(note => note.id === bobNote.id), true);
- assert.strictEqual(res.body.some(note => note.id === carolNote.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), false);
}));
it('ミュートしているユーザーからメンションされても、hasUnreadMentions が true にならない', async(async () => {
@@ -131,9 +121,9 @@ describe('Mute', () => {
assert.strictEqual(res.status, 200);
assert.strictEqual(Array.isArray(res.body), true);
- 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);
+ 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);
}));
it('タイムラインにミュートしているユーザーの投稿のRenoteが含まれない', async(async () => {
@@ -147,9 +137,9 @@ describe('Mute', () => {
assert.strictEqual(res.status, 200);
assert.strictEqual(Array.isArray(res.body), true);
- 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);
+ 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);
}));
});
@@ -163,8 +153,8 @@ describe('Mute', () => {
assert.strictEqual(res.status, 200);
assert.strictEqual(Array.isArray(res.body), true);
- assert.strictEqual(res.body.some(notification => notification.userId === bob.id), true);
- assert.strictEqual(res.body.some(notification => notification.userId === carol.id), false);
+ assert.strictEqual(res.body.some((notification: any) => notification.userId === bob.id), true);
+ assert.strictEqual(res.body.some((notification: any) => notification.userId === carol.id), false);
}));
});
});
diff --git a/test/note.ts b/test/note.ts
index 4a4a777340..3aa12b5a61 100644
--- a/test/note.ts
+++ b/test/note.ts
@@ -16,9 +16,9 @@ process.env.NODE_ENV = 'test';
import * as assert from 'assert';
import * as childProcess from 'child_process';
-import { async, signup, request, post, uploadFile } from './utils';
-import { Note } from '../built/models/entities/note';
-const initDb = require('../built/db/postgre.js').initDb;
+import { async, signup, request, post, uploadFile, launchServer } from './utils';
+import { Note } from '../src/models/entities/note';
+import { initDb } from '../src/db/postgre';
describe('Note', () => {
let p: childProcess.ChildProcess;
@@ -27,23 +27,12 @@ describe('Note', () => {
let alice: any;
let bob: any;
- before(done => {
- p = childProcess.spawn('node', [__dirname + '/../index.js'], {
- stdio: ['inherit', 'inherit', 'ipc'],
- env: { NODE_ENV: 'test' }
- });
- p.on('message', message => {
- if (message === 'ok') {
- (p.channel as any).onread = () => {};
- initDb(true).then(async connection => {
- Notes = connection.getRepository(Note);
- alice = await signup({ username: 'alice' });
- bob = await signup({ username: 'bob' });
- done();
- });
- }
- });
- });
+ before(launchServer(g => p = g, async () => {
+ const connection = await initDb(true);
+ Notes = connection.getRepository(Note);
+ alice = await signup({ username: 'alice' });
+ bob = await signup({ username: 'bob' });
+ }));
after(() => {
p.kill();
diff --git a/test/streaming.ts b/test/streaming.ts
index 1eb1b7ff47..cb962cfb3d 100644
--- a/test/streaming.ts
+++ b/test/streaming.ts
@@ -16,29 +16,18 @@ process.env.NODE_ENV = 'test';
import * as assert from 'assert';
import * as childProcess from 'child_process';
-import { connectStream, signup, request, post } from './utils';
-import { Following } from '../built/models/entities/following';
-const initDb = require('../built/db/postgre.js').initDb;
+import { connectStream, signup, request, post, launchServer } from './utils';
+import { Following } from '../src/models/entities/following';
+import { initDb } from '../src/db/postgre';
describe('Streaming', () => {
let p: childProcess.ChildProcess;
let Followings: any;
- beforeEach(done => {
- p = childProcess.spawn('node', [__dirname + '/../index.js'], {
- stdio: ['inherit', 'inherit', 'ipc'],
- env: { NODE_ENV: 'test' }
- });
- p.on('message', message => {
- if (message === 'ok') {
- (p.channel as any).onread = () => {};
- initDb(true).then(async (connection: any) => {
- Followings = connection.getRepository(Following);
- done();
- });
- }
- });
- });
+ beforeEach(launchServer(g => p = g, async () => {
+ const connection = await initDb(true);
+ Followings = connection.getRepository(Following);
+ }));
afterEach(() => {
p.kill();
diff --git a/test/user-notes.ts b/test/user-notes.ts
index 63a97cd805..5094180202 100644
--- a/test/user-notes.ts
+++ b/test/user-notes.ts
@@ -16,7 +16,7 @@ process.env.NODE_ENV = 'test';
import * as assert from 'assert';
import * as childProcess from 'child_process';
-import { async, signup, request, post, uploadFile } from './utils';
+import { async, signup, request, post, uploadFile, launchServer } from './utils';
describe('users/notes', () => {
let p: childProcess.ChildProcess;
@@ -26,32 +26,20 @@ describe('users/notes', () => {
let pngNote: any;
let jpgPngNote: any;
- before(done => {
- p = childProcess.spawn('node', [__dirname + '/../index.js'], {
- stdio: ['inherit', 'inherit', 'ipc'],
- env: { NODE_ENV: 'test' }
+ before(launchServer(g => p = g, async () => {
+ alice = await signup({ username: 'alice' });
+ const jpg = await uploadFile(alice, __dirname + '/resources/Lenna.jpg');
+ const png = await uploadFile(alice, __dirname + '/resources/Lenna.png');
+ jpgNote = await post(alice, {
+ fileIds: [jpg.id]
});
- p.on('message', async message => {
- if (message === 'ok') {
- (p.channel as any).onread = () => {};
-
- alice = await signup({ username: 'alice' });
- const jpg = await uploadFile(alice, __dirname + '/resources/Lenna.jpg');
- const png = await uploadFile(alice, __dirname + '/resources/Lenna.png');
- jpgNote = await post(alice, {
- fileIds: [jpg.id]
- });
- pngNote = await post(alice, {
- fileIds: [png.id]
- });
- jpgPngNote = await post(alice, {
- fileIds: [jpg.id, png.id]
- });
-
- done();
- }
+ pngNote = await post(alice, {
+ fileIds: [png.id]
});
- });
+ jpgPngNote = await post(alice, {
+ fileIds: [jpg.id, png.id]
+ });
+ }));
after(() => {
p.kill();
@@ -66,8 +54,8 @@ describe('users/notes', () => {
assert.strictEqual(res.status, 200);
assert.strictEqual(Array.isArray(res.body), true);
assert.strictEqual(res.body.length, 2);
- assert.strictEqual(res.body.some(note => note.id === jpgNote.id), true);
- assert.strictEqual(res.body.some(note => note.id === jpgPngNote.id), true);
+ assert.strictEqual(res.body.some((note: any) => note.id === jpgNote.id), true);
+ assert.strictEqual(res.body.some((note: any) => note.id === jpgPngNote.id), true);
}));
it('ファイルタイプ指定 (jpg or png)', async(async () => {
@@ -79,8 +67,8 @@ describe('users/notes', () => {
assert.strictEqual(res.status, 200);
assert.strictEqual(Array.isArray(res.body), true);
assert.strictEqual(res.body.length, 3);
- 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);
+ 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);
}));
});
diff --git a/test/utils.ts b/test/utils.ts
index f67baf0048..af190254ec 100644
--- a/test/utils.ts
+++ b/test/utils.ts
@@ -2,6 +2,7 @@ import * as fs from 'fs';
import * as WebSocket from 'ws';
const fetch = require('node-fetch');
import * as req from 'request';
+import * as childProcess from 'child_process';
export const async = (fn: Function) => (done: Function) => {
fn().then(() => {
@@ -17,7 +18,7 @@ export const request = async (endpoint: string, params: any, me?: any): Promise<
} : {};
try {
- const res = await fetch('http://localhost:80/api' + endpoint, {
+ const res = await fetch('http://localhost:8080/api' + endpoint, {
method: 'POST',
body: JSON.stringify(Object.assign(auth, params))
});
@@ -65,7 +66,7 @@ export const react = async (user: any, note: any, reaction: string): Promise<any
export const uploadFile = (user: any, path?: string): Promise<any> => new Promise((ok, rej) => {
req.post({
- url: 'http://localhost:80/api/drive/files/create',
+ url: 'http://localhost:8080/api/drive/files/create',
formData: {
i: user.token,
file: fs.createReadStream(path || __dirname + '/resources/Lenna.png')
@@ -78,7 +79,7 @@ export const uploadFile = (user: any, path?: string): Promise<any> => new Promis
export function connectStream(user: any, channel: string, listener: (message: Record<string, any>) => any, params?: any): Promise<WebSocket> {
return new Promise((res, rej) => {
- const ws = new WebSocket(`ws://localhost/streaming?i=${user.token}`);
+ const ws = new WebSocket(`ws://localhost:8080/streaming?i=${user.token}`);
ws.on('open', () => {
ws.on('message', data => {
@@ -102,3 +103,16 @@ export function connectStream(user: any, channel: string, listener: (message: Re
});
});
}
+
+export function launchServer(callbackSpawnedProcess: (p: childProcess.ChildProcess) => void, moreProcess: () => Promise<void> = async () => {}) {
+ return (done: (err?: Error) => any) => {
+ const p = childProcess.spawn('node', [__dirname + '/../index.js'], {
+ stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
+ env: { NODE_ENV: 'test', PATH: process.env.PATH }
+ });
+ callbackSpawnedProcess(p);
+ p.on('message', message => {
+ if (message === 'ok') moreProcess().then(() => done()).catch(e => done(e));
+ });
+ };
+}