Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
nleush committed Jun 20, 2024
2 parents 3df2fd6 + 885e6d8 commit 06182d9
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ jobs:
- name: Install dependencies
run: npm i
- name: Running tests
run: npm run test-core-plugins
run: npm test
8 changes: 7 additions & 1 deletion config.test_with_custom_plugins.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
export default {
import { fileURLToPath } from 'url';
import { dirname } from 'path';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

export default {

CUSTOM_PLUGINS_PATH: __dirname + '/test/fixtures/custom-plugins',

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@
"iframely-proxy-plugins": true,
"main": "./lib/core.js",
"scripts": {
"test": "npm run test-core-plugins && npm run test-e2e",
"test": "npm run test-core-plugins && npm run test-e2e && npm run custom_plugins",
"test-core-plugins": "mocha --exit test/core-plugins.js",
"test-e2e": "NODE_ENV=test PORT=8080 mocha --exit test/e2e.js"
"test-e2e": "NODE_ENV=test PORT=8080 mocha --exit test/e2e.js",
"custom_plugins": "NODE_ENV=test_with_custom_plugins PORT=8080 mocha --exit test/custom_plugins.js"
},
"engines": {
"node": ">=14.0"
Expand Down
78 changes: 32 additions & 46 deletions test/custom_plugins.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,23 @@
'use strict';
import * as request from 'supertest';
import * as ServerMock from 'mock-http-server';
import * as chai from 'chai';
import * as async from 'async';

var server;

var ENV_WITH_CUSTOM_PLUGINS = 'test_with_custom_plugins';

function invalidateRequireCache () {
Object.keys(require.cache).forEach(function(key) { delete require.cache[key] })
}

var startWithENV = function (env, cb) {
process.env.NODE_ENV = env;
import * as app from '../app.js';
server = app.listen(process.env.PORT, cb);
};
import request from 'supertest';
import ServerMock from 'mock-http-server';
import chai from 'chai';
import app from '../app.js';

describe('custom plugins', function() {

var BASE_IFRAMELY_SERVER_URL = 'http://localhost:' + process.env.PORT;

var TARGET_MOCKED_SERVER_PORT = 9000;
var TARGET_MOCKED_SERVER_BASEURL = 'http://127.0.0.1:' + TARGET_MOCKED_SERVER_PORT;

var targetMockedServer = new ServerMock({ host: 'localhost', port: TARGET_MOCKED_SERVER_PORT });
var targetMockedServer = new ServerMock({ host: '127.0.0.1', port: TARGET_MOCKED_SERVER_PORT });
var server;

beforeEach(function(done) {
invalidateRequireCache();
targetMockedServer.start(done);
server = app.listen(process.env.PORT, function() {
targetMockedServer.start(done);
});
});

afterEach(function(done) {
Expand All @@ -38,7 +27,7 @@ describe('custom plugins', function() {
});

it('should use a custom plugin if defined', function(done) {
startWithENV(ENV_WITH_CUSTOM_PLUGINS, function () {

targetMockedServer.on({
method: 'GET',
path: '/testok',
Expand All @@ -56,33 +45,31 @@ describe('custom plugins', function() {
chai.expect(res.body.meta.description).to.equal('custom description for test.com domain');
done(err);
});
});
});

//it('should use a core plugin if no custom plugin exists', function(done) {
// startWithENV('test', function () {
// targetMockedServer.on({
// method: 'GET',
// path: '/testok',
// reply: {
// status: 200,
// headers: { 'content-type': 'text/html' },
// body: "<html><title>my title</title><meta name='description' content='my description'><body>Hi there!</body></html>"
// }
// });
//
// var url = TARGET_MOCKED_SERVER_BASEURL + '/testok';
// request(BASE_IFRAMELY_SERVER_URL)
// .get('/iframely?url=' + url)
// .end(function(err, res) {
// chai.expect(res.body.meta.title).to.equal('my title');
// done(err);
// });
// });
//});
it('should use a core plugin if no custom plugin exists', function(done) {

targetMockedServer.on({
method: 'GET',
path: '/test-another',
reply: {
status: 200,
headers: { 'content-type': 'text/html' },
body: "<html><title>my title</title><meta name='description' content='my description'><body>Hi there!</body></html>"
}
});

var url = TARGET_MOCKED_SERVER_BASEURL + '/test-another';
request(BASE_IFRAMELY_SERVER_URL)
.get('/iframely?url=' + url)
.end(function(err, res) {
chai.expect(res.body.meta.description).to.equal('my description');
done(err);
});
});

it('should use a custom plugin overriding a core plugin ', function(done) {
startWithENV(ENV_WITH_CUSTOM_PLUGINS, function () {

targetMockedServer.on({
method: 'GET',
path: '/testok',
Expand All @@ -100,6 +87,5 @@ describe('custom plugins', function() {
chai.expect(res.body.meta.title).to.equal('TITLE FROM CUSTOM-PLUGIN');
done(err);
});
});
});
});
2 changes: 1 addition & 1 deletion test/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('meta endpoint', function() {
var TARGET_MOCKED_SERVER_PORT = 9000;
var TARGET_MOCKED_SERVER_BASEURL = 'http://127.0.0.1:' + TARGET_MOCKED_SERVER_PORT;

var targetMockedServer = new ServerMock({ host: 'localhost', port: TARGET_MOCKED_SERVER_PORT });
var targetMockedServer = new ServerMock({ host: '127.0.0.1', port: TARGET_MOCKED_SERVER_PORT });
var server;

beforeEach(function(done) {
Expand Down

0 comments on commit 06182d9

Please sign in to comment.