Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore/Issue 1016: Replace the use of request with fetch in test cases #1172

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
Loading