Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix tests #5544

Merged
merged 53 commits into from
Nov 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
6f5656c
fix test
rinsuki Oct 24, 2019
8e526c2
fix compile errors
rinsuki Oct 24, 2019
6e16c93
PATH引き継ぎでchild_process.spawn時のENOENTを修正
rinsuki Oct 24, 2019
cc7cc56
サーバー起動処理を共通化
rinsuki Oct 24, 2019
9cc57cd
fix coding style
rinsuki Oct 24, 2019
8119e4a
fd=4をipcに使うように
rinsuki Oct 24, 2019
d87cf25
fix port
rinsuki Oct 24, 2019
34aac68
fix
rinsuki Oct 24, 2019
d92285b
fix ws port
rinsuki Oct 24, 2019
c203b9c
#4033 にテストケースを追従
rinsuki Oct 24, 2019
a02c087
fix?
rinsuki Oct 24, 2019
7df31a4
fix??
rinsuki Oct 24, 2019
9bc4d8b
fix
rinsuki Oct 24, 2019
36fb18a
fix
rinsuki Oct 24, 2019
d954030
fix
rinsuki Oct 24, 2019
a3dbaea
maybe fix
rinsuki Oct 24, 2019
fa6b770
fix
rinsuki Oct 24, 2019
282a3b1
node 10.xサポートしてなかった
rinsuki Oct 24, 2019
a0dbcae
11.10じゃないとだめだった
rinsuki Oct 24, 2019
dcb9c67
fix
rinsuki Oct 24, 2019
dc83af3
remove chart test
rinsuki Oct 24, 2019
54f92aa
fix
rinsuki Oct 24, 2019
7082d0a
chart test復活
rinsuki Oct 24, 2019
273e090
fix
rinsuki Oct 25, 2019
56e35cf
一回一回コネクションを閉じる
rinsuki Oct 25, 2019
40bf3c2
Revert "一回一回コネクションを閉じる"
rinsuki Oct 25, 2019
a9e543b
一回一回sync→dropしてるのをやめてみる
rinsuki Oct 25, 2019
be1f755
fix
rinsuki Oct 25, 2019
7f58bc7
fix
rinsuki Oct 25, 2019
bcbc9c1
rinsuki Oct 25, 2019
88161c5
キャッシュを切ってみる
rinsuki Oct 25, 2019
bfc687c
add ts to require target
rinsuki Oct 25, 2019
9089b37
omg fix
rinsuki Oct 25, 2019
49f9565
Revert "キャッシュを切ってみる"
rinsuki Oct 25, 2019
16171d6
done呼び忘れ
rinsuki Oct 25, 2019
7394de3
実際の文字数リミットと違ってたので対応
rinsuki Oct 25, 2019
e0d4353
テストケースがバグってたので修正
rinsuki Oct 25, 2019
89a267e
Revert "一回一回sync→dropしてるのをやめてみる"
rinsuki Oct 25, 2019
5dfead3
fix
rinsuki Oct 25, 2019
8b61c26
fix
rinsuki Oct 25, 2019
482273f
fix
rinsuki Oct 25, 2019
a7b021c
fix?
rinsuki Oct 25, 2019
5a89ec9
fix
rinsuki Oct 25, 2019
c49dfd4
chartのconnectionを分離する
rinsuki Oct 25, 2019
d7263be
fix
rinsuki Oct 25, 2019
d3d4dc9
fix
rinsuki Oct 25, 2019
ba9269e
fix tsconfig?
rinsuki Oct 25, 2019
5798750
Revert "fix tsconfig?"
rinsuki Oct 25, 2019
c419e88
fix
rinsuki Oct 25, 2019
37ff058
Merge branch 'develop' into fix/tests
rinsuki Oct 25, 2019
900a7aa
Merge branch 'add/github-actions' into fix/tests
rinsuki Oct 25, 2019
e14fe15
TS_NODE_FILES を scripts の方で指定
rinsuki Oct 31, 2019
3bbf2b6
Windowsェ
rinsuki Nov 9, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .circleci/misskey/default.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
url: 'http://misskey.local'
port: 80
mongodb:
port: 8080
db:
host: localhost
port: 27017
db: misskey
user: syuilo
port: 5432
db: test-misskey
user: postgres
pass: ''
redis:
host: localhost
port: 6379
pass: ''
id: aid
2 changes: 1 addition & 1 deletion .circleci/misskey/test.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
url: 'http://misskey.local'
port: 80
port: 8080
db:
host: localhost
port: 5432
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

strategy:
matrix:
node-version: [10.x, 12.x]
node-version: [11.10.x, 12.x]

services:
postgres:
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"clean": "gulp clean",
"cleanall": "gulp cleanall",
"lint": "gulp lint",
"test": "gulp test",
"test": "cross-env TS_NODE_FILES=true gulp test",
"format": "gulp format"
},
"resolutions": {
Expand Down Expand Up @@ -266,6 +266,7 @@
"xev": "2.0.1"
},
"devDependencies": {
"@types/fluent-ffmpeg": "2.1.10"
"@types/fluent-ffmpeg": "2.1.10",
"cross-env": "6.0.3"
}
}
12 changes: 7 additions & 5 deletions src/db/postgre.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,13 @@ export const entities = [
...charts as any
];

export function initDb(justBorrow = false, sync = false, log = false) {
try {
const conn = getConnection();
return Promise.resolve(conn);
} catch (e) {}
export function initDb(justBorrow = false, sync = false, log = false, forceRecreate = false) {
if (!forceRecreate) {
try {
const conn = getConnection();
return Promise.resolve(conn);
} catch (e) {}
}

return createConnection({
type: 'postgres',
Expand Down
1 change: 1 addition & 0 deletions src/services/chart/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Chart from './core';

export const entities = Object.values(require('require-all')({
dirname: __dirname + '/charts/schemas',
filter: /^.+\.[jt]s$/,
resolve: (x: any) => {
return Chart.schemaToEntity(x.name, x.schema);
}
Expand Down
27 changes: 11 additions & 16 deletions test/api-visibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -45,6 +37,8 @@ describe('API visibility', () => {
let other: any;
/** 非フォロワーでもリプライやメンションをされた人 */
let target: any;
/** specified mentionでmentionを飛ばされる人 */
let target2: any;

/** public-post */
let pub: any;
Expand Down Expand Up @@ -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);
Expand All @@ -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
});

Expand Down Expand Up @@ -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 () => {
Expand All @@ -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);
}));

Expand Down
44 changes: 24 additions & 20 deletions test/chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

function initDb() {
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 initChartDb() {
try {
const conn = getConnection();
return Promise.resolve(conn);
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions test/extract-mentions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down
42 changes: 16 additions & 26 deletions test/mute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand All @@ -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);
}));
});

Expand All @@ -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);
}));
});
});
29 changes: 9 additions & 20 deletions test/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
Loading