From 92c59a18e40065d9e79a44996b4badcc91d4e941 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Tue, 6 Mar 2018 09:21:17 -0800 Subject: [PATCH] fix test setup process --- bin/run-mastodon.js | 2 +- bin/wait-for-mastodon-data.js | 30 ++++++++++++++++++++++++++++++ bin/wait-for-mastodon-to-start.js | 7 +++---- package.json | 3 ++- 4 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 bin/wait-for-mastodon-data.js diff --git a/bin/run-mastodon.js b/bin/run-mastodon.js index ffea10a0..7f0b732e 100644 --- a/bin/run-mastodon.js +++ b/bin/run-mastodon.js @@ -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 diff --git a/bin/wait-for-mastodon-data.js b/bin/wait-for-mastodon-data.js new file mode 100644 index 00000000..9931df88 --- /dev/null +++ b/bin/wait-for-mastodon-data.js @@ -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) + }) +} diff --git a/bin/wait-for-mastodon-to-start.js b/bin/wait-for-mastodon-to-start.js index b0f5b17d..8f3da02a 100644 --- a/bin/wait-for-mastodon-to-start.js +++ b/bin/wait-for-mastodon-to-start.js @@ -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) }) diff --git a/package.json b/package.json index 5aa17e64..2b96a8bf 100644 --- a/package.json +++ b/package.json @@ -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 ."