Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function start() {
await getStream(await docker.pull(IMAGE));
container = await docker.createContainer({
Tty: true,
Image: IMAGE,
PortBindings: {[`${COUCHDB_PORT}/tcp`]: [{HostPort: `${SERVER_PORT}`}]},
Env: [`COUCHDB_USER=${COUCHDB_USER}`, `COUCHDB_PASSWORD=${COUCHDB_PASSWORD}`],
});
await container.start();
await delay(4000);
try {
// Wait for the registry to be ready
await pRetry(() => got(`http://${SERVER_HOST}:${SERVER_PORT}/registry/_design/app`, {cache: false}), {
retries: 7,
minTimeout: 1000,
factor: 2,
});
} catch (_) {
throw new Error(`Couldn't start npm-docker-couchdb after 2 min`);
}
// Create user
await got(`http://${SERVER_HOST}:${SERVER_PORT}/_users/org.couchdb.user:${NPM_USERNAME}`, {
json: true,
auth: `${COUCHDB_USER}:${COUCHDB_PASSWORD}`,
const delay =
methodOptions &&
typeof methodOptions === 'object' &&
typeof methodOptions.delay === 'number'
? methodOptions.delay
: options.delay;
if (methodOptions) {
args[len - 1] = omit(methodOptions, ['delay']);
}
if (this.typingOn) {
await this.typingOn();
}
await sleep(delay);
return _method.call(context, ...args);
};
/* eslint-enable func-names */
export async function tryFetch(url: string) {
while (!navigator.onLine) {
console.error("you're offline, retrying...")
await delay(1000)
}
const response = await fetch(proxify(url, 'latin1'))
if (response.status !== 200) {
throw new Error(`${url}: ${response.status}`)
}
const text = await response.text()
if (text.includes('<title>404 Not Found</title>')) {
// stupid me
throw new Error(`${url}: 404`)
}
return text
}
async function tryFetch(url: string) {
while (!navigator.onLine) {
console.error("you're offline, retrying...")
await delay(1000)
}
const text = await proxy(url, 'latin1')
if (text.includes('<title>404 Not Found</title>')) {
// stupid me
throw new Error(`${url}: 404`)
}
return text
}
// stage,
season,
})
setPopup({
waiting: false,
error: null,
})
} catch (err) {
console.error(err)
setPopup({
waiting: false,
error: 'Could not fetch data',
})
await delay(1000)
const {
tournament: newTournament,
stage: newStage,
} = params
const newSeason = pots && season !== currentSeasonByTournament(newTournament, newStage)
? season
: undefined
onSeasonChange(newTournament, newStage, newSeason)
setPopup({
error: null,
})
}
}
async componentDidMount() {
// UI Boot
await delay(150)
const { isFirstVisit, ...actions } = this.props
if (isFirstVisit) {
// Start omotenashi
// Remove first visit flag
await actions.setConfigValue({ key: "isFirstVisit", value: false })
// Open scratch.md as user first view
actions.loadFile({ filepath: "/playground/scratch.md" })
// TODO: Reload git on init. Sometimes initialze on git is failing
await delay(300)
actions.initializeGitStatus("/playground")
}
// TODO: dirty hack to focus
// Focus first element
await delay(150)
const target = (document as any).querySelector("textarea")
target && target.focus()
}
})
app.on('ready', async () => {
// transparency workaround https://github.com/electron/electron/issues/2170
await delay(10)
mb = menubar({
alwaysOnTop: process.env.NODE_ENV === 'development',
icon: path.join(app.getAppPath(), '/static/tray.png'),
width: 500,
minWidth: 500,
maxWidth: 500,
minHeight: 530,
hasShadow: false,
preloadWindow: true,
resizable: true,
transparent: true,
frame: false,
toolbar: false
})
async function dev() {
let proc;
const wrapper = () => {
if (proc) {
proc.kill();
}
};
process.on('SIGINT', wrapper);
process.on('SIGTERM', wrapper);
process.on('exit', wrapper);
proc = serve(server, false);
await delay(300);
// const app = module.exports.__REACT_SSR_EXPRESS__;
// app.listen(8888, async () => {
// const url = (route) => `http://localhost:8888${route}`;
// spinner.create(`Building '/'`);
// await got(url('/'));
// spinner.create(`Building '/' (test 2)`);
// await got(url('/'));
// spinner.create(`Building '/' (test 3)`);
// await got(url('/'));
// spinner.clear('Success!');
test('cache', async t => {
const alfy = createAlfy();
t.deepEqual(await alfy.fetch(`${URL}/cache`, {maxAge: 5000}), {hello: 'world'});
t.deepEqual(await alfy.fetch(`${URL}/cache`, {maxAge: 5000}), {hello: 'world'});
await delay(5000);
t.deepEqual(await alfy.fetch(`${URL}/cache`, {maxAge: 5000}), {hello: 'world!'});
});
let receivedSms;
let messageListener = evt => {
receivedSms = evt.body;
subscription.removeListener('message', messageListener);
notify('The subscription is alive. Notification delay:' + (Date.now() - sentTime));
rc.account().extension().messageStore(receivedSms.id).delete({});
rc.account().extension().messageStore(sentSms.id).delete({});
};
subscription.onMessage(messageListener);
let sentSms = await rc.account().extension().sms().post({
from: { phoneNumber: config.user.username },
to: [{ phoneNumber: config.user.username }],
text: 'Test sms to trigger subscription.'
});
let sentTime = Date.now();
await delay(notificationTimeout * 60 * 1000);
if (!receivedSms) {
let msg = 'The notification does not arrive in ' + notificationTimeout + ' minutes.';
await notify(msg);
await subscription.cancel();
process.exit(1);
}
}