This commit is contained in:
Nolan Lawson 2018-03-05 21:21:28 -08:00
parent 97fb94dba6
commit 9db0d3547a
5 changed files with 51 additions and 20 deletions

View file

@ -101,7 +101,18 @@ export const actions = times(30, i => ({
},
{
user: 'foobar',
follow: 'quux'
post: {
text: 'this is followers-only',
privacy: 'private'
}
},
{
user: 'foobar',
post: {
internalId: 2,
text: 'this is unlisted',
privacy: 'unlisted'
}
},
{
user: 'admin',
@ -139,14 +150,6 @@ export const actions = times(30, i => ({
user: 'admin',
boost: 1
},
{
user: 'foobar',
post: {
internalId: 2,
text: 'this is unlisted',
privacy: 'private'
}
},
{
user: 'admin',
favorite: 2

View file

@ -8,6 +8,10 @@ import { reblogStatus } from '../routes/_api/reblog'
import fetch from 'node-fetch'
import FileApi from 'file-api'
import path from 'path'
import fs from 'fs'
import pify from 'pify'
const readFile = pify(fs.readFile.bind(fs))
global.File = FileApi.File
global.FormData = FileApi.FormData
@ -26,7 +30,13 @@ export async function restoreMastodonData () {
inReplyTo = internalIdsToIds[inReplyTo]
}
let mediaIds = media && await Promise.all(media.map(async mediaItem => {
let file = new File(path.join(__dirname, '../tests/images/' + mediaItem))
let type = mediaItem.endsWith('gif') ? 'image/gif'
: mediaItem.endsWith('jpg') ? 'image/jpg' : 'video/mp4'
let file = new File({
name: mediaItem,
type: type,
buffer: await readFile(path.join(__dirname, '../tests/images/' + mediaItem))
})
let mediaResponse = await uploadMedia('localhost:3000', accessToken, file)
return mediaResponse.id
}))
@ -43,4 +53,5 @@ export async function restoreMastodonData () {
await reblogStatus('localhost:3000', accessToken, internalIdsToIds[action.boost])
}
}
console.log('Restored mastodon data')
}

View file

@ -3,7 +3,7 @@ import pify from 'pify'
import childProcessPromise from 'child-process-promise'
import path from 'path'
import fs from 'fs'
import { waitForMastodonToStart } from './wait-for-mastodon-to-start'
import { waitForMastodonApiToStart, waitForMastodonUiToStart } from './wait-for-mastodon-to-start'
import mkdirpCB from 'mkdirp'
const exec = childProcessPromise.exec
@ -68,15 +68,15 @@ async function runMastodon () {
childProc = promise.childProcess
childProc.stdout.pipe(log)
childProc.stderr.pipe(log)
await waitForMastodonToStart()
}
async function main () {
await cloneMastodon()
await setupMastodonDatabase()
await runMastodon()
await waitForMastodonApiToStart()
await restoreMastodonData()
await waitForMastodonUiToStart()
}
process.on('SIGINT', function () {

View file

@ -1,23 +1,40 @@
import fetch from 'node-fetch'
export async function waitForMastodonToStart () {
export async function waitForMastodonUiToStart () {
while (true) {
try {
let json = await ((await fetch('http://127.0.0.1:3000/api/v1/instance')).json())
let html = await ((await fetch('http://127.0.0.1:3035/packs/common.js')).text())
if (json.uri && html) {
if (html) {
break
}
} catch (err) {
console.log('Waiting for Mastodon to start up...')
console.log('Waiting for Mastodon UI to start up...')
await new Promise(resolve => setTimeout(resolve, 1000))
}
}
console.log('Mastodon started up')
console.log('Mastodon UI started up')
}
export async function waitForMastodonApiToStart () {
while (true) {
try {
let json = await ((await fetch('http://127.0.0.1:3000/api/v1/instance')).json())
if (json.uri) {
break
}
} catch (err) {
console.log('Waiting for Mastodon API to start up...')
await new Promise(resolve => setTimeout(resolve, 1000))
}
}
console.log('Mastodon API started up')
}
if (require.main === module) {
waitForMastodonToStart().catch(err => {
Promise.all([
waitForMastodonApiToStart(),
waitForMastodonUiToStart()
]).catch(err => {
console.error(err)
process.exit(1)
})

View file

@ -17,7 +17,7 @@
"test": "cross-env BROWSER=chrome:headless npm run test-browser",
"test-browser": "run-p --race run-mastodon dev test-mastodon",
"test-mastodon": "run-s wait-for-mastodon-to-start run-testcafe",
"wait-for-mastodon-to-start": "node bin/wait-for-mastodon-to-start.js",
"wait-for-mastodon-to-start": "node -r @std/esm bin/wait-for-mastodon-to-start.js",
"globalize-css": "node ./bin/globalize-css.js",
"deglobalize-css": "node ./bin/globalize-css.js --reverse",
"backup-mastodon-data": "pg_dump -Fc mastodon_development > fixtures/dump.sql && cd mastodon/public/system && tar -czf ../../../fixtures/system.tgz ."