diff --git a/.circleci/config.yml b/.circleci/config.yml index e82c5290b..7984c9373 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,76 +1,12 @@ version: 2.1 executors: - default: - working_directory: /tmp/workspace - docker: - - image: misskey/ci:v11-node11 - - image: circleci/redis:latest - - image: circleci/postgres:latest docker: working_directory: /tmp/workspace docker: - image: docker:latest jobs: - build: - executor: default - steps: - - checkout - - run: - name: Ensure yarn.lock - command: | - touch yarn.lock - - restore_cache: - name: Restore npm package caches - keys: - - yarn-v1-arch-{{ arch }}-env-{{ .Environment.variableName }}-package-{{ checksum "package.json" }}-lock-{{ checksum "yarn.lock" }} - - yarn-v1-arch-{{ arch }}-env-{{ .Environment.variableName }}-package-{{ checksum "package.json" }}- - - yarn-v1-arch-{{ arch }}-env-{{ .Environment.variableName }}- - - yarn-v1-arch-{{ arch }}- - - yarn-v1- - - run: - name: Install Dependencies - command: | - yarn install - - run: - name: Configure - command: | - cp .circleci/misskey/default.yml .config - cp .circleci/misskey/test.yml .config - - run: - name: Build - command: | - yarn build - touch yarn.lock - - save_cache: - name: Cache npm packages - key: yarn-v1-arch-{{ arch }}-env-{{ .Environment.variableName }}-package-{{ checksum "package.json" }}-lock-{{ checksum "yarn.lock" }} - paths: - - node_modules - - persist_to_workspace: - root: . - paths: - - . - test: - parameters: - executor: - type: string - default: "default" - executor: <> - steps: - - attach_workspace: - at: /tmp/workspace - - run: - name: Test - command: | - yarn test - touch yarn.lock - - save_cache: - name: Cache npm packages - key: yarn-v1-arch-{{ arch }}-env-{{ .Environment.variableName }}-package-{{ checksum "package.json" }}-lock-{{ checksum "yarn.lock" }} - paths: - - node_modules docker: parameters: with_deploy: @@ -102,55 +38,8 @@ jobs: workflows: version: 2 - nodejs: - jobs: - - hold: - name: manual-build-trigger - type: approval - filters: - branches: - ignore: master - - build: - name: manual-build - requires: - - manual-build-trigger - filters: - branches: - ignore: master - - build: - name: auto-build - filters: - branches: - only: master - - test: - name: manual-test - requires: - - manual-build - filters: - branches: - ignore: master - - test: - name: auto-test - requires: - - auto-build - filters: - branches: - only: master docker: jobs: - - hold: - name: manual-build-trigger - type: approval - filters: - branches: - ignore: master - - docker: - name: manual-build - requires: - - manual-build-trigger - filters: - branches: - ignore: master - docker: name: auto-build with_deploy: true diff --git a/.circleci/misskey/default.yml b/.circleci/misskey/default.yml index 5cdb7330c..ae18a841b 100644 --- a/.circleci/misskey/default.yml +++ b/.circleci/misskey/default.yml @@ -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 diff --git a/.circleci/misskey/test.yml b/.circleci/misskey/test.yml index 99ad50876..ae18a841b 100644 --- a/.circleci/misskey/test.yml +++ b/.circleci/misskey/test.yml @@ -1,13 +1,12 @@ url: 'http://misskey.local' -port: 80 -mongodb: +port: 8080 +db: host: localhost - port: 27017 + port: 5432 db: test-misskey - user: admin + user: postgres pass: '' -# __REDIS__ redis: host: localhost port: 6379 - pass: '' +id: aid diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 000000000..f1c3ef0b6 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,18 @@ +name: Docker build +on: + push: + branches: + - master + - develop + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v1 + - name: Pull previous build result (for cache) + run: docker pull misskey/misskey:latest + - name: Build docker container + run: docker build --cache-from misskey/misskey:latest -t misskey/misskey . diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml new file mode 100644 index 000000000..c5c8b3597 --- /dev/null +++ b/.github/workflows/nodejs.yml @@ -0,0 +1,42 @@ +name: Node.js CI +on: + push: + branches: + - master + - develop + pull_request: + +jobs: + build_and_test: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [11.10.x, 12.x] + + services: + postgres: + image: postgres:10-alpine + ports: + - 5432:5432 + env: + POSTGRES_DB: test-misskey + redis: + image: redis:alpine + ports: + - 6379:6379 + + steps: + - uses: actions/checkout@v1 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - name: Install dependencies + run: yarn install + - name: Copy Configure + run: cp .circleci/misskey/*.yml .config + - name: Build + run: yarn build + - name: Test + run: yarn test diff --git a/package.json b/package.json index 608265d5a..0f0dda57a 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -259,6 +259,7 @@ "xev": "2.0.1" }, "devDependencies": { - "@types/fluent-ffmpeg": "2.1.12" + "@types/fluent-ffmpeg": "2.1.12", + "cross-env": "6.0.3" } } diff --git a/src/db/postgre.ts b/src/db/postgre.ts index ad59e8650..0947a5983 100644 --- a/src/db/postgre.ts +++ b/src/db/postgre.ts @@ -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', diff --git a/src/services/chart/entities.ts b/src/services/chart/entities.ts index 14fd3adba..e3d5e6f8c 100644 --- a/src/services/chart/entities.ts +++ b/src/services/chart/entities.ts @@ -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); } diff --git a/test/api-visibility.ts b/test/api-visibility.ts index 1e263bef5..47b222b16 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 98c501f91..4f626ed9a 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; + 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 a70926cbb..00f736ae1 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 07c77f762..1b1a8d7a5 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 4a4a77734..3aa12b5a6 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 1eb1b7ff4..cb962cfb3 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 63a97cd80..509418020 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 f67baf004..af190254e 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 => 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 => new Promis export function connectStream(user: any, channel: string, listener: (message: Record) => any, params?: any): Promise { 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 = 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)); + }); + }; +} diff --git a/yarn.lock b/yarn.lock index 57b98d007..d6208cc76 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2743,6 +2743,13 @@ cropperjs@^1.5.6: resolved "https://registry.yarnpkg.com/cropperjs/-/cropperjs-1.5.6.tgz#82faf432bec709d828f2f7a96d1179198edaf0e2" integrity sha512-eAgWf4j7sNJIG329qUHIFi17PSV0VtuWyAu9glZSgu/KlQSrfTQOC2zAz+jHGa5fAB+bJldEnQwvJEaJ8zRf5A== +cross-env@6.0.3: + version "6.0.3" + resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-6.0.3.tgz#4256b71e49b3a40637a0ce70768a6ef5c72ae941" + integrity sha512-+KqxF6LCvfhWvADcDPqo64yVIB31gv/jQulX2NGzKS/g3GEVz6/pt4wjHFtFWsHMddebWD/sDthJemzM4MaAag== + dependencies: + cross-spawn "^7.0.0" + cross-spawn@6.0.5, cross-spawn@^6.0.0, cross-spawn@^6.0.5: version "6.0.5" resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-6.0.5.tgz#4a5ec7c64dfae22c3a14124dbacdee846d80cbc4"