From 741a667f3a49463025e8982cf4b27806f9765da5 Mon Sep 17 00:00:00 2001 From: Paul Barry Date: Thu, 19 Oct 2023 01:01:44 -0400 Subject: [PATCH] Issue-1016: Progress on removal of request --- .../qraphql-server/graphql-server.spec.js | 72 ++++++------------- .../develop.default/develop.default.spec.js | 67 +++++------------ .../develop.default/develop.default.spec.js | 33 +++------ .../cases/serve.default/serve.default.spec.js | 49 ++++--------- 4 files changed, 65 insertions(+), 156 deletions(-) diff --git a/packages/plugin-graphql/test/cases/qraphql-server/graphql-server.spec.js b/packages/plugin-graphql/test/cases/qraphql-server/graphql-server.spec.js index ead6131e9..4fa353c24 100644 --- a/packages/plugin-graphql/test/cases/qraphql-server/graphql-server.spec.js +++ b/packages/plugin-graphql/test/cases/qraphql-server/graphql-server.spec.js @@ -15,7 +15,6 @@ * Greenwood default (src/) */ import chai from 'chai'; -import request from 'request'; import path from 'path'; import { Runner } from 'gallinago'; import { fileURLToPath, URL } from 'url'; @@ -26,12 +25,12 @@ describe('Develop Greenwood With: ', function() { const LABEL = 'GraphQL Server'; const cliPath = path.join(process.cwd(), 'packages/cli/src/index.js'); const outputPath = fileURLToPath(new URL('.', import.meta.url)); - const hostname = '127.0.0.1'; + const hostname = 'localhost'; const port = 4000; let runner; before(function() { - runner = new Runner(); + runner = new Runner(true); }); describe(LABEL, function() { @@ -56,42 +55,29 @@ describe('Develop Greenwood With: ', function() { }; before(async function() { - return new Promise((resolve, reject) => { - request.get({ - url: `http://${hostname}:${port}`, - headers: { - accept: 'text/html' - } - }, (err, res) => { - if (err) { - reject(); - } - - response.status = res.statusCode; - response.headers = res.headers; - - resolve(response); - }); + response = await fetch(`http://${hostname}:${port}`, { + headers: { + accept: 'text/html' + } }); }); - it('should return a 200 status', function(done) { + it('should return a 200 status', function() { expect(response.status).to.equal(200); - done(); }); - it('should return the correct content type', function(done) { - expect(response.headers['content-type']).to.equal('text/html'); - done(); + it('should return the correct content type', function() { + expect(response.headers.get('content-type')).to.equal('text/html'); }); }); // test a query call - describe('Develop command with GraphQL server and running a query', function() { + describe.only('Develop command with GraphQL server and running a query', function() { let response = { body: '', code: 0 }; + let data; const body = { 'operationName': null, @@ -100,38 +86,26 @@ describe('Develop Greenwood With: ', function() { }; before(async function() { - return new Promise((resolve, reject) => { - request.post({ - url: `http://${hostname}:${port}/graphql`, - json: true, - body - }, (err, res, body) => { - if (err) { - reject(); - } - - response.status = res.statusCode; - response.headers = res.headers; - response.body = body; - - resolve(response); - }); + response = await fetch(`http://${hostname}:${port}/graphql`, { + method: 'POST', + body: JSON.stringify(body), + headers: { + 'content-type': 'application/json' + } }); + data = await response.text(); }); - it('should return a 200 status', function(done) { + it('should return a 200 status', function() { expect(response.status).to.equal(200); - done(); }); - it('should return the correct content type', function(done) { - expect(response.headers['content-type']).to.equal('application/json; charset=utf-8'); - done(); + it('should return the correct content type', function() { + expect(response.headers.get('content-type')).to.equal('application/json; charset=utf-8'); }); - it('should return the expected query response', function(done) { - expect(response.body.data.config.workspace).to.equal(new URL('./src/', import.meta.url).href); - done(); + it('should return the expected query response', function() { + expect(data.config.workspace).to.equal(new URL('./src/', import.meta.url).href); }); }); }); diff --git a/packages/plugin-import-css/test/cases/develop.default/develop.default.spec.js b/packages/plugin-import-css/test/cases/develop.default/develop.default.spec.js index 601c872a3..45c06f766 100644 --- a/packages/plugin-import-css/test/cases/develop.default/develop.default.spec.js +++ b/packages/plugin-import-css/test/cases/develop.default/develop.default.spec.js @@ -24,7 +24,6 @@ */ import chai from 'chai'; import path from 'path'; -import request from 'request'; import { Runner } from 'gallinago'; import { fileURLToPath, URL } from 'url'; import { runSmokeTest } from '../../../../../test/smoke-test.js'; @@ -64,42 +63,27 @@ describe('Develop Greenwood With: ', function() { describe('Develop command specific ESM .css behaviors', function() { let response = {}; + let data; before(async function() { - return new Promise((resolve, reject) => { - request.get({ - url: `http://127.0.0.1:${port}/main.css?type=css` - }, (err, res, body) => { - if (err) { - reject(); - } - - response = res; - response.body = body; - - resolve(); - }); - }); + response = await fetch(`http://localhost:${port}/main.css?type=css`); + data = await response.text(); }); - it('should return a 200', function(done) { - expect(response.statusCode).to.equal(200); - - done(); + it('should return a 200', function() { + expect(response.status).to.equal(200); }); - it('should return the correct content type', function(done) { - expect(response.headers['content-type']).to.equal('text/javascript'); - done(); + it('should return the correct content type', function() { + expect(response.headers.get('content-type')).to.equal('text/javascript'); }); // https://github.com/ProjectEvergreen/greenwood/issues/766 // https://unpkg.com/browse/bootstrap@4.6.1/dist/css/bootstrap.css // https://unpkg.com/browse/font-awesome@4.7.0/css/font-awesome.css - it('should return an ECMASCript module', function(done) { - expect(response.body.replace('\n', '').replace(/ /g, '').trim()) + it('should return an ECMASCript module', function() { + expect(data.replace('\n', '').replace(/ /g, '').trim()) .to.equal('constcss=`*{background-image:url("/assets/background.jpg");font-family:\'Arial\'}.blockquote-footer::before{content:"\\\\2014\\\\00A0";}.fa-chevron-right:before{content:"\\\\f054";}`;exportdefaultcss;'); // eslint-disable-line max-len - done(); }); }); @@ -107,38 +91,23 @@ describe('Develop Greenwood With: ', function() { // https://unpkg.com/browse/@material/mwc-button@0.22.1/styles.css.js describe('Develop command specific ESM .css.js files behaviors (CSS in disguise)', function() { let response = {}; + let data; before(async function() { - return new Promise((resolve, reject) => { - request.get({ - url: `http://127.0.0.1:${port}/styles.css.js` - }, (err, res, body) => { - if (err) { - reject(); - } - - response = res; - response.body = body; - - resolve(); - }); - }); + response = await fetch(`http://localhost:${port}/styles.css.js`); + data = await response.text(); }); - it('should return a 200', function(done) { - expect(response.statusCode).to.equal(200); - - done(); + it('should return a 200', function() { + expect(response.status).to.equal(200); }); - it('should return the correct content type', function(done) { - expect(response.headers['content-type']).to.equal('text/javascript'); - done(); + it('should return the correct content type', function() { + expect(response.headers.get('content-type')).to.equal('text/javascript'); }); - it('should return an ECMASCript module', function(done) { - expect(response.body).to.equal('export const styles = css `.mdc-touch-target-wrapper{display:inline}`;'); - done(); + it('should return an ECMASCript module', function() { + expect(data).to.equal('export const styles = css `.mdc-touch-target-wrapper{display:inline}`;'); }); }); }); diff --git a/packages/plugin-import-json/test/cases/develop.default/develop.default.spec.js b/packages/plugin-import-json/test/cases/develop.default/develop.default.spec.js index cc694b00c..2cdadb981 100644 --- a/packages/plugin-import-json/test/cases/develop.default/develop.default.spec.js +++ b/packages/plugin-import-json/test/cases/develop.default/develop.default.spec.js @@ -25,7 +25,6 @@ */ import chai from 'chai'; import path from 'path'; -import request from 'request'; import { Runner } from 'gallinago'; import { fileURLToPath, URL } from 'url'; import { runSmokeTest } from '../../../../../test/smoke-test.js'; @@ -65,37 +64,23 @@ describe('Develop Greenwood With: ', function() { describe('Develop command specific ESM .json behaviors', function() { let response = {}; + let data; before(async function() { - return new Promise((resolve, reject) => { - request.get({ - url: `http://127.0.0.1:${port}/main.json?type=json` - }, (err, res) => { - if (err) { - reject(); - } - - response = res; - - resolve(); - }); - }); + response = await fetch(`http://localhost:${port}/main.json?type=json`); + data = await response.text(); }); - it('should return a 200', function(done) { - expect(response.statusCode).to.equal(200); - - done(); + it('should return a 200', function() { + expect(response.status).to.equal(200); }); - it('should return the correct content type', function(done) { - expect(response.headers['content-type']).to.equal('text/javascript'); - done(); + it('should return the correct content type', function() { + expect(response.headers.get('content-type')).to.equal('text/javascript'); }); - it('should return an ECMAScript module', function(done) { - expect(response.body).to.equal('export default {"status":200,"message":"got json"}'); - done(); + it('should return an ECMAScript module', function() { + expect(data).to.equal('export default {"status":200,"message":"got json"}'); }); }); }); diff --git a/packages/plugin-renderer-lit/test/cases/serve.default/serve.default.spec.js b/packages/plugin-renderer-lit/test/cases/serve.default/serve.default.spec.js index 7a679fb5f..a4422fff0 100644 --- a/packages/plugin-renderer-lit/test/cases/serve.default/serve.default.spec.js +++ b/packages/plugin-renderer-lit/test/cases/serve.default/serve.default.spec.js @@ -28,7 +28,6 @@ import fs from 'fs'; import { JSDOM } from 'jsdom'; import path from 'path'; import { getSetupFiles, getDependencyFiles, getOutputTeardownFiles } from '../../../../../test/utils.js'; -import request from 'request'; import { Runner } from 'gallinago'; import { fileURLToPath, URL } from 'url'; @@ -38,7 +37,7 @@ describe('Serve Greenwood With: ', function() { const LABEL = 'Custom Lit Renderer for SSR'; const cliPath = path.join(process.cwd(), 'packages/cli/src/index.js'); const outputPath = fileURLToPath(new URL('.', import.meta.url)); - const hostname = 'http://127.0.0.1:8080'; + const hostname = 'http://localhost:8080'; let runner; before(async function() { @@ -140,6 +139,7 @@ describe('Serve Greenwood With: ', function() { let response = {}; let artists = []; + let data; let dom; let usersPageDom; let usersPageHtml; @@ -151,50 +151,31 @@ describe('Serve Greenwood With: ', function() { aboutPageGraphData = graph.filter(page => page.route === '/artists/')[0]; - return new Promise((resolve, reject) => { - request.get(`${hostname}/artists/`, (err, res, body) => { - if (err) { - reject(); - } + response = await fetch(`${hostname}/artists/`); + data = await response.text(); + dom = new JSDOM(data); - response = res; - response.body = body; - dom = new JSDOM(body); - - request.get(`${hostname}/users/`, (err, res, body) => { - if (err) { - reject(); - } - - usersPageHtml = body; - usersPageDom = new JSDOM(body); - - resolve(); - }); - }); - }); + response = await fetch(`${hostname}/users/`); + usersPageHtml = await response.text(); + usersPageDom = new JSDOM(usersPageHtml); }); describe('Serve command with HTML route response using getBody, getTemplate and getFrontmatter', function() { - it('should return a 200 status', function(done) { - expect(response.statusCode).to.equal(200); - done(); + it('should return a 200 status', function() { + expect(response.status).to.equal(200); }); - it('should return the correct content type', function(done) { - expect(response.headers['content-type']).to.equal('text/html'); - done(); + it('should return the correct content type', function() { + expect(response.headers.get('content-type')).to.equal('text/html'); }); - it('should return a response body', function(done) { - expect(response.body).to.not.be.undefined; - done(); + it('should return a response body', function() { + expect(data).to.not.be.undefined; }); - it('the response body should be valid HTML from JSDOM', function(done) { + it('the response body should be valid HTML from JSDOM', function() { expect(dom).to.not.be.undefined; - done(); }); it('should have one