Skip to content

Commit

Permalink
chore/Issue 1016: Replace the use of request with fetch in test cases (
Browse files Browse the repository at this point in the history
…#1172)

* Issue 1016: Initital attempt at using fetch over request

* Issue-1016: Refactor IP to use localhost url

* Issue-1016: Initial POST refactor to fetch

* Issue-1016: Progress on removal of request

* Issue-1016: Additional removal of request

* Issue-1016: Finalize plugin tests

* use response.text()

* refactor init spec to fetch

* all specs refactored to use fetch

* refactoring all specs

---------

Co-authored-by: Owen Buckley <[email protected]>
  • Loading branch information
DevLab2425 and thescientist13 authored Nov 8, 2023
1 parent ce0c14f commit 7c9c23f
Show file tree
Hide file tree
Showing 29 changed files with 699 additions and 1,717 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import fs from 'fs';
import { JSDOM } from 'jsdom';
import path from 'path';
import { getSetupFiles } from '../../../../../test/utils.js';
import request from 'request';
import { Runner } from 'gallinago';
import { runSmokeTest } from '../../../../../test/smoke-test.js';
import { fileURLToPath, URL } from 'url';
Expand Down Expand Up @@ -61,46 +60,31 @@ describe('Develop Greenwood With: ', function() {
describe('Develop command specific HUD HTML behaviors when disabled', function() {
let response = {};
let sourceHtml = '';
let dom;
let body;

before(async function() {
return new Promise((resolve, reject) => {
request.get({
url: `http://127.0.0.1:${port}`,
headers: {
accept: 'text/html'
}
}, (err, res, body) => {
if (err) {
reject();
}

response = res;

dom = new JSDOM(body);
sourceHtml = fs.readFileSync(fileURLToPath(new URL('./src/pages/index.html', import.meta.url)), 'utf-8');

resolve();
});
});
response = await fetch(`${hostname}:${port}`);
body = await response.clone().text();
sourceHtml = fs.readFileSync(fileURLToPath(new URL('./src/pages/index.html', import.meta.url)), 'utf-8');
});

it('should return the correct content type', function(done) {
expect(response.headers['content-type']).to.equal('text/html');
expect(response.headers.get('content-type')).to.equal('text/html');
done();
});

it('should return a 200', function(done) {
expect(response.statusCode).to.equal(200);
expect(response.status).to.equal(200);

done();
});

it('should contain the appropriate HUD output in the response', function(done) {
const body = dom.window.document.querySelectorAll('body')[0];
const dom = new JSDOM(body);
const bodyTag = dom.window.document.querySelectorAll('body')[0];

expect(body.textContent).not.to.contain('Malformed HTML detected, please check your closing tags or an HTML formatter');
expect(body.textContent.replace(/\\n/g, '').trim()).not.to.contain(sourceHtml.replace(/\\n/g, '').trim());
expect(bodyTag.textContent).not.to.contain('Malformed HTML detected, please check your closing tags or an HTML formatter');
expect(bodyTag.textContent.replace(/\\n/g, '').trim()).not.to.contain(sourceHtml.replace(/\\n/g, '').trim());

done();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import fs from 'fs';
import { JSDOM } from 'jsdom';
import path from 'path';
import { getSetupFiles } from '../../../../../test/utils.js';
import request from 'request';
import { Runner } from 'gallinago';
import { runSmokeTest } from '../../../../../test/smoke-test.js';
import { fileURLToPath, URL } from 'url';
Expand Down Expand Up @@ -61,46 +60,31 @@ describe('Develop Greenwood With: ', function() {
describe('Develop command specific HUD HTML behaviors', function() {
let response = {};
let sourceHtml = '';
let dom;
let body;

before(async function() {
return new Promise((resolve, reject) => {
request.get({
url: `http://127.0.0.1:${port}`,
headers: {
accept: 'text/html'
}
}, (err, res, body) => {
if (err) {
reject();
}

response = res;

dom = new JSDOM(body);
sourceHtml = fs.readFileSync(fileURLToPath(new URL('./src/pages/index.html', import.meta.url)), 'utf-8');

resolve();
});
});
response = await fetch(`${hostname}:${port}`);
body = await response.clone().text();
sourceHtml = fs.readFileSync(fileURLToPath(new URL('./src/pages/index.html', import.meta.url)), 'utf-8');
});

it('should return the correct content type', function(done) {
expect(response.headers['content-type']).to.equal('text/html');
expect(response.headers.get('content-type')).to.equal('text/html');
done();
});

it('should return a 200', function(done) {
expect(response.statusCode).to.equal(200);
expect(response.status).to.equal(200);

done();
});

it('should contain the appropriate HUD output in the response', function(done) {
const body = dom.window.document.querySelectorAll('body')[0];
const dom = new JSDOM(body);
const bodyTag = dom.window.document.querySelectorAll('body')[0];

expect(body.textContent).to.contain('Malformed HTML detected, please check your closing tags or an HTML formatter');
expect(body.textContent.replace(/\\n/g, '').trim()).to.contain(sourceHtml.replace(/\\n/g, '').trim());
expect(bodyTag.textContent).to.contain('Malformed HTML detected, please check your closing tags or an HTML formatter');
expect(bodyTag.textContent.replace(/\\n/g, '').trim()).to.contain(sourceHtml.replace(/\\n/g, '').trim());

done();
});
Expand Down
Loading

0 comments on commit 7c9c23f

Please sign in to comment.