From 470f09e16ea4c65a94f7bdcd00b9d38eafb7b48e Mon Sep 17 00:00:00 2001 From: Lillian Zhang Date: Tue, 2 Jun 2020 14:51:13 -0700 Subject: [PATCH 1/2] replace deprecated request with got --- package.json | 4 ++-- test.js | 29 ++++++++++++++++------------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 232ab4b..6998917 100644 --- a/package.json +++ b/package.json @@ -12,10 +12,10 @@ }, "dependencies": { "ejs": "^2.5.6", - "express": "^4.15.2" + "express": "^4.15.2", + "got": "^11.1.4" }, "devDependencies": { - "request": "^2.81.0", "tape": "^4.7.0" }, "repository": { diff --git a/test.js b/test.js index 5575106..e64f67f 100644 --- a/test.js +++ b/test.js @@ -1,5 +1,5 @@ const { spawn } = require('child_process'); -const request = require('request'); +const got = require('got'); const test = require('tape'); // Start the app @@ -12,17 +12,20 @@ test('responds to requests', (t) => { // Wait until the server is ready child.stdout.on('data', _ => { // Make a request to our app - request('http://127.0.0.1:5000', (error, response, body) => { - // stop the server - child.kill(); - - // No error - t.false(error); - // Successful response - t.equal(response.statusCode, 200); - // Assert content checks - t.notEqual(body.indexOf("Node.js Getting Started on Heroku"), -1); - t.notEqual(body.indexOf("Getting Started on Heroku with Node.js"), -1); - }); + (async () => { + try { + const response = await got('http://127.0.0.1:5000'); + // stop the server + child.kill(); + // No error + t.false(error); + // Successful response + t.equal(response.statusCode, 200); + // Assert content checks + t.notEqual(body.indexOf("Node.js Getting Started on Heroku"), -1); + t.notEqual(body.indexOf("Getting Started on Heroku with Node.js"), -1); + } catch (error) { + } + })(); }); }); From 5445cdc1241fb235cfaa347c104edf66bf4df7d9 Mon Sep 17 00:00:00 2001 From: Lillian Zhang Date: Mon, 8 Jun 2020 12:34:00 -0700 Subject: [PATCH 2/2] add got to dev and fix errors --- package.json | 4 ++-- test.js | 23 ++++++++++------------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 6998917..affba49 100644 --- a/package.json +++ b/package.json @@ -12,10 +12,10 @@ }, "dependencies": { "ejs": "^2.5.6", - "express": "^4.15.2", - "got": "^11.1.4" + "express": "^4.15.2" }, "devDependencies": { + "got": "^11.3.0", "tape": "^4.7.0" }, "repository": { diff --git a/test.js b/test.js index e64f67f..3cc1e0e 100644 --- a/test.js +++ b/test.js @@ -13,19 +13,16 @@ test('responds to requests', (t) => { child.stdout.on('data', _ => { // Make a request to our app (async () => { - try { - const response = await got('http://127.0.0.1:5000'); - // stop the server - child.kill(); - // No error - t.false(error); - // Successful response - t.equal(response.statusCode, 200); - // Assert content checks - t.notEqual(body.indexOf("Node.js Getting Started on Heroku"), -1); - t.notEqual(body.indexOf("Getting Started on Heroku with Node.js"), -1); - } catch (error) { - } + const response = await got('http://127.0.0.1:5000'); + // stop the server + child.kill(); + // No error + t.false(response.error); + // Successful response + t.equal(response.statusCode, 200); + // Assert content checks + t.notEqual(response.body.indexOf("Node.js Getting Started on Heroku"), -1); + t.notEqual(response.body.indexOf("Getting Started on Heroku with Node.js"), -1); })(); }); });