forked from itteco/iframely
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom_plugins.js
106 lines (91 loc) · 3.28 KB
/
custom_plugins.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
'use strict';
var request = require('supertest');
var ServerMock = require('mock-http-server');
var chai = require('chai');
var async = require('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;
var app = require('../app');
server = app.listen(process.env.PORT, cb);
};
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 });
beforeEach(function(done) {
invalidateRequireCache();
targetMockedServer.start(done);
});
afterEach(function(done) {
server.close(function() {
targetMockedServer.stop(done);
});
});
it('should use a custom plugin if defined', function(done) {
startWithENV(ENV_WITH_CUSTOM_PLUGINS, 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.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 custom plugin overriding a core plugin ', function(done) {
startWithENV(ENV_WITH_CUSTOM_PLUGINS, 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('TITLE FROM CUSTOM-PLUGIN');
done(err);
});
});
});
});