strapi/test/helpers/waitRestart.js

24 lines
650 B
JavaScript
Raw Normal View History

2019-03-09 01:06:39 +01:00
const request = require('request-promise-native');
2019-03-06 19:19:33 +01:00
module.exports = function(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(() => {
return new Promise(resolve => setTimeout(resolve, 200)).then(ping);
2019-03-06 19:19:33 +01:00
});
};
2019-03-06 19:19:33 +01:00
return new Promise(resolve => setTimeout(resolve, initTime)).then(ping);
};