Skip to content

Commit

Permalink
Issue-1016: Finalize plugin tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DevLab2425 committed Oct 19, 2023
1 parent 6625ee9 commit 9864116
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 138 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ describe('Build Greenwood With: ', function() {
const cliPath = path.join(process.cwd(), 'packages/cli/src/index.js');
const outputPath = fileURLToPath(new URL('.', import.meta.url));
const netlifyFunctionsOutputUrl = new URL('./netlify/functions/', import.meta.url);
const hostname = 'http://localhost:8080';
let runner;

before(async function() {
Expand Down Expand Up @@ -114,7 +115,7 @@ describe('Build Greenwood With: ', function() {
});
const { handler } = await import(new URL(`./${name}/${name}.js`, netlifyFunctionsOutputUrl));
const response = await handler({
rawUrl: `http://localhost:8080/api/greeting?name=${param}`,
rawUrl: `${hostname}/api/greeting?name=${param}`,
httpMethod: 'GET'
}, {});
const { statusCode, body, headers } = response;
Expand Down Expand Up @@ -145,7 +146,7 @@ describe('Build Greenwood With: ', function() {
});
const { handler } = await import(new URL(`./${name}/${name}.js`, netlifyFunctionsOutputUrl));
const response = await handler({
rawUrl: `http://localhost:8080/api/greeting?name=${param}`,
rawUrl: `${hostname}/api/greeting?name=${param}`,
httpMethod: 'GET'
}, {});
const { statusCode, body, headers } = response;
Expand Down Expand Up @@ -178,7 +179,7 @@ describe('Build Greenwood With: ', function() {
});
const { handler } = await import(new URL(`./${name}/${name}.js`, netlifyFunctionsOutputUrl));
const response = await handler({
rawUrl: 'http://localhost:8080/api/submit-json',
rawUrl: `${hostname}/api/submit-json`,
body: { name: param },
httpMethod: 'POST',
headers: {
Expand Down Expand Up @@ -214,7 +215,7 @@ describe('Build Greenwood With: ', function() {
});
const { handler } = await import(new URL(`./${name}/${name}.js`, netlifyFunctionsOutputUrl));
const response = await handler({
rawUrl: 'http://localhost:8080/api/submit-form-data',
rawUrl: `${hostname}/api/submit-form-data`,
body: `name=${param}`,
httpMethod: 'POST',
headers: {
Expand Down Expand Up @@ -250,7 +251,7 @@ describe('Build Greenwood With: ', function() {
});
const { handler } = await import(new URL(`./${name}/${name}.js`, netlifyFunctionsOutputUrl));
const response = await handler({
rawUrl: 'http://localhost:8080/artists/',
rawUrl: `${hostname}/artists/`,
httpMethod: 'GET'
}, {});
const { statusCode, body, headers } = response;
Expand Down Expand Up @@ -287,7 +288,7 @@ describe('Build Greenwood With: ', function() {
});
const { handler } = await import(new URL(`./${name}/${name}.js`, netlifyFunctionsOutputUrl));
const response = await handler({
rawUrl: 'http://localhost:8080/users/',
rawUrl: `${hostname}/users/`,
httpMethod: 'GET'
}, {});
const { statusCode, body, headers } = response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ describe('Build Greenwood With: ', function() {
const outputPath = fileURLToPath(new URL('.', import.meta.url));
const vercelOutputFolder = new URL('./.vercel/output/', import.meta.url);
const vercelFunctionsOutputUrl = new URL('./functions/', vercelOutputFolder);
const hostname = 'http://localhost:8080';
let runner;

before(async function() {
Expand Down Expand Up @@ -125,9 +126,9 @@ describe('Build Greenwood With: ', function() {
};

await handler({
url: `http://localhost:8080/api/greeting?name=${param}`,
url: `${hostname}/api/greeting?name=${param}`,
headers: {
host: 'http://localhost:8080'
host: hostname
},
method: 'GET'
}, {
Expand Down Expand Up @@ -157,9 +158,9 @@ describe('Build Greenwood With: ', function() {
};

await handler({
url: 'http://localhost:8080/api/fragment',
url: `${hostname}/api/fragment`,
headers: {
host: 'http://localhost:8080'
host: hostname
},
method: 'GET'
}, {
Expand Down Expand Up @@ -193,9 +194,9 @@ describe('Build Greenwood With: ', function() {
};

await handler({
url: 'http://localhost:8080/api/submit-json',
url: `${hostname}/api/submit-json`,
headers: {
'host': 'http://localhost:8080',
'host': hostname,
'content-type': 'application/json'
},
body: { name },
Expand Down Expand Up @@ -230,9 +231,9 @@ describe('Build Greenwood With: ', function() {
};

await handler({
url: 'http://localhost:8080/api/submit-form-data',
url: `${hostname}/api/submit-form-data`,
headers: {
'host': 'http://localhost:8080',
'host': hostname,
'content-type': 'application/x-www-form-urlencoded'
},
body: { name },
Expand Down Expand Up @@ -265,9 +266,9 @@ describe('Build Greenwood With: ', function() {
const count = 2;

await handler({
url: 'http://localhost:8080/artists',
url: `${hostname}/artists`,
headers: {
host: 'http://localhost:8080'
host: hostname
},
method: 'GET'
}, {
Expand Down Expand Up @@ -304,9 +305,9 @@ describe('Build Greenwood With: ', function() {
const count = 1;

await handler({
url: 'http://localhost:8080/users',
url: `${hostname}/users`,
headers: {
host: 'http://localhost:8080'
host: hostname
},
method: 'GET'
}, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@
import chai from 'chai';
import { JSDOM } from 'jsdom';
import path from 'path';
import request from 'request';
import { Runner } from 'gallinago';
import { fileURLToPath, URL } from 'url';
import { runSmokeTest } from '../../../../../test/smoke-test.js';

const expect = chai.expect;

describe('Develop Greenwood With: ', function() {
describe.only('Develop Greenwood With: ', function() {

Check failure on line 29 in packages/plugin-graphql/test/cases/develop.default/develop.default.spec.js

View workflow job for this annotation

GitHub Actions / build (18)

describe.only not permitted

Check failure on line 29 in packages/plugin-graphql/test/cases/develop.default/develop.default.spec.js

View workflow job for this annotation

GitHub Actions / build (18)

describe.only not permitted
const LABEL = 'GraphQL plugin for resolving client facing files';
const cliPath = path.join(process.cwd(), 'packages/cli/src/index.js');
const outputPath = fileURLToPath(new URL('.', import.meta.url));
Expand Down Expand Up @@ -60,37 +59,21 @@ describe('Develop Greenwood With: ', function() {

describe('Develop command import map for GraphQL', function() {
let response = {};
let data;
let dom;

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);
resolve();
});
});
response = await fetch(`${hostname}:${port}`);
data = await response.text();
dom = new JSDOM(data);
});

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/html');
done();
it('should return the correct content type', function() {
expect(response.headers.get('content-type')).to.equal('text/html');
});

it('should return an import map shim <script> in the <head> of the document', function(done) {
Expand All @@ -110,73 +93,45 @@ describe('Develop Greenwood With: ', function() {

describe('Develop command specific client node_modules resolution', function() {
let response = {};
let data;

before(async function() {
return new Promise((resolve, reject) => {
request.get({
url: `http://127.0.0.1:${port}/node_modules/@greenwood/plugin-graphql/src/core/client.js`
}, (err, res) => {
if (err) {
reject();
}

response = res;

resolve();
});
});
response = await fetch(`${hostname}:${port}/node_modules/@greenwood/plugin-graphql/src/core/client.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.contain('export default client;');
done();
it('should return an ECMASCript module', function() {
expect(data).to.contain('export default client;');
});
});

describe('Develop command specific .gql behaviors', function() {
let response = {};
let data;

before(async function() {
return new Promise((resolve, reject) => {
request.get({
url: `http://127.0.0.1:${port}/data/queries/gallery.gql`
}, (err, res) => {
if (err) {
reject();
}

response = res;

resolve();
});
});
response = await fetch(`${hostname}:${port}/data/queries/gallery.gql`);
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.trim().indexOf('export default')).to.equal(0);
done();
it('should return an ECMASCript module', function() {
expect(data.trim().indexOf('export default')).to.equal(0);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe('Develop Greenwood With: ', function() {
});

// test a query call
describe.only('Develop command with GraphQL server and running a query', function() {
describe('Develop command with GraphQL server and running a query', function() {
let response = {
body: '',
code: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('Develop Greenwood With: ', function() {
let data;

before(async function() {
response = await fetch(`http://localhost:${port}/main.css?type=css`);
response = await fetch(`${hostname}:${port}/main.css?type=css`);
data = await response.text();
});

Expand Down Expand Up @@ -94,7 +94,7 @@ describe('Develop Greenwood With: ', function() {
let data;

before(async function() {
response = await fetch(`http://localhost:${port}/styles.css.js`);
response = await fetch(`${hostname}:${port}/styles.css.js`);
data = await response.text();
});

Expand Down
Loading

0 comments on commit 9864116

Please sign in to comment.