1
1
'use strict' ;
2
- import * as request from 'supertest' ;
3
- import * as ServerMock from 'mock-http-server' ;
4
- import * as chai from 'chai' ;
5
- import * as async from 'async' ;
6
-
7
- var server ;
8
-
9
- var ENV_WITH_CUSTOM_PLUGINS = 'test_with_custom_plugins' ;
10
-
11
- function invalidateRequireCache ( ) {
12
- Object . keys ( require . cache ) . forEach ( function ( key ) { delete require . cache [ key ] } )
13
- }
14
-
15
- var startWithENV = function ( env , cb ) {
16
- process . env . NODE_ENV = env ;
17
- import * as app from '../app.js' ;
18
- server = app . listen ( process . env . PORT , cb ) ;
19
- } ;
2
+ import request from 'supertest' ;
3
+ import ServerMock from 'mock-http-server' ;
4
+ import chai from 'chai' ;
5
+ import app from '../app.js' ;
20
6
21
7
describe ( 'custom plugins' , function ( ) {
8
+
22
9
var BASE_IFRAMELY_SERVER_URL = 'http://localhost:' + process . env . PORT ;
23
10
24
11
var TARGET_MOCKED_SERVER_PORT = 9000 ;
25
12
var TARGET_MOCKED_SERVER_BASEURL = 'http://127.0.0.1:' + TARGET_MOCKED_SERVER_PORT ;
26
13
27
- var targetMockedServer = new ServerMock ( { host : 'localhost' , port : TARGET_MOCKED_SERVER_PORT } ) ;
14
+ var targetMockedServer = new ServerMock ( { host : '127.0.0.1' , port : TARGET_MOCKED_SERVER_PORT } ) ;
15
+ var server ;
28
16
29
17
beforeEach ( function ( done ) {
30
- invalidateRequireCache ( ) ;
31
- targetMockedServer . start ( done ) ;
18
+ server = app . listen ( process . env . PORT , function ( ) {
19
+ targetMockedServer . start ( done ) ;
20
+ } ) ;
32
21
} ) ;
33
22
34
23
afterEach ( function ( done ) {
@@ -38,7 +27,7 @@ describe('custom plugins', function() {
38
27
} ) ;
39
28
40
29
it ( 'should use a custom plugin if defined' , function ( done ) {
41
- startWithENV ( ENV_WITH_CUSTOM_PLUGINS , function ( ) {
30
+
42
31
targetMockedServer . on ( {
43
32
method : 'GET' ,
44
33
path : '/testok' ,
@@ -56,33 +45,31 @@ describe('custom plugins', function() {
56
45
chai . expect ( res . body . meta . description ) . to . equal ( 'custom description for test.com domain' ) ;
57
46
done ( err ) ;
58
47
} ) ;
59
- } ) ;
60
48
} ) ;
61
49
62
- //it('should use a core plugin if no custom plugin exists', function(done) {
63
- // startWithENV('test', function () {
64
- // targetMockedServer.on({
65
- // method: 'GET',
66
- // path: '/testok',
67
- // reply: {
68
- // status: 200,
69
- // headers: { 'content-type': 'text/html' },
70
- // body: "<html><title>my title</title><meta name='description' content='my description'><body>Hi there!</body></html>"
71
- // }
72
- // });
73
- //
74
- // var url = TARGET_MOCKED_SERVER_BASEURL + '/testok';
75
- // request(BASE_IFRAMELY_SERVER_URL)
76
- // .get('/iframely?url=' + url)
77
- // .end(function(err, res) {
78
- // chai.expect(res.body.meta.title).to.equal('my title');
79
- // done(err);
80
- // });
81
- // });
82
- //});
50
+ it ( 'should use a core plugin if no custom plugin exists' , function ( done ) {
51
+
52
+ targetMockedServer . on ( {
53
+ method : 'GET' ,
54
+ path : '/test-another' ,
55
+ reply : {
56
+ status : 200 ,
57
+ headers : { 'content-type' : 'text/html' } ,
58
+ body : "<html><title>my title</title><meta name='description' content='my description'><body>Hi there!</body></html>"
59
+ }
60
+ } ) ;
61
+
62
+ var url = TARGET_MOCKED_SERVER_BASEURL + '/test-another' ;
63
+ request ( BASE_IFRAMELY_SERVER_URL )
64
+ . get ( '/iframely?url=' + url )
65
+ . end ( function ( err , res ) {
66
+ chai . expect ( res . body . meta . description ) . to . equal ( 'my description' ) ;
67
+ done ( err ) ;
68
+ } ) ;
69
+ } ) ;
83
70
84
71
it ( 'should use a custom plugin overriding a core plugin ' , function ( done ) {
85
- startWithENV ( ENV_WITH_CUSTOM_PLUGINS , function ( ) {
72
+
86
73
targetMockedServer . on ( {
87
74
method : 'GET' ,
88
75
path : '/testok' ,
@@ -100,6 +87,5 @@ describe('custom plugins', function() {
100
87
chai . expect ( res . body . meta . title ) . to . equal ( 'TITLE FROM CUSTOM-PLUGIN' ) ;
101
88
done ( err ) ;
102
89
} ) ;
103
- } ) ;
104
90
} ) ;
105
91
} ) ;
0 commit comments