Fix flaky tests (#3724)

* adds continuation to silence rejected promises

* Wrap json parsing
This commit is contained in:
Florent Vilmart
2017-04-16 16:50:03 -04:00
committed by GitHub
parent dcd8e5626a
commit 5813fd0bf8
12 changed files with 63 additions and 14 deletions

View File

@@ -10,8 +10,12 @@ describe('AuthenticationProviers', function() {
var provider = require("../src/Adapters/Auth/" + providerName);
jequal(typeof provider.validateAuthData, "function");
jequal(typeof provider.validateAppId, "function");
jequal(provider.validateAuthData({}, {}).constructor, Promise.prototype.constructor);
jequal(provider.validateAppId("app", "key", {}).constructor, Promise.prototype.constructor);
const authDataPromise = provider.validateAuthData({}, {});
const validateAppIdPromise = provider.validateAppId("app", "key", {});
jequal(authDataPromise.constructor, Promise.prototype.constructor);
jequal(validateAppIdPromise.constructor, Promise.prototype.constructor);
authDataPromise.then(()=>{}, ()=>{});
validateAppIdPromise.then(()=>{}, ()=>{});
done();
});
});

View File

@@ -43,7 +43,11 @@ function graphRequest(path) {
data += chunk;
});
res.on('end', function() {
data = JSON.parse(data);
try {
data = JSON.parse(data);
} catch(e) {
return reject(e);
}
resolve(data);
});
}).on('error', function() {

View File

@@ -36,7 +36,11 @@ function request(path, access_token) {
data += chunk;
});
res.on('end', function() {
data = JSON.parse(data);
try {
data = JSON.parse(data);
} catch(e) {
return reject(e);
}
resolve(data);
});
}).on('error', function() {

View File

@@ -55,7 +55,11 @@ function request(path) {
data += chunk;
});
res.on('end', function() {
data = JSON.parse(data);
try {
data = JSON.parse(data);
} catch(e) {
return reject(e);
}
resolve(data);
});
}).on('error', function() {

View File

@@ -41,7 +41,7 @@ function request(api_key, auth_token) {
}
};
return new Promise(function (resolve) {
return new Promise(function (resolve, reject) {
// Create the post request.
var post_req = https.request(post_options, function (res) {
var data = '';
@@ -52,7 +52,12 @@ function request(api_key, auth_token) {
});
// Once we have all the data, we can parse it and return the data we want.
res.on('end', function () {
resolve(JSON.parse(data));
try {
data = JSON.parse(data);
} catch(e) {
return reject(e);
}
resolve(data);
});
});

View File

@@ -42,7 +42,11 @@ function request(path, access_token, is_mobile_sdk) {
data += chunk;
});
res.on('end', function() {
data = JSON.parse(data);
try {
data = JSON.parse(data);
} catch(e) {
return reject(e);
}
resolve(data);
});
}).on('error', function() {

View File

@@ -35,7 +35,11 @@ function request(path, access_token) {
data += chunk;
});
res.on('end', function() {
data = JSON.parse(data);
try {
data = JSON.parse(data);
} catch(e) {
return reject(e);
}
resolve(data);
});
}).on('error', function() {

View File

@@ -32,7 +32,11 @@ function graphRequest(path) {
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'qq auth is invalid for this user.');
}
data = data.substring(starPos + 1,endPos - 1);
data = JSON.parse(data);
try {
data = JSON.parse(data);
} catch(e) {
return reject(e);
}
resolve(data);
});
}).on('error', function () {

View File

@@ -49,7 +49,11 @@ function request(path, access_token) {
data += chunk;
});
res.on('end', function() {
data = JSON.parse(data);
try {
data = JSON.parse(data);
} catch(e) {
return reject(e);
}
resolve(data);
});
}).on('error', function() {

View File

@@ -47,7 +47,11 @@ function request(host, path) {
data += chunk;
});
res.on('end', function () {
data = JSON.parse(data);
try {
data = JSON.parse(data);
} catch(e) {
return reject(e);
}
resolve(data);
});
}).on('error', function () {

View File

@@ -26,7 +26,11 @@ function graphRequest(path) {
data += chunk;
});
res.on('end', function () {
data = JSON.parse(data);
try {
data = JSON.parse(data);
} catch(e) {
return reject(e);
}
resolve(data);
});
}).on('error', function () {

View File

@@ -39,7 +39,11 @@ function graphRequest(access_token) {
data += chunk;
});
res.on('end', function () {
data = JSON.parse(data);
try {
data = JSON.parse(data);
} catch(e) {
return reject(e);
}
resolve(data);
});
res.on('error', function () {