replace deprecated request with got

main
Lillian Zhang 4 years ago
parent b9a3b99865
commit 470f09e16e

@ -12,10 +12,10 @@
}, },
"dependencies": { "dependencies": {
"ejs": "^2.5.6", "ejs": "^2.5.6",
"express": "^4.15.2" "express": "^4.15.2",
"got": "^11.1.4"
}, },
"devDependencies": { "devDependencies": {
"request": "^2.81.0",
"tape": "^4.7.0" "tape": "^4.7.0"
}, },
"repository": { "repository": {

@ -1,5 +1,5 @@
const { spawn } = require('child_process'); const { spawn } = require('child_process');
const request = require('request'); const got = require('got');
const test = require('tape'); const test = require('tape');
// Start the app // Start the app
@ -12,17 +12,20 @@ test('responds to requests', (t) => {
// Wait until the server is ready // Wait until the server is ready
child.stdout.on('data', _ => { child.stdout.on('data', _ => {
// Make a request to our app // Make a request to our app
request('http://127.0.0.1:5000', (error, response, body) => { (async () => {
// stop the server try {
child.kill(); const response = await got('http://127.0.0.1:5000');
// stop the server
// No error child.kill();
t.false(error); // No error
// Successful response t.false(error);
t.equal(response.statusCode, 200); // Successful response
// Assert content checks t.equal(response.statusCode, 200);
t.notEqual(body.indexOf("<title>Node.js Getting Started on Heroku</title>"), -1); // Assert content checks
t.notEqual(body.indexOf("Getting Started on Heroku with Node.js"), -1); t.notEqual(body.indexOf("<title>Node.js Getting Started on Heroku</title>"), -1);
}); t.notEqual(body.indexOf("Getting Started on Heroku with Node.js"), -1);
} catch (error) {
}
})();
}); });
}); });

Loading…
Cancel
Save