fix test setup process
This commit is contained in:
parent
814a4dce76
commit
92c59a18e4
|
@ -3,7 +3,7 @@ import pify from 'pify'
|
|||
import childProcessPromise from 'child-process-promise'
|
||||
import path from 'path'
|
||||
import fs from 'fs'
|
||||
import { waitForMastodonApiToStart, waitForMastodonUiToStart } from './wait-for-mastodon-to-start'
|
||||
import { waitForMastodonUiToStart, waitForMastodonApiToStart } from './wait-for-mastodon-to-start'
|
||||
import mkdirpCB from 'mkdirp'
|
||||
|
||||
const exec = childProcessPromise.exec
|
||||
|
|
30
bin/wait-for-mastodon-data.js
Normal file
30
bin/wait-for-mastodon-data.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
import fetch from 'node-fetch'
|
||||
import { actions } from './mastodon-data'
|
||||
|
||||
const numStatuses = actions.filter(_ => _.post || _.boost).length
|
||||
|
||||
async function waitForMastodonData () {
|
||||
while (true) {
|
||||
try {
|
||||
let json = await ((await fetch('http://127.0.0.1:3000/api/v1/instance')).json())
|
||||
if (json.stats.status_count === numStatuses) {
|
||||
break
|
||||
} else {
|
||||
console.log('Waiting for number of statuses to equal ' +
|
||||
numStatuses + ' (currently ' + json.stats.status_count + ')...')
|
||||
}
|
||||
} catch (err) {
|
||||
console.log('Waiting for Mastodon API to be available...')
|
||||
} finally {
|
||||
await new Promise(resolve => setTimeout(resolve, 5000))
|
||||
}
|
||||
}
|
||||
console.log('Mastodon data populated')
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
waitForMastodonData().catch(err => {
|
||||
console.error(err)
|
||||
process.exit(1)
|
||||
})
|
||||
}
|
|
@ -31,10 +31,9 @@ export async function waitForMastodonApiToStart () {
|
|||
}
|
||||
|
||||
if (require.main === module) {
|
||||
Promise.all([
|
||||
waitForMastodonApiToStart(),
|
||||
waitForMastodonUiToStart()
|
||||
]).catch(err => {
|
||||
Promise.resolve()
|
||||
.then(waitForMastodonApiToStart)
|
||||
.then(waitForMastodonUiToStart).catch(err => {
|
||||
console.error(err)
|
||||
process.exit(1)
|
||||
})
|
||||
|
|
|
@ -16,8 +16,9 @@
|
|||
"run-testcafe": "cross-env-shell testcafe --hostname localhost --skip-js-errors $BROWSER tests/spec",
|
||||
"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",
|
||||
"test-mastodon": "run-s wait-for-mastodon-to-start wait-for-mastodon-data run-testcafe",
|
||||
"wait-for-mastodon-to-start": "node -r @std/esm bin/wait-for-mastodon-to-start.js",
|
||||
"wait-for-mastodon-data": "node -r @std/esm bin/wait-for-mastodon-data.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 ."
|
||||
|
|
Loading…
Reference in a new issue