strapi/test/helpers/waitRestart.js
2019-03-13 00:10:20 +01:00

24 lines
650 B
JavaScript

const request = require('request-promise-native');
module.exports = function(initTime = 200) {
const ping = async () => {
return new Promise((resolve, reject) => {
// ping _health
request({
url: 'http://localhost:1337/_health',
method: 'HEAD',
mode: 'no-cors',
json: true,
headers: {
'Content-Type': 'application/json',
'Keep-Alive': false,
},
}).then(resolve, reject);
}).catch(() => {
return new Promise(resolve => setTimeout(resolve, 200)).then(ping);
});
};
return new Promise(resolve => setTimeout(resolve, initTime)).then(ping);
};