Skip to content

Commit

Permalink
Issue-1016: Progress on removal of request
Browse files Browse the repository at this point in the history
  • Loading branch information
DevLab2425 committed Oct 19, 2023
1 parent 92609cd commit 741a667
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 156 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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() {
Expand All @@ -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() {

Check failure on line 75 in packages/plugin-graphql/test/cases/qraphql-server/graphql-server.spec.js

View workflow job for this annotation

GitHub Actions / build (18)

describe.only not permitted

Check failure on line 75 in packages/plugin-graphql/test/cases/qraphql-server/graphql-server.spec.js

View workflow job for this annotation

GitHub Actions / build (18)

describe.only not permitted
let response = {
body: '',
code: 0
};
let data;

const body = {
'operationName': null,
Expand All @@ -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);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -64,81 +63,51 @@ 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/[email protected]/dist/css/bootstrap.css
// https://unpkg.com/browse/[email protected]/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();
});
});

// https://github.com/ProjectEvergreen/greenwood/pull/747
// https://unpkg.com/browse/@material/[email protected]/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}`;');
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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"}');
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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() {
Expand Down Expand Up @@ -140,6 +139,7 @@ describe('Serve Greenwood With: ', function() {

let response = {};
let artists = [];
let data;
let dom;
let usersPageDom;
let usersPageHtml;
Expand All @@ -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 <style> tag in the <head>', function() {
Expand Down

0 comments on commit 741a667

Please sign in to comment.