Skip to content

Commit

Permalink
fix tests (#5544)
Browse files Browse the repository at this point in the history
* 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 56e35cf.

* 一回一回sync→dropしてるのをやめてみる

* fix

* fix

* …

* キャッシュを切ってみる

* add ts to require target

* omg fix

* Revert "キャッシュを切ってみる"

This reverts commit 88161c5.

* done呼び忘れ

* 実際の文字数リミットと違ってたので対応

* テストケースがバグってたので修正

* Revert "一回一回sync→dropしてるのをやめてみる"

This reverts commit a9e543b.

* fix

* fix

* fix

* fix?

* fix

* chartのconnectionを分離する

* fix

* fix

* fix tsconfig?

* Revert "fix tsconfig?"

This reverts commit ba9269e.

* fix

* TS_NODE_FILES を scripts の方で指定

* Windowsェ
  • Loading branch information
rinsuki authored and syuilo committed Nov 10, 2019
1 parent 3ac0338 commit 8e5691a
Show file tree
Hide file tree
Showing 15 changed files with 130 additions and 150 deletions.
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

0 comments on commit 8e5691a

Please sign in to comment.