strapi/test/helpers/waitRestart.js

30 lines
694 B
JavaScript
Raw Normal View History

'use strict';
2019-03-09 01:06:39 +01:00
const request = require('request-promise-native');
2019-03-06 19:19:33 +01:00
2022-08-08 23:33:39 +02:00
module.exports = (initTime = 200) => {
2019-03-06 19:19:33 +01:00
const ping = async () => {
return new Promise((resolve, reject) => {
// ping _health
2019-03-09 01:06:39 +01:00
request({
url: 'http://localhost:1337/_health',
method: 'HEAD',
mode: 'no-cors',
json: true,
headers: {
'Content-Type': 'application/json',
'Keep-Alive': false,
2019-03-06 19:19:33 +01:00
},
2019-03-09 01:06:39 +01:00
}).then(resolve, reject);
}).catch(() => {
2022-08-08 23:33:39 +02:00
return new Promise((resolve) => {
setTimeout(resolve, 200);
}).then(ping);
2019-03-06 19:19:33 +01:00
});
};
2022-08-08 23:33:39 +02:00
return new Promise((resolve) => {
setTimeout(resolve, initTime);
}).then(ping);
};